Linter
@noshift.js/lint is an official linter for NoShift.js that checks .nsjs files for syntax errors and style issues.
Installation
Install as a dev dependency:
npm install --save-dev @noshift.js/lint CLI Usage
The nslint command lints all .nsjs files in your project's rootdir (from nsjsconfig.json).
nslint You can also lint specific files:
nslint src/index.nsjs src/utils.nsjs Configuration
Create a nsjslinter.json file in the project root. You can generate one with defaults:
nslint init Config Structure
Each rule can be set to "error", "warning", or "off":
{
"rules": {
"unclosed-string": "error",
"unclosed-comment": "error",
"unclosed-template-expr": "error",
"unknown-caret-sequence": "error",
"lone-caret": "error",
"capitalize-eof": "error",
"uppercase-in-code": "warning",
"trailing-whitespace": "off",
"no-consecutive-blank-lines": "off"
}
} Rules
Available rules:
| Rule | Default | Description |
|---|---|---|
unclosed-string | error | Unclosed string literal (^2, ^7, ^@) |
unclosed-comment | error | Unclosed block comment (/^:...^:/) |
unclosed-template-expr | error | Unclosed template expression (^4^[...^]) |
unknown-caret-sequence | error | Unknown ^ sequence |
lone-caret | error | Lone ^ at end of file |
capitalize-eof | error | ^3 at end of file with no following character |
uppercase-in-code | warning | Uppercase letter in code (suggestion to use ^3) |
trailing-whitespace | off | Trailing whitespace |
no-consecutive-blank-lines | off | Consecutive blank lines |
Programmatic API
Use the linter as a library in your code:
import { lint, createDefaultConfig } from "@noshift.js/lint";
const messages = lint(source);
for (const m of messages) {
console.log(`${m.line}:${m.column} [${m.severity}] ${m.message} (${m.rule})`);
}