
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@atomspace/eslint
Advanced tools
Neutrino preset for adding ESLint config, following the Atom Space code style
@atomspace/eslint
is a Neutrino preset that supports linting JavaScript projects with ESLint config used in Atom Space.
@atomspace/eslint
can be installed using NPM. Inside your project, make sure neutrino
, eslint
and @atomspace/eslint
are development dependencies. You will also be using another Neutrino preset for building your application source code.
npm install --save-dev neutrino eslint "@atomspace/eslint"
After adding the Atom Space preset to your Neutrino-built project, edit your project's package.json
and .neutrinorc.js
to add the preset for linting before your build presets. Make it the first in the list of presets
let eslint = require('@atomspace/eslint');
module.exports = {
use: [
eslint()
// put your rest of presets here
]
};
{
"scripts": {
"build": "webpack --mode production",
"start": "webpack --mode development",
"lint": "eslint ./ --fix"
}
}
@atomspace/eslint
, provides an .eslintrc()
output handler for generating the ESLint configuration in a format suitable for use in an .eslintrc.js
file. This allows the ESLint CLI to be used outside of building the project, and for IDEs and text editors to provide linting hints/fixes.
Create a .eslintrc.js
file in the root of the project, containing:
let neutrino = require('neutrino');
module.exports = neutrino().eslintrc();
If you have a Neutrino build preset in .neutrinorc.js
, start the app in development mode via webpack --mode development
. Then check your console for any linting errors. If everything is successful, you should see no errors in the console. ESLint errors visible during development are reported, but will still continue to build and serve your project.
❯ npm start
✔ Development server running on: http://localhost:5000
✔ Build completed
ERROR in ./src/index.js
/src/index.js
7:1 warning Unexpected console statement no-console
7:14 error A space is required after '{' babel/object-curly-spacing
7:20 error Missing space before value for key 'hello' key-spacing
7:27 error A space is required before '}' babel/object-curly-spacing
✖ 4 problems (3 errors, 1 warning)
ESLint errors during production mode build will not build the project, and will cause the command to fail your build when creating a bundle via webpack --mode production
.
❯ npm run build
/src/index.js
6:1 warning Unexpected console statement no-console
6:14 error A space is required after '{' babel/object-curly-spacing
6:16 error Missing space before value for key 'a' key-spacing
6:17 error A space is required before '}' babel/object-curly-spacing
✖ 4 problems (3 errors, 1 warning)
error Command failed with exit code 1.
If you wish to customize what is included, excluded, or any ESLint options, you can provide an options object with the preset and this will be merged with defaults. Define eslint
property to override ESLint configuration.
Example: Include a plugin, browser and Node environments and turn off semicolons from being required as defined by the Atom Space rules.
let eslint = require('@atomspace/eslint');
module.exports = {
use: [
eslint({
eslint: {
plugins: ['fp'],
env: {
browser: true,
node: true
},
rules: {
semi: 'off'
}
}
})
]
};
This preset enables rules compatible with the latest EcmaScript version by default. This is suitable for the latest browsers or if you use transpilation during a build step. However in some cases old good ES5 may be required. You may disable modern features by overriding esnext
property:
module.exports = {
use: [
eslint({ esnext: false })
]
};
This will disable:
use strict
directive in every file)In case you want to check a compatibility with certain browsers you may pass browsers
option to settings. But it is recommended to use it only in case if there is no Babel transpilation for such browsers.
Configure supported browsers in .neutrinorc.js
(see browserslist):
module.exports = {
use: [
eslint({ browsers: ['ie >= 8'] })
]
};
If you want to check a compatibility with a NodeJS version pass node
option to settings. This will check the code for EcmaScript compatibility. It is recommended to use it only if there is no Babel transpilation.
module.exports = {
use: [
eslint({ node: '>=8.0.0' })
]
};
Also you can enable linting of NodeJS features and deprecated API providing engines
in your package.json. This will highlight usage of deprecated properties, methods and global variables.
{
"engines": {
"node": ">=8.3.0"
}
}
You can find more details how to run ESLint in the CLI in the official documentation.
Usually ESLint is a part of Webpack build configuration and any violation will prevent build and report errors. So it is not necessary to run ESLint separately during CI/CD for instance. But if you don't use Webpack and would like to include linting in your pipeline you can use this configuration of scripts
{
"scripts": {
"eslint": "eslint ./",
"pretest": "npm run eslint -- --max-warnings 0 --format codeframe",
"lint": "npm run eslint -- --fix"
}
}
Running of tests will lint before and fail if there are violations
❯ npm test
Running lint
command will auto-fix and report left violations
❯ npm run lint
To enable ESLint in Visual Studio Code you should have the ESLint extension installed.
These are suggested workspace settings related to @atomspace/eslint
rules:
{
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"jshint.enable": false,
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"javascript.format.enable": true,
"javascript.validate.enable": false,
"files.eol": "\n",
"files.insertFinalNewline": false,
"[markdown]": {
"editor.tabSize": 3,
"editor.insertSpaces": true
},
"eslint.options": {
"extensions": [".js", ".jsx", ".html", ".md", ".vue", ".json", ".jsonc", ".json5", ".json6"]
},
"eslint.validate": ["javascript", "javascriptreact", "html", "markdown", "vue", "json", "jsonc", "json5", "json6"],
"vetur.validation.template": false
}
When project has been initially installed you need to restart an editor. After this ESLint will start to highlight and auto-fix errors in your code on file save.
@atomspace/eslint
can work in your editor even if there is no build infrastructure (npm start
/ npm run build
). You can install it to any kind of JavaScript projects following the ESLint CLI guide above.
FAQs
Neutrino preset for adding ESLint config, following the Atom Space code style
The npm package @atomspace/eslint receives a total of 8 weekly downloads. As such, @atomspace/eslint popularity was classified as not popular.
We found that @atomspace/eslint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.