linthis 0.22.0

A fast, cross-platform multi-language linter and formatter
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
# Creating Plugins

This guide explains how to create and distribute linthis plugins.

## What is a Plugin?

A linthis plugin is a Git repository containing:
- A `linthis-plugin.toml` manifest file
- One or more language configuration files (TOML, YAML, or JSON)
- An optional `linthis-hook.toml` that bundles hook source overrides
- Optional custom rules and presets

Plugins allow you to share lint configurations **and git/agent hook setups** across projects or teams.

## Plugin Structure

```
my-linthis-plugin/
├── linthis-plugin.toml           # Required: Plugin manifest
├── linthis-hook.toml           # Optional: Hook source overrides (auto-merged on plugin add)
├── config.toml                   # Main lint configuration
├── hooks/                        # Optional: Custom hook files
│   ├── git/
│   │   └── pre-commit            # Custom pre-commit script
│   └── agent/
│       └── plugins/
│           ├── _default/                     # Default fallback (all providers)
│           │   └── lt/                       # Plugin bundle
│           │       ├── skills/lt-lint/SKILL.md
│           │       ├── commands/
│           │       ├── memories/TOPLEVEL.md
│           │       └── hooks/hooks.json
│           └── claude/                       # Provider-specific override (optional)
│               └── lt/
│                   ├── skills/lt-lint/SKILL.md
│                   └── hooks/hooks.json      # Provider hooks (e.g. stop hook)
├── rules/                        # Optional: Additional rule configs
│   ├── strict.toml
│   └── relaxed.toml
└── README.md                     # Optional: Documentation
```

## Hook Bundling via `linthis-hook.toml`

A plugin can ship a `linthis-hook.toml` alongside its lint configs. This file declares `[hook.*]` source overrides that point back into the plugin itself using `plugin = "self"`.

When a user runs `linthis plugin add <alias> <url>`, linthis automatically:

