lint 0.1.2

A versatile linting tool with CLI, MCP, and library interfaces
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# Lint

A versatile linting tool with multiple interfaces: CLI, MCP (Model Context Protocol), and library.

## Features

- **CLI Interface**: Run linting from the command line
- **MCP Server**: Expose linting capabilities via MCP protocol
- **Library API**: Use linting functionality in your Rust projects

## Installation

```bash
cargo install --path .
```

## Usage

### CLI

Lint files or directories:

```bash
# Lint current directory
lint lint .

# `check` is an alias for `lint`
lint check .

# Lint specific files
lint lint src/main.rs src/lib.rs

# Use glob patterns
lint lint "src/**/*.rs"

# Specify output format (text, json, markdown, github, sarif, junit, concise, gitlab)
lint lint . --output json

# --output-format is an alias for --output
lint lint . --output-format markdown

# Set maximum line length
lint lint . --max-line-length 120

# Enable specific rules
lint lint . -r line-length -r trailing-whitespace

# Use a configuration file
lint lint . --config .lint.json

# Config is auto-discovered: place .lint.json in your project root
# and run lint without --config

# .gitignore patterns are automatically respected when walking directories

# Auto-fix fixable issues
lint lint . --fix

# Preview fixes without writing changes
lint lint . --diff

# Apply fixes but don't report remaining violations
lint lint . --fix-only

# Auto-add suppression comments to all violations
lint lint . --add-noqa

# Ignore all suppression comments (useful for auditing)
lint lint . --ignore-suppressions

# Ignore all ignore patterns (lint everything including node_modules)
lint lint . --no-ignore

# Watch for changes and re-lint
lint lint . --watch

# Use cache to skip unchanged files
lint lint . --cache

# Use a custom cache file location
lint lint . --cache --cache-location /tmp/lint_cache.json

# Use content-based caching (more accurate, slower)
lint lint . --cache --cache-strategy content

# Only show errors (suppress warnings and infos)
lint lint . --quiet

# Fail if more than 10 warnings
lint lint . --max-warnings 10

# Disable colored output
lint lint . --color never

# Add a rule to the default set
lint lint . --select no-todo

# Remove a rule from the default set
lint lint . --ignore line-length

# Enable the final-newline rule
lint lint . --select final-newline

# Enable the no-mixed-line-endings rule
lint lint . --select no-mixed-line-endings

# Enable all built-in rules
lint lint . --select-all

# List files that would be linted (without linting)
lint lint . --print-files

# Write JSON results to a file
lint lint . --output json --output-file results.json

# Generate SARIF output for GitHub Advanced Security
lint lint . --output sarif --output-file results.sarif.json

# Generate JUnit XML for CI integration
lint lint . --output junit --output-file results.junit.xml

# Generate GitLab Code Quality report
lint lint . --output gitlab --output-file gl-code-quality-report.json

# Concise one-line-per-violation output
lint lint . --output concise

# Show violations without failing the build
lint lint . --exit-zero

# Show effective configuration after merging all sources
lint lint . --show-settings

# Enable specific rules
lint lint . --select no-tabs --select no-consecutive-empty-lines

# Show per-rule violation statistics
lint lint . --statistics

# Exclude specific paths or patterns
lint lint . --exclude vendor --exclude "*.min.js"

# Don't fail when a glob pattern doesn't match any files
lint lint "nonexistent/**/*.rs" --no-error-on-unmatched-pattern

# Treat warnings as errors (exit 1 on any warning)
lint lint . --deny-warnings

# Exit non-zero even if all violations were fixed
lint lint . --fix --exit-non-zero-on-fix

# Lint code from stdin (useful for editor integrations)
echo 'let x = 5;   ' | lint lint --stdin --stdin-filename test.rs

# List available rules
lint list-rules

# Explain what a specific rule does
lint explain line-length

# Show version
lint version

# Generate a default configuration file
lint init
```

**Exit codes**: `0` if no issues found, `1` if any errors detected or if warnings exceed `--max-warnings`.

