# GDScript linting

The lint pillar parses GDScript with a committed tree-sitter grammar WASM
(`data/tree-sitter-gdscript.wasm`, MIT, see [THIRD_PARTY_NOTICES.md](../THIRD_PARTY_NOTICES.md); loaded via `web-tree-sitter`) and runs a
conservative ruleset. No Godot binary, editor, or network is required. It is
exposed both as MCP tools (`lint_file`, `lint_project`) and as a CI-first CLI
(`gdcorrect`).

## Default ruleset

| Rule ID | Default | What it flags |
|---------|---------|---------------|
| `delta-misuse` | error | A plain `velocity = <speed> * delta` assignment (either operand order) in a function that calls `move_and_slide()` (double-scales; `move_and_slide()` already applies frame timing). Integrating an acceleration (`velocity += get_gravity() * delta`, `velocity.y += ...`), damping from the current velocity, and `* delta` inside call arguments (`move_toward`, `lerp`) are not flagged. |
| `delta-misuse` | info | `position`/`rotation` mutated in `_process`/`_physics_process` with no `delta` factor (frame-rate dependent). Same rule id, softer sub-pattern. |
| `get-node-in-process` | warning | `$` / `get_node()` lookups inside `_process`/`_physics_process` (runs every frame). |
| `missing-onready` | warning | Class-level node-path member initialized without `@onready`. |
| `untyped-declaration` | warning | `var x = ...` with neither a type hint nor `:=` inference. |
| `await-misuse` | warning | `await` applied to a literal value. Conservative: literals only. |
| `stringly-nodepath` | info | String-literal node path passed to `get_node()`/`NodePath()`/etc. (rename-fragile). |
| `connect-without-disconnect` | info | `connect()` in `_ready()` with no `disconnect()` anywhere and no `CONNECT_ONE_SHOT`. |
| `float-grid-equality` | info | `==`/`!=` where an operand is a float literal or `Vector2/3/4(...)` (precision). |
| `removed-api-usage` | warning | Target version from `project.godot` `config/features` (or `targetVersion`). Engine API that was removed in the target Godot version, calls whose argument count becomes invalid, and overrides of engine virtuals that were removed or changed arity. See below. |

Detection is deliberately conservative: for a CI gate, false positives are worse
than misses. Only `error`-severity findings fail the CLI (exit 1).

## Configuration

Place `godot-correctness.config.json` at the project root. All fields optional;
defaults apply when the file is absent. See
[`godot-correctness.config.example.json`](../godot-correctness.config.example.json).

```json
{
  "include": ["**/*.gd"],
  "exclude": ["**/.godot/**", "**/addons/**"],
  "rules": {
    "untyped-declaration": { "severity": "info" },
    "float-grid-equality": { "enabled": false }
  },
  "registryDirs": [],
  "pathPropertyPatterns": ["*_path", "*_scene"]
}
```

- `include` / `exclude`: glob sets (picomatch), relative to the project root.
  Defaults: include `**/*.gd`, exclude `**/.godot/**`. `addons/` **is linted by
  default**; add `"addons/**"` to `exclude` to skip third-party plugins.
  Excluded directories are not descended into, and `.git/` and `.godot/` are
  always skipped.
  - `include` selects the `.gd` files for **every** script check: lint,
    `scene-node-path-missing`, and `project-input-action-undefined`.
  - `exclude` applies to every check: the script checks above and the `.tscn`
    and registry `.tres` walks (so excluding `**/addons/**` also skips scene
    validation there). `uid://` lookups still see excluded files, since
    references into them are valid.
- `rules.<id>.enabled`: set `false` to disable a rule.
- `rules.<id>.severity`: override to `error` / `warning` / `info`. A config
  override wins over a rule's per-finding severity.
- `enabled` and `severity` apply to every rule id gdcorrect reports: the lint
  rules here and the `scene-*`, `project-*`, and `registry-*` checks in
  [scenes.md](scenes.md).
- `rules.<id>.options`: per-rule options (currently read by `removed-api-usage`).
- `registryDirs`, `pathPropertyPatterns`: list your `.tres` registry directories in `registryDirs` to enable the registry validator (see [scenes.md](scenes.md)).

Unknown top-level keys (for example a typo like `exlude`), unknown rule ids in
`rules`, and unknown keys inside a rule entry (for example `enable` or
`sevrity`) are rejected with an error naming the config file, rather than
silently ignored. `$schema` and `$comment` are allowed. A `registryDirs` entry
that does not exist is reported as `registry-dir-missing`.

`lint_file` and `lint_project` use the same config: `lint_file` loads it from
the nearest ancestor directory that contains `godot-correctness.config.json` or
`project.godot`.

## Upgrading Godot: `removed-api-usage`

