Riccardo D’Ambrosio recently released RSLint, a linter for JavaScript that is written entirely in Rust. RSLint strives to be as fast as possible, customizable, and easy to use. RSLint is still in the early phase of its development and features basic Visual Studio Code integration.

RSLint’s creator described his motivation as follows:

The project is a fully-fledged JavaScript linter but written from scratch in Rust. I felt existing linters were too limiting and slow and decided to try and make one myself with some key points in mind:

speed: file loading, file linting, rule running are all parallelized

very rustc-like and friendly errors (including labels, notes)

error recovery: source code can be linted no matter how wrong it is

[…]

more powerful directives

As any linter, RSLint strives to help developers enforce good practices and flag programming errors, bugs, stylistic errors, and suspicious constructs. Linters are generally used within a code editor to provide real-time feedback while editing. Users working on a large codebase with a sizable number of configured lint rules may benefit from the provided speed improvement in the form of faster real-time feedback.

Similarly, developer experience may be enhanced by friendly and explanatory message errors when a lint rule fails, especially so when rules are complex or refer to several other syntactic entities.

D’Ambrosio emphasized the error recovery capabilities of RSLint that are allegedly absent from some known linters:

Error recovery refers to a parser being able to take in incorrect source code, and still parse a mostly correct AST Abstract Syntax Treeout of it. Most linters do not attempt this at all, for example, espree, and swc_ecmascript (ESLint and deno_lint’s parsers respectively) make no attempt at recovery. When the parsers encounter an error they return an Err result and quit parsing, producing no AST.

[…] This means it is impossible for the linters to lint wrong code, which is an amazing feature for on-the-fly linting in things such as IDEs.

RSLint can parse the following code:

if true {
  /* */
} else {
  /* */
}

and lints it as follows:

error[SyntaxError]: Expected token `L_PAREN` but instead found `TRUE_KW`
  ┌─ tests\main.js:1:4
  │
1 │ if true {
  │    ^^^^ Unexpected

error[SyntaxError]: Expected token `R_PAREN` but instead found `L_CURLY`
  ┌─ tests\main.js:1:9
  │
1 │ if true {
  │         ^ Unexpected

error[no-constant-condition]: Unexpected constant condition
  ┌─ tests\main.js:1:4
  │  
1 │   if true {
  │      ^^^^ this condition is always truthy...
2 │     /* */
3 │   } else {
  │ ┌────────'
4 │ │   /* */
5 │ │ }
  │ └─' ...which makes this unreachable

#rust #javascript #programming #developer #web-development

RSLint, a New, Fast JavaScript Linter Written in Rust
2.20 GEEK