Skip to content
Merged

Lint #20

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9d7fa4
init(lint): Linting rules
TheRootDaemon Aug 1, 2026
5033081
feat(lint): Filename rules
TheRootDaemon Aug 1, 2026
f71abdb
docs(lint): Fix docs
TheRootDaemon Aug 1, 2026
2ecb25f
lint: Implement parser
TheRootDaemon Aug 2, 2026
b672848
lint: Tests for parse
TheRootDaemon Aug 2, 2026
db17d6f
lint: Tests for parse_lines
TheRootDaemon Aug 2, 2026
4cb5638
lint: Tests for parse_sections
TheRootDaemon Aug 2, 2026
82e608e
lint: Tests for title_rules
TheRootDaemon Aug 2, 2026
a31228e
lint: Title rules
TheRootDaemon Aug 2, 2026
9d82c0e
lint: File rules
TheRootDaemon Aug 4, 2026
4c42c89
lint: Description rules
TheRootDaemon Aug 6, 2026
42384e5
lint: example rules
TheRootDaemon Aug 6, 2026
e4440ad
lint: command rules
TheRootDaemon Aug 7, 2026
6e54f39
lint: global Lint
TheRootDaemon Aug 7, 2026
53e75ac
lint: Remove unused field
TheRootDaemon Aug 7, 2026
1341894
fix(lint): align whitespace rules with reference behavior
TheRootDaemon Aug 8, 2026
706a0b4
fix(lint): report TLDR105 only for extra commands
TheRootDaemon Aug 8, 2026
7d530a4
lint: Add specifications
TheRootDaemon Aug 8, 2026
5046154
fix(lint): Avoid platform dependent filename checks
TheRootDaemon Aug 10, 2026
5bc4050
tests(cache): Add deterministic times to avoid brittle edge cases,
TheRootDaemon Aug 10, 2026
6b4b94a
tests(cache): Refactor similar tests into table driven tests
TheRootDaemon Aug 10, 2026
3bfa3ca
lint: Format
TheRootDaemon Aug 10, 2026
d8971e4
test(lint): Tests for error strings
TheRootDaemon Aug 10, 2026
7d4f224
cmd: Add flags/modifiers for --lint, --format
TheRootDaemon Aug 10, 2026
03d9400
test(cache): Fix brittle test on info_test
TheRootDaemon Aug 10, 2026
59ce316
chore
TheRootDaemon Aug 12, 2026
2fd1911
fix(lint): Reach flag dependency error for --output before parsing
TheRootDaemon Aug 12, 2026
a9813b1
feat(app): Lint
TheRootDaemon Aug 12, 2026
db34926
chore(help): Add help strings, completions
TheRootDaemon Aug 12, 2026
b5e1326
app: Format handlers, linting refactors
TheRootDaemon Aug 13, 2026
896dad7
fix(lint): 1-indexed linting
TheRootDaemon Aug 14, 2026
aa6fced
chore: Add help strings, completions for --format
TheRootDaemon Aug 14, 2026
90e170b
chore: Improve TUI
TheRootDaemon Aug 14, 2026
278780a
chore: Move error as the last argument
TheRootDaemon Aug 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* text=auto eol=lf

