js-code-linter is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code.It is inspired from ESlint, JSLint and JSHint with a few exceptions:
- js-code-linter uses Espree for JavaScript parsing.
- js-code-linter uses an AST to evaluate patterns in code.
- js-code-linter is completely pluggable, every single rule is a plugin and you can add more at runtime.
Prerequisites: Node.js (^12.22.0, ^14.17.0, or >=16.0.0) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
To install run this command:
npm i js-code-linter
After that, you can run js-code-linter on any file or directory like this:
node_modules/js-code-linter/src/index.js --file <file-path.js>
To configure in your project add below line in package.json
.
"lint": "node_modules/js-code-linter/src/index.js",
After that, you can run js-code-linter in project using npm run lint
commad.
example:
npm run lint -- --file <file-path.js>
js-code-linter performs linting on your JavaScript code, primarily focusing on identifier (variable) declarations and the use of quotes.
It generates a new file <file-name>.linted.js
with all the tranformation.
Also give error message with line of code where the lint issue is present.
Variable Declaration Type Optimization:
-
js-code-linter automatically optimizes:
- variable declarations by transforming
var
identifiers tolet
orconst
as needed.
- variable declarations by transforming
-
Reassignment Analysis:
- It identifies variables whose values are reassigned and transforms them from
var
orconst
tolet
.
- It identifies variables whose values are reassigned and transforms them from
-
Constant Declaration:
- Variables that are never reassigned are transformed from
var
orlet
toconst
for better code consistency.
- Variables that are never reassigned are transformed from
- Double to Single Quote Conversion:
js-code-linter
convert double quotes""
to single quotes''
for consistent quoting style.
- After linting your code, js-code-linter generates a new file named
<file-name>.linted.js
, which includes all the transformations. This file is created in the same directory as the original file.
- js-code-linter provides error messages that pinpoint the location of linting issues in your code. Each error message includes the clickable line & column number, making it easy to identify and fix problems in your code.