By default the target is read from `project.godot`: the version in
`[application] config/features=PackedStringArray("4.5", ...)`, mapped to the
newest pinned symbol database that is not newer than it (a 4.6 project is checked
against 4.5). `lint` output reports it as `godotVersion`. The source version
defaults to the pinned version before the target, so a project on the oldest
pinned version (4.4) gets no findings. To choose the versions yourself (for
example before upgrading):

```json
{ "rules": { "removed-api-usage": { "options": { "targetVersion": "4.5" } } } }
```

Options: `targetVersion` (one of the pinned versions: `4.4`, `4.5`) and
`fromVersion` (another pinned version; it may be newer than the target to check
a downgrade). Any other value is a config error (exit 2). Projects with no
version in `config/features` and no `targetVersion` skip the rule; disable it
with `"enabled": false`.
Using the committed symbol databases, it flags:

- members removed between the versions (methods, properties, signals,
  constants), accessed through receivers whose type is statically certain:
  bare or `self.` calls in a script that `extends` a built-in class,
  `ClassName.member`, and variables/parameters with an explicit built-in type;
- calls whose argument count was valid before and is invalid after (new
  optional parameters never trigger it);
- script methods overriding engine virtuals that were removed in the target or
  whose parameter count changed, which the engine would stop calling.

Members that moved to a parent class are not reported. Untyped receivers are
never guessed at; use `api_diff` for anything else.

## Inline suppressions

Silence a specific finding without disabling the rule project-wide:

```gdscript
var legacy = load_thing()  # gdcorrect-ignore[untyped-declaration]

# gdcorrect-ignore[get-node-in-process]
var hud := get_node("HUD")   # a comment-only directive applies to the next line

# gdcorrect-ignore-file[stringly-nodepath]   # whole file
```

- `# gdcorrect-ignore[rule-a, rule-b]` on a code line applies to that line; on a
  comment-only line it applies to the next line.
- Omit the brackets (`# gdcorrect-ignore`) to silence every rule on that line.
- A comment-only directive applies to the very next line, so keep it directly
  above the code (no blank line in between). Findings sit on the first line of
  a multi-line statement; put the directive there.
- Only real comments count: the text inside a string literal is ignored.
- `# gdcorrect-ignore-file[...]` applies to the whole file.
- Directives also silence the checks that report findings in `.gd` files:
  `scene-node-path-missing` and `project-input-action-undefined`.
- A directive that silences nothing is reported as an `unused-suppression`
  `info` finding so stale comments get cleaned up. Configure it like any rule
  (`"rules": { "unused-suppression": { "enabled": false } }`). The lint pass
  never reports a directive as unused when every rule it names is a
  scene/project check or is disabled in config. A bare `# gdcorrect-ignore`
  on a line that uses a node path or an input action is also never reported
  as unused, since it may be silencing one of those checks. Naming the rule
  explicitly is still clearer.

## CLI

```bash
gdcorrect lint <projectPath> --format json    # primary, machine-readable
gdcorrect lint <projectPath> --format pretty  # human-readable
gdcorrect lint <projectPath> --format sarif   # SARIF 2.1.0 for code scanning
gdcorrect lint <projectPath> --format github  # GitHub Actions annotations (::error file=...::)
gdcorrect lint <projectPath> --fail-on warning  # also fail on warnings
gdcorrect --help                              # every command, option, and exit code
```

Findings with a deterministic rewrite carry a `fix` (`description` plus `edits`
with 1-based `startLine`/`startCol`/`endLine`/`endCol`, end exclusive, and a
`replacement`); SARIF output includes them as `fixes`, and `gdcorrect lint --fix`
applies them in place. Today: `missing-onready` (adds `@onready`; exported
members are flagged without a fix, since combining `@onready` with `@export`
changes when the inspector value applies) and
`stringly-nodepath` (a bare `get_node("A/B")` with a plain path becomes `$A/B`).

JSON output for `lint` is a findings array (`file`, `line`, `col`, `ruleId`,
`severity`, `message`, `suggestion`) plus `fileCount` and severity counts. With
`--baseline`, each command keeps its own payload shape (baselined findings are
removed from every findings list and the counts are recomputed) and adds
`baselined` and `staleBaselineEntries`; the JSON matches the MCP tool given the
same `baseline`. A relative `--baseline` path resolves against the current
directory; the MCP tools' `baseline` argument resolves against the project root. Exit codes: **0** no findings at or
above `--fail-on` (default `error`), **1** otherwise, **2** on a usage, config,
or tool error.

### GitHub Actions

```yaml
- run: npx -y -p @tmhs/godot-correctness-mcp@^0.2 gdcorrect lint . --format json
```

The step fails the job (exit 1) when any `error`-severity finding is present.
