Linter
@noshift.js/lint は NoShift.js の公式 linter で、.nsjs ファイルの構文エラーやスタイルの問題をチェックします。
インストール
開発依存としてインストール:
npm install --save-dev @noshift.js/lint CLI の使い方
nslint コマンドでプロジェクトの rootdir(nsjsconfig.json から)内のすべての .nsjs ファイルを lint します。
nslint 特定のファイルを指定することもできます:
nslint src/index.nsjs src/utils.nsjs 設定
プロジェクトルートに nsjslinter.json を作成します。デフォルト設定で生成できます:
nslint init 設定の構造
各ルールは "error"、"warning"、"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"
}
} ルール
利用可能なルール:
| Rule | Default | Description |
|---|---|---|
unclosed-string | error | 閉じられていない文字列リテラル(^2、^7、^@) |
unclosed-comment | error | 閉じられていないブロックコメント(/^:...^:/) |
unclosed-template-expr | error | 閉じられていないテンプレート式(^4^[...^]) |
unknown-caret-sequence | error | 不明な ^ シーケンス |
lone-caret | error | ファイル末尾の孤立 ^ |
capitalize-eof | error | ファイル末尾の ^3(対象文字なし) |
uppercase-in-code | warning | コード内の大文字(^3 の使用を推奨) |
trailing-whitespace | off | 末尾の空白 |
no-consecutive-blank-lines | off | 連続する空行 |
プログラマティック API
コード内からライブラリとして使用:
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})`);
}