To install eslint run the following command from the command prompt:
Code: Select all
npm i -g eslint
Code: Select all
eslint -h
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-eslintrc Disable use of configuration from .eslintrc.*
-c, --config path::String Use this configuration, overriding .eslintrc.* config options if present
--env [String] Specify environments
--ext [String] Specify JavaScript file extensions
--global [String] Define global variables
--parser String Specify the parser to be used
--parser-options Object Specify parser options
--resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default
.......
Initializing Eslint
For Eslint to work it needs a project folder containing a package.json file.
The simplest way to do create this project structure is to npm using the following command:
Code: Select all
npm init
Code: Select all
eslint --init
Start Zeus and use the Options, Document Types menu to edit the JScript Document Type.
In the Compiler panel enter the following details:
Code: Select all
Command Line: eslint "$fn"
Lines Regex: [0-9]+:[0-9]+[ ]+
Errors Regex: [0-9]+:[0-9]+[ ]+error
Warnings Regex: [0-9]+:[0-9]+[ ]+error
[attachment=1]eslint-comp.png[/attachment]
(o) Display on errors and warnings
In the project folder initialized earlier, create a test.js file shown below:
Code: Select all
if (!!(typeof window === 'undefined')) {
console.log('Hello from Node.js!');
}
That should result in the output shown below: Clicking on the error should then navigate you back to the line and column where the error is found.
Using Eslint with the Fix Option
If you change the command line described earlier to be the following:
Code: Select all
eslint --fix "$fn"
Code: Select all
if (typeof window === 'undefined') {
console.log('Hello from Node.js!');
}
Cheers Jussi