1. Replaces every `plugin = "self"` reference with `plugin = "<alias>"` (the user's chosen alias)
2. Non-overwritingly merges `[hook.*]` entries into the user's `.linthis/config.toml`

After this, running `linthis hook install` will pick up the plugin's custom hook scripts and agent bundles automatically — no manual configuration needed.

### Example `linthis-hook.toml`

```toml
# Bundled inside the plugin. References use plugin = "self".

[hook.git]
pre-commit = { source = { plugin = "self", file = "hooks/git/pre-commit" } }

[hook.agent.plugins._default]
"lt" = { source = { plugin = "self", file = "hooks/agent/plugins/_default/lt" } }

[hook.agent.plugins.claude]
"lt" = { source = { plugin = "self", file = "hooks/agent/plugins/claude/lt" } }
```

After `linthis plugin add myteam <url>`, `plugin = "self"` becomes `plugin = "myteam"` and all entries are merged into the user's `.linthis/config.toml`.

## Plugin Manifest

The `linthis-plugin.toml` manifest describes your plugin:

```toml
[plugin]
# Required fields
name = "my-plugin"
version = "1.0.0"

# Optional fields
description = "Custom lint rules for my organization"
author = "Your Name <email@example.com>"
repository = "https://github.com/username/my-linthis-plugin"
license = "MIT"

# Minimum linthis version required (optional)
min_linthis_version = "0.1.0"

[config]
# Path to the main configuration file
path = "config.toml"

# Optional: Additional config files that can be referenced
# [config.presets]
# strict = "rules/strict.toml"
# relaxed = "rules/relaxed.toml"
```

## Configuration File

The main configuration file follows the standard linthis config format:

```toml
# config.toml

# Exclude patterns (will be merged with project config)
excludes = ["vendor/**", "third_party/**"]

# Default max complexity for this plugin's style guide
max_complexity = 15

# Rule modifications
[rules]
disable = ["E501"]  # Disable line length checks

[rules.severity]
"W0612" = "error"   # Treat unused variables as errors

# Custom rules
[[rules.custom]]
code = "org/no-fixme"
pattern = "FIXME|XXX"
message = "FIXME comments must be resolved before merge"
severity = "error"
suggestion = "Create a tracking issue or resolve the FIXME"

[[rules.custom]]
code = "org/copyright-header"
pattern = "^(?!// Copyright)"
message = "Missing copyright header"
severity = "warning"
extensions = ["rs", "go", "java"]

# Language-specific settings
[rust]
max_complexity = 12

[python]
excludes = ["*_test.py", "test_*.py"]
```

## Creating Your First Plugin

### Step 1: Create Repository

```bash
mkdir my-linthis-plugin
cd my-linthis-plugin
git init
```

### Step 2: Create Manifest

Create `linthis-plugin.toml`:

```toml
[plugin]
name = "my-plugin"
version = "1.0.0"
description = "My custom lint configuration"

[config]
path = "config.toml"
```

### Step 3: Create Configuration

Create `config.toml`:

```toml
# My organization's lint rules

excludes = ["generated/**"]
max_complexity = 20

[[rules.custom]]
code = "custom/no-console-log"
pattern = "console\\.log"
message = "Remove console.log before committing"
severity = "warning"
languages = ["typescript", "javascript"]
```

### Step 4: Test Locally

Before publishing, test your plugin locally:

```bash
# In your project's .linthis/config.toml
[plugins]
sources = [
    { name = "local-test", url = "file:///path/to/my-linthis-plugin" }
]
```

Then run:

```bash
linthis plugin init
linthis -c
```

### Step 5: Publish

Push to GitHub or any Git host:

```bash
git add .
git commit -m "Initial plugin release"
git tag v1.0.0
git push origin main --tags
```

## Using Your Plugin

Add to your project's `.linthis/config.toml`:

```toml
[plugins]
sources = [
    { name = "my-plugin", url = "https://github.com/username/my-linthis-plugin.git" }
]
```

Or pin to a specific version:

```toml
[plugins]
sources = [
    { name = "my-plugin", url = "https://github.com/username/my-linthis-plugin.git", ref = "v1.0.0" }
]
```

## Plugin Commands

```bash
# Initialize/download plugins
linthis plugin init

# List installed plugins
linthis plugin list

# Update all plugins to latest
linthis plugin update

# Update specific plugin
linthis plugin update my-plugin

# Clean plugin cache
linthis plugin clean
```

## Configuration Merging

Plugin configurations are merged with your project configuration. The precedence is:

1. **CLI arguments** (highest)
2. **Project config** (`.linthis/config.toml`)
3. **Plugin configs** (in order listed)
4. **User config** (`~/.linthis/config.toml`)
5. **Built-in defaults** (lowest)

Array fields (`excludes`, `includes`, `rules.disable`, `rules.custom`) are **extended** (added to), while scalar fields are **overridden**.

## Best Practices

### 1. Version Your Plugin

Use semantic versioning and Git tags:

```bash
git tag v1.0.0   # Initial release
git tag v1.1.0   # New features (backward compatible)
git tag v2.0.0   # Breaking changes
```

### 2. Document Your Rules

Add comments explaining each custom rule:

```toml
# Prevent debug code from being committed
[[rules.custom]]
code = "org/no-debug"
pattern = "debugger|console\\.debug"
message = "Debug code should not be committed"
```

### 3. Set Minimum Version

If your plugin uses features from a specific linthis version:

```toml
[plugin]
min_linthis_version = "0.2.0"
```

### 4. Provide Presets

For flexibility, offer multiple configuration levels:

```
my-plugin/
├── config.toml           # Default (recommended) settings
├── presets/
│   ├── strict.toml       # Stricter rules for CI
│   └── relaxed.toml      # More lenient for prototyping
```

### 5. Test Thoroughly

Before releasing, test your plugin:
- On multiple languages your rules target
- With existing project configurations
- After linthis updates

## Example Plugins

### Organization Style Guide

```toml
# linthis-plugin.toml
[plugin]
name = "acme-style"
version = "2.0.0"
description = "ACME Corp coding standards"

[config]
path = "config.toml"
```

```toml
# config.toml
max_complexity = 15
preset = "google"

[rules]
disable = ["E501"]  # We use 120-char lines

[[rules.custom]]
code = "acme/ticket-ref"
pattern = "TODO(?!.*\\[ACME-\\d+\\])"
message = "TODO comments must reference a JIRA ticket [ACME-XXX]"
severity = "warning"

[rust]
max_complexity = 12

[python]
max_complexity = 10
```

### Security Rules Plugin

```toml
# linthis-plugin.toml
[plugin]
name = "security-rules"
version = "1.0.0"
description = "Security-focused lint rules"

[config]
path = "security.toml"
```

```toml
# security.toml
[[rules.custom]]
code = "sec/no-eval"
pattern = "\\beval\\s*\\("
message = "Avoid eval() - potential code injection vulnerability"
severity = "error"
languages = ["javascript", "typescript", "python"]

[[rules.custom]]
code = "sec/no-hardcoded-secret"
pattern = "(password|secret|api_key|token)\\s*=\\s*['\"][^'\"]+['\"]"
message = "Potential hardcoded secret detected"
severity = "error"

[[rules.custom]]
code = "sec/no-http"
pattern = "http://"
message = "Use HTTPS instead of HTTP"
severity = "warning"
```

## See It in Action

Watch the [Plugin System video tutorial](../getting-started/videos.md#episode-3-plugin-system) for a 20-second demo.

## Troubleshooting

### Plugin not loading

1. Check `linthis plugin list` to see installed plugins
2. Run `linthis plugin init` to re-fetch
3. Verify the Git URL is accessible
4. Check for manifest errors in `linthis-plugin.toml`

### Configuration not applied

1. Check merge order (later plugins override earlier)
2. Verify the config file path in manifest
3. Run with `--verbose` to see config loading

### Version conflicts

If you see version compatibility errors:
1. Update linthis to the required version
2. Or use an older plugin version with `ref = "v1.0.0"`