### Config Extends

Share a base configuration across projects:

```json
{
  "extends": ".lint.base.json",
  "max_line_length": 120,
  "rule_set": {
    "enabled_rules": ["line-length", "trailing-whitespace", "no-todo"]
  }
}
```

Values in the local config override the base. Collections like `ignore_patterns`, `per_file_ignores`, and `severity_overrides` are merged.

### Unused Suppression Detection

Enable the `unused-suppression` rule to detect suppression comments that don't actually suppress any violations (useful for cleanup after refactoring):

```bash
lint lint . --rules line-length,trailing-whitespace,unused-suppression
```

This reports warnings like:

```
Unused suppression comment: `lint: ignore=line-length`
```

### MCP Server

Run the MCP server:

```bash
cargo run --bin lint-mcp -- --host 127.0.0.1 --port 8080
```

The server exposes the following tools:

- `lint_files`: Lint specified files and return issues
- `list_rules`: List all available linting rules

### Library

Use as a library in your Rust project:

```rust
use lint::{ConfigBuilder, OutputFormat};

fn main() -> anyhow::Result<()> {
    let config = ConfigBuilder::new()
        .paths(vec!["src".into()])
        .max_line_length(Some(100))
        .enabled_rules(vec![
            "line-length".to_string(),
            "trailing-whitespace".to_string(),
        ])
        .output_format(OutputFormat::Json)
        .build();

    let results = lint::lint_files(&config)?;

    for result in results {
        println!("File: {}", result.file_path.display());
        for message in result.messages {
            println!("  {}: {}", message.severity.as_str(), message.message);
        }
    }

    Ok(())
}
```

## Available Rules

All violations include **fix suggestions** to help resolve issues. Use `--output text` to see `→ help:` messages, or `--output markdown` for `**Fix**:` blocks.

### Universal Rules
- `line-length`: Lines exceeding max length → break line, extract variable, or use continuation
- `trailing-whitespace`: Trailing spaces/tabs → remove
- `no-todo`: TODO/FIXME comments → address or create tracking issue

### JavaScript/TypeScript Rules
- `no-console-log`: console.log/warn/error → use logger
- `no-var`: var usage → use let/const
- `missing-semicolon`: Missing semicolons

### Python Rules
- `no-print`: print() → use logging module
- `python-style`: PEP 8 (PascalCase classes, snake_case functions)

### Go Rules
- `go-style`: Exported functions need documentation

### Java Rules
- `java-style`: PascalCase classes, no System.out → use SLF4J
- `missing-semicolon`: Missing semicolons

### Rust Rules
- `no-unwrap`: .unwrap() → use ? or match
- `no-expect`: .expect() → use ? or match
- `missing-semicolon`: Missing semicolons

### Ruby Rules
- `no-puts`: puts → use Logger
- `ruby-style`: CamelCase classes, attr_writer for setters

### PHP Rules
- `no-echo`: echo → use error_log or return JSON

### Swift Rules
- `no-swift-print`: print() → use OSLog

### Kotlin Rules
- `kotlin-style`: PascalCase classes, println → use slf4j

### Dart Rules
- `no-dart-print`: print() → use debugPrint or logging package

### C# Rules
- `no-csharp-console`: Console.WriteLine → use ILogger
- `csharp-style`: PascalCase classes

### Shell Rules
- `shell-echo-quote`: Unquoted variables in echo → quote with `"$VAR"`

### SQL Rules
- `sql-no-select-star`: SELECT * → list explicit columns

### Lua Rules
- `no-lua-print`: print() → use logging or remove

### Scala Rules
- `no-scala-println`: println() → use slf4j

### R Rules
- `no-r-print`: print() → use message() or cat()

### Zig Rules
- `no-zig-debug-print`: std.debug.print → remove or use std.log

### HTML Rules
- `html-no-inline-style`: Inline style= → move to CSS class
- `html-img-alt`: img without alt → add alt for accessibility

### CSS Rules
- `css-avoid-important`: !important → increase selector specificity

## Configuration

