To install eslint run the following command from the command prompt:
Code: Select all
npm i -g eslint
Code: Select all
eslint -h
More details on these command line options can be found here: https://eslint.org/docs/latest/user-guide/command-line-interfaceeslint [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
By default Eslint needs a project folder containing a package.json file to run.
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
Code: Select all
Oops! Something went wrong! :(
ESLint: 8.22.0
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
npm init @eslint/config
ESLint looked for configuration files in C:\Projects and its ancestors. If it found none, it then looked in your home directory.
If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
An alternative to creating a project is to use the following command line option:
Code: Select all
--no-eslintrc
Using Eslint inside Zeus
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: cmd.exe /c eslint --no-eslintrc "$fn"
Lines Regex: [0-9]+:[0-9]+[ ]+
Errors Regex: [0-9]+:[0-9]+[ ]+error
Warnings Regex: [0-9]+:[0-9]+[ ]+warning
[attachment=1]eslint-comp.png[/attachment]
[x] Capture Standard Output [x] Capture Standard Error
(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