# Writing scenarios

## 9. Syntax check

It checks the scenarios and project files before running. Mistakes are reported with the line and a suggested fix.

### Where it runs

| Place | What it does |
|---|---|
| `lim check` | Checks every scenario in the project. `--json` gives machine-readable output |
| The VS Code extension, the Studio editor | Run the same check while you write and underline mistakes with a wavy line |
| `lim build` | Checks before exporting |

`lim check` fails (exit code 1) if there is even one error. With only warnings, it succeeds.

### Reading the output

The messages are in Japanese by default; with `--lang en` they're in English. For example, `lim check --lang en` prints:

```
start:12 error [unknown-label] The label #nort_road isn't in this file
    → Did you mean #north_road?

1 files, 1 errors, 0 warnings
  unknown-label: 1
```

Each diagnostic has the following. With `--json`, each element of `diagnostics` has this form.

| Item | Contents |
|---|---|
| `file` `line` `column` | Location. Lines and columns count from 1. The column is omitted for problems with a whole line |
| `severity` | `error`, `warning`, `info` |
| `code` | A machine-readable identifier (`unknown-label` and so on). `lim explain code` shows a description, examples and how to fix it |
| `message` | What is happening |
| `hint` | Suggested fix. Written, where possible, as the line itself fixed rather than as a fixed template. Sometimes there is none |
| `fix` | A line fix a machine can apply (`replace` replaces `find` with `with`, and `delete-line` deletes the line). Sometimes there is none |
| `fixes` | Candidate fixes, in order of recommendation. Besides line fixes, it includes ones that rewrite things outside the line (`add-speaker`: adds `name` to `speakers` in cast.json; `add-label`: adds a `# label` line at the end of `file` to create the scene) |

Diagnostics are sorted by file, line and column (`--json` too).

Command names, parameter names, labels, files, characters and speakers with a similar spelling appear in the suggested fix as "Did you mean …?"
For labels and files, only names that differ little relative to their length are suggested (`#start` isn't suggested for `#stay`).
For a jump target that doesn't exist, "Create the scene" (`add-label`) comes before replacements. For a value of the wrong type, the suggested fix is the line with only the value fixed
(removing `who=` attached to an unnamed parameter, and for a duration without a unit, `1s` for a small number and `300ms` for a large one).