Create a custom configuration:

```rust
let config = ConfigBuilder::new()
    .paths(vec!["src".into(), "tests".into()])
    .ignore_patterns(vec![
        "node_modules".to_string(),
        "target".to_string(),
        ".git".to_string(),
    ])
    .max_line_length(Some(120))
    .enabled_rules(vec![
        "line-length".to_string(),
        "trailing-whitespace".to_string(),
    ])
    .custom_rules(Some("custom_rules.json".into()))
    .output_format(OutputFormat::Text)
    .build();
```

### Custom Rules

Define your own rules in a JSON file:

```json
[
  {
    "name": "no-debugger",
    "pattern": "\\bdebugger\\b",
    "message": "Debugger statement found",
    "severity": "Error",
    "suggestion": "Remove debugger before committing",
    "extensions": ["js", "ts"]
  }
]
```

- `name`: Unique rule identifier
- `pattern`: Regular expression to match
- `message`: Error/warning message
- `severity`: `Error`, `Warning`, or `Info`
- `suggestion`: Optional fix hint
- `extensions`: Optional list of file extensions to apply the rule to

### Suppressing Rules Inline

Suppress a rule on a specific line:

```rust
let x = 5; // lint: ignore=line-length
```

Suppress all rules on a line:

```rust
let x = 5; // lint: ignore
```

### Block Suppressions

Disable a rule for a block of code:

```rust
// lint: disable=line-length
const LONG_CONFIG: &str = "some very long configuration string that exceeds normal limits";
// lint: enable=line-length
```

Disable all rules for a block:

```rust
// lint: disable
const GENERATED_DATA: &str = "...generated content...";
// lint: enable
```

### File-Level Ignore

Ignore all rules for an entire file (must be on the first line):

```rust
// lint: ignore-file
// This file is auto-generated
const DATA: &str = "...";
```

Ignore a specific rule for the entire file:

```rust
// lint: ignore-file=line-length
// Test files often have long lines
```

Works in any language — the suppression comment is language-agnostic.

### Per-File Ignore Patterns

Disable specific rules for files matching a glob pattern via config:

```json
{
  "per_file_ignores": {
    "tests/**/*.rs": ["line-length"],
    "gen/**/*.js": ["line-length", "trailing-whitespace"]
  }
}
```

### Rule Severity Override

Override the default severity of any rule in your config:

```json
{
  "severity_overrides": {
    "line-length": "Error",
    "no-todo": "Warning"
  }
}
```

Valid severities: `Error`, `Warning`, `Info`.

## Supported File Extensions

- **Rust**: `.rs`
- **JavaScript/TypeScript**: `.js`, `.ts`, `.jsx`, `.tsx`
- **Python**: `.py`
- **Java**: `.java`
- **Go**: `.go`
- **C/C++**: `.c`, `.cpp`, `.h`, `.hpp`
- **Ruby**: `.rb`
- **PHP**: `.php`
- **Swift**: `.swift`
- **Kotlin**: `.kt`
- **Dart**: `.dart`
- **C#**: `.cs`
- **Shell**: `.sh`, `.bash`
- **SQL**: `.sql`
- **Lua**: `.lua`
- **Scala**: `.scala`
- **R**: `.r`
- **Zig**: `.zig`
- **HTML**: `.html`, `.htm`
- **CSS**: `.css`, `.scss`, `.sass`

## Output Formats

- **Text**: Human-readable output (default)
- **Json**: Machine-readable JSON format
- **Markdown**: Markdown-formatted output
- **GitHub**: GitHub Actions workflow commands (`::error file=...::...`)

## Benchmarking

Run the built-in performance benchmark:

```bash
cargo run --example bench
```

This generates 100 files (500 lines each) and measures linting throughput. The linter processes multiple files in parallel using `rayon` for better performance on multi-core machines.

## Contributing

If you find this project helpful, please consider giving it a star ⭐️

Feedback, issues, and pull requests are welcome! Feel free to open an issue for bug reports, feature requests, or questions.

## License

Apache-2.0