lintobot 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -3
- package/dist/cli.js +541 -222
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# lintobot
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/lintobot)
|
|
4
|
+
|
|
3
5
|
A code linter whose rules are plain-language sentences answered by a **decision model** (Jev and similar). No AST rules to write: you state what must be true of a file, the model says how sure it is that it isn't.
|
|
4
6
|
|
|
5
7
|
```
|
|
@@ -18,7 +20,39 @@ Reads or writes files on disk
|
|
|
18
20
|
|
|
19
21
|
❌ and ⚠️ are rules that look broken, ✅ rules that hold. The plain line under a file name lists observations that are true of it.
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
## What it is for
|
|
24
|
+
|
|
25
|
+
`lintobot.yml` is where you describe what good code is for you. Its rules are **intentions**, the code you would like to see, not laws.
|
|
26
|
+
|
|
27
|
+
- **It knows what a file is for.** Name the purposes a file may have and lintobot says which one it serves, and fails the file that serves the wrong one: a job doing a controller's work, a project-scoped controller that is not about one project. See [Composition](#composition).
|
|
28
|
+
- **Smarter than a linter, cheaper than an agent.** It can tell whether a comment matches the code under it, whether a function belongs in its file, whether a file is about one thing. It answers in a fraction of the time and cost of a subagent reading the same file.
|
|
29
|
+
- **Signals, not problems.** A finding is advice to look, not a call to action. Hand findings to an agent or a reviewer, who reads the code and decides whether there is anything to fix.
|
|
30
|
+
- **Not deterministic.** The answer is a probability; it can move a few points between runs. Results are not strict and should not be read as proof.
|
|
31
|
+
- **Flexible.** Every rule has its own thresholds. Lower `error` on a rule you want enforced hard, raise it or switch it off on one you only want to hear about. The exit code follows what you set.
|
|
32
|
+
- **Strict rules go to the real linter.** What must hold exactly and can be read from syntax ("all methods are private except perform") is better checked by RuboCop, ESLint or Biome. The `linto-lint` skill finds such rules in `lintobot.yml`, sets them up in the linter and comments them out.
|
|
33
|
+
|
|
34
|
+
Start every code file with a few basic checks and add your own intentions on top:
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
rules:
|
|
38
|
+
- "no duplicated code"
|
|
39
|
+
- "no magic numbers"
|
|
40
|
+
- "no comments that restate the code"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If the project has a `CLAUDE.md` or `AGENTS.md`, the intentions are already written down. The `lintobot` skill (`lintobot skill --install`) tells an agent to read them and turn every statement about how the code should look into a rule.
|
|
44
|
+
|
|
45
|
+
It pairs well with a coding agent: run it from a hook after the agent edits a file, or on a pull request over the changed files, and give the output to the agent as things to review.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
lintobot --diff # what changed since the last commit: after an agent's edits
|
|
49
|
+
lintobot --diff origin/main # what this branch changes: on a pull request
|
|
50
|
+
lintobot --staged # what is staged: in a pre-commit hook
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Only the lines a change adds are checked, in files the config's patterns match; no change means nothing is checked. See [Changed code only](#changed-code-only).
|
|
54
|
+
|
|
55
|
+
> Early version. Yes/no rules, formulas, file facts, context and large-file handling work. Calibration and the other items of the roadmap are specified in [SPEC.md](SPEC.md) but not built yet.
|
|
22
56
|
|
|
23
57
|
## Install
|
|
24
58
|
|
|
@@ -148,6 +182,84 @@ The config is [scripted-yaml](https://www.npmjs.com/package/scripted-yaml): a ke
|
|
|
148
182
|
|
|
149
183
|
`file` has `path`, `dir`, `name`, `ext`, `lines`, `code_lines`, `comment_lines`, `blank_lines`, `longest_line`, `max_depth`, `complexity`, and the lists `imports` and `exports`. A rule whose formulas never read `confidence` makes no model call.
|
|
150
184
|
|
|
185
|
+
### Composition
|
|
186
|
+
|
|
187
|
+
A composition measures what a file is made of. You name the categories; the result is the share of the file in each, and formulas over `share` say which mix is wrong:
|
|
188
|
+
|
|
189
|
+
```yaml
|
|
190
|
+
files:
|
|
191
|
+
- pattern: "app/controllers/**/*.rb"
|
|
192
|
+
rules:
|
|
193
|
+
- composition:
|
|
194
|
+
code: Ordinary Ruby logic
|
|
195
|
+
sql: Raw SQL strings or query fragments
|
|
196
|
+
template: HTML or other markup built in code
|
|
197
|
+
error!: share.sql > 0.1
|
|
198
|
+
warning!: share.template > 0.05
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
app/controllers/orders_controller.rb
|
|
203
|
+
❌ Ordinary Ruby logic (51%) sql|template sql 31% > 10% lines 31–45
|
|
204
|
+
|
|
205
|
+
app/controllers/users_controller.rb
|
|
206
|
+
✅ Ordinary Ruby logic (100%) sql|template
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
One line per composition: the largest category, in the words of its description (its name when it has none), with its percent, then the names of the other categories, separated by `|`. The same names joined by `|` are the composition's name in the records and for `--rule`, unless it has an `id`. A failed one adds the comparison that is true and the lines where that category is. All the shares are in the `json` and `jsonl` record.
|
|
210
|
+
|
|
211
|
+
Every key is a category and its value an optional description for the model; a name that says enough needs none. `other` is always added, so a piece is never forced into a wrong category: do not add your own `neither` or `none`. Formulas read it like any category (`error!: share.other > 0.3`), and writing `other: <description>` yourself tells the model what belongs there. Category names are identifiers: `raw_sql`, not `raw-sql`.
|
|
212
|
+
|
|
213
|
+
The file is cut into pieces of about 15 lines and each is asked which category it mostly is. A share is the model's probabilities weighted by the size of the piece, so a piece that is half SQL counts as half. Shares run from 0 to 1 and add up to 1.
|
|
214
|
+
|
|
215
|
+
| Key beside the categories | Meaning |
|
|
216
|
+
|---|---|
|
|
217
|
+
| `error!`, `warning!` | Formulas over `share.<category>` and `file`. Without either, the composition is only shown and never fails |
|
|
218
|
+
| `$if!`, `except` | Which files it applies to, as on a rule |
|
|
219
|
+
| `max_lines` | Piece size, 5 or more (default 15). Smaller pieces give finer shares for more calls |
|
|
220
|
+
| `ask` | The question to send instead of "which of these is most of the code?" |
|
|
221
|
+
| `id` | Short name, printed and usable with `--rule` |
|
|
222
|
+
| `context` | Extra material, as on a rule |
|
|
223
|
+
|
|
224
|
+
A composition has no `confidence` and no thresholds: `share.sql > 0.1` is the rule. Useful shapes: `share.exports > 0.9 and file.lines > 300`, `share.assertions < 0.1` for a test file, `share.state > 0.4 and share.template < 0.3` for a component.
|
|
225
|
+
|
|
226
|
+
#### The purpose of a file
|
|
227
|
+
|
|
228
|
+
The categories do not have to be kinds of code. Make them the **purposes** a file may have, described as statements about the file, and a composition tells you what each file is for, and fails the ones in the wrong place:
|
|
229
|
+
|
|
230
|
+
```yaml
|
|
231
|
+
files:
|
|
232
|
+
- pattern: "app/controllers/projects/**/*.rb"
|
|
233
|
+
rules:
|
|
234
|
+
- composition:
|
|
235
|
+
project: focused on a single Project and has a @project instance
|
|
236
|
+
nonproject: works across projects or without any project
|
|
237
|
+
error!: share.project < 0.7
|
|
238
|
+
|
|
239
|
+
- pattern: "app/jobs/**_job.rb"
|
|
240
|
+
rules:
|
|
241
|
+
- composition:
|
|
242
|
+
bulk: processes many records in batches
|
|
243
|
+
external: calls an outside service or API
|
|
244
|
+
io: reads or writes files
|
|
245
|
+
error!: share.other > 0.7 # a job that does none of the things a job is for
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
app/controllers/projects/runs_controller.rb
|
|
250
|
+
✅ focused on a single Project and has a @project instance (93%) nonproject
|
|
251
|
+
|
|
252
|
+
app/controllers/projects/search_controller.rb
|
|
253
|
+
❌ works across projects or without any project (64%) project project 31% < 70%
|
|
254
|
+
|
|
255
|
+
app/jobs/cleanup_job.rb
|
|
256
|
+
❌ other (94%) bulk|external|io other 94% > 70% lines 1–47
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The report reads as a sentence about the file because the largest category is printed by its description, so write descriptions that way. Two ways to fail a wrong purpose: require the right one (`share.project < 0.7`) or cap the catch-all (`share.other > 0.7`). With no formula at all you get a map of what every file is for and nothing fails.
|
|
260
|
+
|
|
261
|
+
It is always listed in the report, passed or not; `--quiet` drops the passed ones. The `json` and `jsonl` record has `"type":"composition"` with `share`, and `areas`: per category, the lines of the pieces that are mostly it. One call is made per piece, so a long file costs more calls than a check does. With `--diff`, a composition is measured only on new files: added lines alone cannot say what a file is made of. It needs a provider on the TypeSafe wire (OpenRouter, AI/ML API, TypeSafe); the Vercel gateway is not supported for it yet.
|
|
262
|
+
|
|
151
263
|
### Context
|
|
152
264
|
|
|
153
265
|
Named extra material sent beside the code, at the top of the config, on a `files` entry, or on one rule:
|
|
@@ -204,6 +316,8 @@ lintobot [files...] files, folders or globs; everything in lintobot.yml w
|
|
|
204
316
|
-o, --output <file>
|
|
205
317
|
--files <path> relative to the project; repeatable
|
|
206
318
|
--rule <id or sentence> a rule or an info item; repeatable
|
|
319
|
+
--diff [ref] only added lines: since the branch left <ref>, or since the last commit
|
|
320
|
+
--staged only lines staged for the next commit
|
|
207
321
|
--dry-run
|
|
208
322
|
--quiet problems only
|
|
209
323
|
--no-cache answers are cached in .lintobot/cache/
|
|
@@ -230,10 +344,35 @@ Naming a folder or file narrows the run to the files in it that the config's pat
|
|
|
230
344
|
|
|
231
345
|
Exit codes: `0` clean · `1` errors · `2` bad usage or config · `3` model unreachable or checks skipped.
|
|
232
346
|
|
|
347
|
+
### Changed code only
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
lintobot --diff # lines added since the last commit, staged or not, and new untracked files
|
|
351
|
+
lintobot --diff origin/main # lines added since this branch left origin/main, uncommitted work included
|
|
352
|
+
lintobot --staged # lines `git commit` would add
|
|
353
|
+
lintobot app/jobs --diff main # the same, inside one folder
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
The ref is a branch, tag or commit. The changed files are narrowed by the config's patterns and by any paths you name; deleted files are left out. When nothing changed, nothing is checked and the exit code is `0`. It works from any folder of the repository, and when the project is a subfolder of it.
|
|
357
|
+
|
|
358
|
+
Only the lines the change **adds** are sent to the model, so a problem that was already in the file stays quiet:
|
|
359
|
+
|
|
360
|
+
```
|
|
361
|
+
src/engine/cache.ts (3 added lines)
|
|
362
|
+
❌ no magic numbers 96% lines 41–43
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
- A changed line counts as added; a file that only lost lines is not checked. A new file is checked whole.
|
|
366
|
+
- Findings name the added lines they come from.
|
|
367
|
+
- Rules marked `whole: true` and rules settled from facts alone (`warning!: file.lines > 500`) are not run on an existing file: added lines cannot answer for the whole file. Conditions such as `$if!: file.lines > 100` still see the whole file.
|
|
368
|
+
- A rule that says what a file must have ("has a @project attribute") reads a few added lines as a file without it. Mark such rules `whole: true`; rules about what must not appear ("no …") work on added lines as they are.
|
|
369
|
+
|
|
370
|
+
`--diff <ref>` needs the commit where the branch left the ref. A shallow clone does not have it: in GitHub Actions set `fetch-depth: 0` on the checkout step.
|
|
371
|
+
|
|
233
372
|
## What to expect from the model
|
|
234
373
|
|
|
235
374
|
- It returns probabilities only: no explanation, no line. The area of a large file is the closest it gets.
|
|
236
|
-
- Answers are
|
|
375
|
+
- Answers are not deterministic: close between runs (a few points) but not identical, and not calibrated: vague rules such as "no magic numbers" fire on most files until given `criteria`. Treat thresholds as something to tune on your own code.
|
|
237
376
|
- Code is sent to the provider you chose. `--dry-run` lists exactly which files.
|
|
238
377
|
|
|
239
378
|
## Development
|
|
@@ -249,4 +388,6 @@ bunosh probe <file> # five questions about one file, raw probabilities
|
|
|
249
388
|
|
|
250
389
|
### Releasing
|
|
251
390
|
|
|
252
|
-
Publish a GitHub release with a tag such as `v0.2.0`. The `Release to npm` workflow takes the version from the tag, runs the type check, the tests and the build, and publishes to npm (a pre-release goes to the `next` tag).
|
|
391
|
+
Publish a GitHub release with a tag such as `v0.2.0`. The `Release to npm` workflow takes the version from the tag, runs the type check, the tests and the build, and publishes to npm with provenance (a pre-release goes to the `next` tag).
|
|
392
|
+
|
|
393
|
+
No npm token is stored. The workflow uses npm trusted publishing: on npmjs.com the package lists this repository and the workflow file `release.yml` as its trusted publisher.
|