# Required for TLDR010 (Only Unix-style line endings allowed)
internal/lint/specs/pages/failing/010.md binary
18 changes: 18 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type CLI struct {
// ListAll requests listing all pages across all platforms.
ListAll bool

// Lint requests validating the specified tldr pages.
Lint bool

// Format requests formatting the specified tldr pages.
Format bool

// Search requests a keyword search across pages.
Search string

Expand Down Expand Up @@ -57,6 +63,18 @@ type CLI struct {
// Languages overrides the language list.
Languages []string

// Output specifies the file to write formatted output to.
Output string

// InPlace requests formatting files in place.
InPlace bool

// Tabular requests displaying lint errors in tabular format.
Tabular bool

// Ignore specifies comma-separated lint error codes to ignore.
Ignore []string

// ShortOptions requests displaying short option forms.
ShortOptions bool

Expand Down
23 changes: 21 additions & 2 deletions cmd/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ func fmtFlagError(fs *flag.FlagSet, err error) error {
case strings.HasPrefix(s, "flag needs an argument: "):
raw := strings.TrimPrefix(s, "flag needs an argument: ")
name := strings.TrimLeft(raw, "-")
return fmtUsage("flag %s requires an argument", termcolor.Sprint("bold blue", flagDisplay(name)))
if name == "output" {
return fmtUsage(
"flag %s requires %s",
termcolor.Sprint("bold blue", "--output"),
termcolor.Sprint("bold blue", "--format"),
)
}
return fmtUsage(
"flag %s requires an argument",
termcolor.Sprint("bold blue", flagDisplay(name)),
)
default:
return fmtUsage("%s", s)
}
Expand Down Expand Up @@ -74,7 +84,10 @@ func flagDisplay(name string) string {
// activeOps returns display names for all active operations in cli.
func activeOps(cli *CLI) []string {
var ops []string
if len(cli.Page) > 0 && !cli.Browse {
if len(cli.Page) > 0 &&
!cli.Browse &&
!cli.Lint &&
!cli.Format {
ops = append(ops, "[PAGE]...")
}
if cli.Update {
Expand All @@ -86,6 +99,12 @@ func activeOps(cli *CLI) []string {
if cli.ListAll {
ops = append(ops, "--list-all")
}
if cli.Lint {
ops = append(ops, "--lint <FILE|DIR>")
}
if cli.Format {
ops = append(ops, "--format <FILE|DIR>")
}
if cli.Search != "" {
ops = append(ops, "--search <KEYWORD>")
}
Expand Down
30 changes: 30 additions & 0 deletions cmd/diagnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func TestFmtFlagError(t *testing.T) {
"requires an argument",
},
},
{
name: "missing_argument_output",
setup: func(fs *flag.FlagSet) {
fs.String("output", "", "")
},
args: []string{"--output"},
contains: []string{
"--format",
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -87,6 +97,11 @@ func TestFmtConflictError(t *testing.T) {
cli: CLI{Page: []string{"tar"}, Search: "foo"},
contains: []string{"cannot be used with", "[PAGE]...", "--search"},
},
{
name: "lint_and_format",
cli: CLI{Lint: true, Format: true, Page: []string{"file.md"}},
contains: []string{"cannot be used with", "--lint <FILE|DIR>", "--format <FILE|DIR>"},
},
{
name: "one_operation_fallback",
cli: CLI{Update: true},
Expand Down Expand Up @@ -176,11 +191,26 @@ func TestActiveOps(t *testing.T) {
cli: CLI{Render: "file.md"},
want: []string{"--render <FILE>"},
},
{
name: "lint",
cli: CLI{Lint: true, Page: []string{"file.md"}},
want: []string{"--lint <FILE|DIR>"},
},
{
name: "format",
cli: CLI{Format: true, Page: []string{"file.md"}},
want: []string{"--format <FILE|DIR>"},
},
{
name: "multiple",
cli: CLI{Update: true, Search: "foo"},
want: []string{"--update", "--search <KEYWORD>"},
},
{
name: "lint_with_update",
cli: CLI{Lint: true, Page: []string{"file.md"}, Update: true},
want: []string{"--update", "--lint <FILE|DIR>"},
},
}

for _, tt := range tests {
Expand Down
66 changes: 52 additions & 14 deletions cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,38 @@ func printFlags() {
description: "List all pages",
},
{
short: "-s",
long: "--search",
arg: "<KEYWORD>", description: "Search for pages containing a keyword",
long: "--lint",
arg: "<FILE|DIR>",
description: "Validate the specified tldr pages",
},
{
long: "--tabular",
description: "Display lint errors in a tabular format",
},
{
long: "--ignore",
arg: "<CODES>",
description: "Ignore comma-separated lint error codes",
},
{
long: "--format",
arg: "<FILE|DIR>",
description: "Format the specified tldr pages",
},
{
long: "--output",
arg: "<FILE>",
description: "Write formatted output to the specified file",
},
{
long: "--in-place",
description: "Format pages in place",
},
{
short: "-s",
long: "--search",
arg: "<KEYWORD>",
description: "Search for pages containing a keyword",
},
{
short: "-b",
Expand All @@ -82,9 +111,10 @@ func printFlags() {
description: "Show cache information",
},
{
short: "-r",
long: "--render",
arg: "<FILE>", description: "Render the specified tldr page",
short: "-r",
long: "--render",
arg: "<FILE>",
description: "Render the specified tldr page",
},
{
long: "--clean-cache",
Expand All @@ -101,14 +131,16 @@ func printFlags() {
description: "Print the default config path",
},
{
short: "-p",
long: "--platform",
arg: "<PLATFORM>", description: "Specify the platform to use (linux, osx, windows, etc.)",
short: "-p",
long: "--platform",
arg: "<PLATFORM>",
description: "Specify the platform to use (linux, osx, windows, etc.)",
},
{
short: "-L",
long: "--language",
arg: "<LANGUAGE_CODE>", description: "Specify the languages to use",
short: "-L",
long: "--language",
arg: "<LANGUAGE_CODE>",
description: "Specify the languages to use",
},
{
long: "--short-options",
Expand Down Expand Up @@ -144,13 +176,19 @@ func printFlags() {
long: "--raw",
description: "Print pages in raw markdown instead of rendering them",
},
{long: "--no-raw", description: "Render pages instead of printing raw file contents (overrides --raw)"},
{
long: "--no-raw",
description: "Render pages instead of printing raw file contents (overrides --raw)",
},
{
short: "-q",
long: "--quiet",
description: "Suppress status messages and warnings",
},
{long: "--verbose...", description: "Be more verbose (can be specified twice)"},
{
long: "--verbose...",
description: "Be more verbose (can be specified twice)",
},
{
long: "--color",
arg: "<WHEN>",
Expand Down
47 changes: 46 additions & 1 deletion cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ func parse(args []string) (*CLI, error) {
"list all pages for the current platform",
)

fs.BoolVar(
&cli.Lint,
"lint",
false,
"validate the specified tldr pages",
)

fs.BoolVar(
&cli.Format,
"format",
false,
"format the specified tldr pages",
)

fs.BoolVar(&cli.ListAll, "a", false, "list all pages")
fs.BoolVar(&cli.ListAll, "list-all", false, "list all pages")

Expand Down Expand Up @@ -145,6 +159,35 @@ func parse(args []string) (*CLI, error) {
"specify the languages to use",
)

fs.StringVar(
&cli.Output,
"output",
"",
"write formatted output to the specified file",
)

fs.BoolVar(
&cli.InPlace,
"in-place",
false,
"formats pages in place",
)

fs.BoolVar(
&cli.Tabular,
"tabular",
false,
"format lint errors in a tabular format",
)

fs.Var(
&stringListValue{
values: &cli.Ignore,
},
"ignore",
"ignore comma-separated tldr lint error codes",
)

fs.BoolVar(
&cli.ShortOptions,
"short-options",
Expand Down Expand Up @@ -258,7 +301,9 @@ func reorderFlags(args []string) []string {
"color",
"config",
"s", "search",
"r", "render":
"r", "render",
"output",
"ignore":
if i+1 < len(args) {
i++
flags = append(flags, args[i])
Expand Down
Loading