Skip to content

Linter

View on npm

Terminal window
npm install -D @puruslang/linter

Or globally:

Terminal window
npm install -g @puruslang/linter
Terminal window
# Lint specific files
purus-lint src/main.purus
# Lint all files in a directory
purus-lint src
# Lint using config.purus settings
purus-lint

When no files are specified, purus-lint reads config.purus and lints all files in the entry directory.

You can pass files and directories as positional arguments.

OptionAliasDescription
--config <file>Path to config file
--help-hShow help
RuleDefaultDescription
no-varwarnAvoid var; use const or let
bare-assignmentwarnAvoid bare assignment without const/let/var
no-nilwarnUse null instead of nil
no-functionwarnfunction is deprecated; use fn
no-protectedwarnprotected is deprecated; use private
no-else-ifwarnUse elif instead of else if
no-js-charserrorJavaScript characters ((){}""''$#@“) are not allowed
no-js-operatorserrorJavaScript operators (===, !==, &&, ||, +=, -=, etc.) are not allowed
no-for-rangewarnfor ... in range is deprecated; use JS-style for loop
bracket-matcherrorUnmatched [ or ] brackets
const-reassignerrorCannot reassign a const variable
duplicate-usewarnDuplicate use import
indent-sizewarn (2)Indentation must be a multiple of N spaces
no-trailing-whitespacewarnNo trailing whitespace
max-line-lengthoff (100)Maximum line length
no-unused-importwarnWarn on unused imports
consistent-namingwarn (kebab-case)Naming convention

Linter settings can be configured in config.purus alongside build settings:

-- Linter settings
const lint.no-var be ///warn///
const lint.bare-assignment be ///warn///
const lint.no-nil be ///warn///
const lint.no-function be ///warn///
const lint.no-protected be ///warn///
const lint.no-else-if be ///warn///
const lint.no-js-chars be ///error///
const lint.no-js-operators be ///error///
const lint.bracket-match be ///error///
const lint.const-reassign be ///error///
const lint.duplicate-use be ///warn///
const lint.indent-size be 2
const lint.max-line-length be ///off///
const lint.no-trailing-whitespace be ///warn///
const lint.no-unused-import be ///warn///
const lint.consistent-naming be ///warn///
const { lint } = require("@puruslang/linter");
const diagnostics = lint("var x be 42");
// [{ rule: "no-var", severity: "warn", line: 1, col: 1, message: "..." }]