Skip to content

Commit 1f63808

Browse files
committed
refactor(analyze-includes): revert toctree support
1 parent f2a787f commit 1f63808

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

audit-cli/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ audit-cli
5959
│ └── find-string
6060
├── analyze # Analyze RST file structures
6161
│ ├── includes
62-
│ └── references
62+
│ └── file-references
6363
└── compare # Compare files across versions
6464
└── file-contents
6565
```
@@ -223,9 +223,9 @@ With `-v` flag, also shows:
223223

224224
#### `analyze includes`
225225

226-
Analyze `include` directive and `toctree` relationships in RST files to understand file dependencies.
226+
Analyze `include` directive relationships in RST files to understand file dependencies.
227227

228-
This command recursively follows both `.. include::` directives and `.. toctree::` entries to show all files that are referenced from a starting file. This provides a complete picture of file dependencies including both content includes and table of contents structure.
228+
This command recursively follows `.. include::` directives to show all files that are referenced from a starting file. This helps you understand which content is transcluded into a page.
229229

230230
**Use Cases:**
231231

@@ -234,7 +234,7 @@ This command helps writers:
234234
- Identify circular include dependencies (files included multiple times)
235235
- Document file relationships for maintenance
236236
- Plan refactoring of complex include structures
237-
- Understand table of contents structure and page hierarchies
237+
- See what content is actually pulled into a page
238238

239239
**Basic Usage:**
240240

@@ -286,6 +286,12 @@ times (e.g., file A includes file C, and file B also includes file C), the file
286286
However, the tree view will show it in all locations where it appears, with subsequent occurrences marked as circular
287287
includes in verbose mode.
288288

289+
**Note on Toctree:**
290+
291+
This command does **not** follow `.. toctree::` entries. Toctree entries are navigation links to other pages, not content
292+
that's transcluded into the page. If you need to find which files reference a target file through toctree entries, use
293+
the `analyze file-references` command with the `--include-toctree` flag.
294+
289295
#### `analyze file-references`
290296

291297
Find all files that reference a target file through RST directives. This performs reverse dependency analysis, showing which files reference the target file through `include`, `literalinclude`, `io-code-block`, or `toctree` directives.
@@ -382,8 +388,7 @@ With `--include-toctree`, also tracks:
382388
getting-started
383389
```
384390

385-
**Note:** Only file-based references are tracked. Inline content (e.g., `.. input::` with `:language:` but no file path) is not tracked.
386-
391+
**Note:** Only file-based references are tracked. Inline content (e.g., `.. input::` with `:language:` but no file path) aly
387392
**Output Formats:**
388393

389394
**Text** (default):
@@ -687,9 +692,9 @@ audit-cli/
687692
│ │ │ ├── analyzer.go # Include tree building
688693
│ │ │ ├── output.go # Output formatting
689694
│ │ │ └── types.go # Type definitions
690-
│ │ └── references/ # References analysis subcommand
691-
│ │ ├── references.go # Command logic
692-
│ │ ├── references_test.go # Tests
695+
│ │ └── file-references/ # File-references analysis subcommand
696+
│ │ ├── file-references.go # Command logic
697+
│ │ ├── file-references_test.go # Tests
693698
│ │ ├── analyzer.go # Reference finding logic
694699
│ │ ├── output.go # Output formatting
695700
│ │ └── types.go # Type definitions

audit-cli/commands/analyze/includes/analyzer.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,13 @@ func buildIncludeTree(filePath string, visited map[string]bool, verbose bool, de
106106
includeFiles = []string{}
107107
}
108108

109-
// Find toctree entries in this file
110-
toctreeFiles, err := rst.FindToctreeEntries(absPath)
111-
if err != nil {
112-
// Not a fatal error - file might not have toctree
113-
toctreeFiles = []string{}
114-
}
115-
116-
// Combine include and toctree files
117-
allFiles := append(includeFiles, toctreeFiles...)
118-
119-
if verbose && len(allFiles) > 0 {
109+
if verbose && len(includeFiles) > 0 {
120110
indent := getIndent(depth)
121-
fmt.Printf("%s📄 %s (%d includes, %d toctree entries)\n", indent, filepath.Base(absPath), len(includeFiles), len(toctreeFiles))
111+
fmt.Printf("%s📄 %s (%d includes)\n", indent, filepath.Base(absPath), len(includeFiles))
122112
}
123113

124-
// Recursively process each included/toctree file
125-
for _, includeFile := range allFiles {
114+
// Recursively process each included file
115+
for _, includeFile := range includeFiles {
126116
childNode, err := buildIncludeTree(includeFile, visited, verbose, depth+1)
127117
if err != nil {
128118
fmt.Fprintf(os.Stderr, "Warning: failed to process file %s: %v\n", includeFile, err)

audit-cli/commands/analyze/includes/includes.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Package includes provides functionality for analyzing include and toctree relationships.
1+
// Package includes provides functionality for analyzing include relationships.
22
//
33
// This package implements the "analyze includes" subcommand, which analyzes RST files
4-
// to understand their include directive and toctree relationships. It can display results as:
5-
// - A hierarchical tree structure showing include and toctree relationships
6-
// - A flat list of all files referenced through includes and toctree entries
4+
// to understand their include directive relationships. It can display results as:
5+
// - A hierarchical tree structure showing include relationships
6+
// - A flat list of all files referenced through includes
77
//
88
// This helps writers understand the impact of changes to files that are widely included
9-
// or referenced in table of contents.
9+
// across the documentation.
1010
package includes
1111

1212
import (
@@ -17,7 +17,7 @@ import (
1717

1818
// NewIncludesCommand creates the includes subcommand.
1919
//
20-
// This command analyzes include directive and toctree relationships in RST files.
20+
// This command analyzes include directive relationships in RST files.
2121
// Supports flags for different output formats (tree or list).
2222
//
2323
// Flags:
@@ -33,17 +33,16 @@ func NewIncludesCommand() *cobra.Command {
3333

3434
cmd := &cobra.Command{
3535
Use: "includes [filepath]",
36-
Short: "Analyze include and toctree relationships in RST files",
37-
Long: `Analyze include directive and toctree relationships to understand file dependencies.
36+
Short: "Analyze include relationships in RST files",
37+
Long: `Analyze include directive relationships to understand file dependencies.
3838
39-
This command recursively follows .. include:: directives and .. toctree:: entries
40-
and shows all files that are referenced. This helps writers understand the impact
41-
of changes to files that are widely included or referenced in table of contents
42-
across the documentation.
39+
This command recursively follows .. include:: directives and shows all files
40+
that are referenced. This helps writers understand the impact of changes to
41+
files that are widely included across the documentation.
4342
4443
Output formats:
45-
--tree: Show hierarchical tree structure of includes and toctree entries
46-
--list: Show flat list of all included and toctree files
44+
--tree: Show hierarchical tree structure of includes
45+
--list: Show flat list of all included files
4746
4847
If neither flag is specified, shows a summary with basic statistics.`,
4948
Args: cobra.ExactArgs(1),

0 commit comments

Comments
 (0)