Using Zeus with Eslint
Posted: Thu Feb 04, 2021 11:03 am
Installing Eslint
To install eslint run the following command from the command prompt:
Verify the install by running the following command:
That command should produce the following output:
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:
Once that command completes run the Eslint initialization using the following command:
If you fail to do this then the following error is produced:
Using Eslint Without a Package File
An alternative to creating a project is to use the following command line option:
Using that option it is possible to validate a parse a json file without the need to have first defined a project.
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:
Those settings should look like the screen shown below:
NOTE: To use Eslint for TypeScript files just repeat the steps for the TypeScript Document Type.
In the project folder initialized earlier, create a test.js file shown below:
Now with test.js as the active file use the Compiler, Compile menu to run the linter.
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:
Now when the Compiler, Compile menu is use the broken code will be automatically fixed and reloaded into the editor, replaced with the code shown below:
More command line options can be found here: https://eslint.org/docs/user-guide/comm ... -interface
Cheers Jussi
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