@bitfactory/eslint-config v4.1.2
@bitfactory/eslint-config
This is a shareable config for ESLint. All the rules and configurations are already set. Rules can be overridden if needed.
!IMPORTANT
From ESLint v9 the Flat Config file is the default. Because of this change update thepackage.jsonnpm run scripts!See also the Release Roadmap https://github.com/bitfactory-nl/shared-npm-eslint-config-bitfactory/issues/83
For now the
eslintscripts can only be run with theESLINT_USE_FLAT_CONFIG=falseenvironment variable set like this. For examples how to add this to thepackage.json, please check out the CLI usage documentation.
:technologist: Development
Publishing
Before publishing a new version:
- Update the version number in the
package.jsonfile. - And also update the badges in the
README.mdfile, even for patches. - Create a new release, after merging the PR. This will trigger a workflow.
- The GitHub action workflow will then automatically create a new NPM package.
:package: Installing
Include the config into your project:
make npm "i @bitfactory/eslint-config --save-dev --save-exact"make pnpm "i @bitfactory/eslint-config --save-dev --save-exact"Then install the dependencies that the config needs:
make npx "install-peerdeps --dev --extra-args="-E" @bitfactory/eslint-config"make pnpm dlx "install-peerdeps --dev --extra-args="-E" @bitfactory/eslint-config"In your project, create an .eslintrc.js file with the following contents:
module.exports = {
extends: ['@bitfactory'],
};Vue.js projects
To use this config with a Vue.js project also install the following packages:
make npm "i eslint-plugin-vue eslint-plugin-vuejs-accessibility --save-dev --save-exact"make pnpm "i eslint-plugin-vue eslint-plugin-vuejs-accessibility --save-dev --save-exact"And set the following extend in .eslintrc.js:
module.exports = {
extends: ['@bitfactory/eslint-config/vue'],
};Vue 3 extra configuration
!IMPORTANT
For Vue 3 TypeScript is mandatory, so install the TS packages as described in the TypeScript section.
And set the following extend in .eslintrc.js:
module.exports = {
extends: [
'@bitfactory/eslint-config/vue',
'plugin:vue/vue3-recommended',
'@bitfactory/eslint-config/typescript',
],
};TypeScript projects
To use this config with a TypeScript project also install the following packages
!NOTE
Check and make sure a compatible TypeScript version is installed. Can be added with:make [p]npm i typescript.
make npm "i @typescript-eslint/eslint-plugin @typescript-eslint/parse --save-dev --save-exact"make pnpm "i @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev --save-exact"And set the following extend in .eslintrc.js:
module.exports = {
extends: ['@bitfactory/eslint-config/typescript'],
};Vue.js, TypeScript and regular JavaScript together
To use this config with a Vue.js, TypeScript and regular JavaScript together in one project make sure to install the packages from all three sections:
And set the following extend in .eslintrc.js:
module.exports = {
extends: [
'@bitfactory/eslint-config/vue',
// 'plugin:vue/vue3-recommended', // <-- add this only for Vue 3
'@bitfactory/eslint-config/typescript',
],
};:rocket: CLI usage
To use ESLint in the command-line, add the following scripts to your projects package.json:
"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs}'",
"eslint:fix": "npm run eslint -- --fix"
}"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs}'",
"eslint:fix": "pnpm run eslint --fix"
}To also check Vue.js files:
"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs,vue}'",
"eslint:fix": "npm run eslint -- --fix"
}"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs,vue}'",
"eslint:fix": "pnpm run eslint --fix"
}Or TypeScript files:
"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs,ts,tsx}'",
"eslint:fix": "npm run eslint -- --fix"
}"scripts": {
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint 'path/to/your/assets/**/*.{cjs,js,mjs,ts,tsx}'",
"eslint:fix": "pnpm run eslint --fix"
}You can run the commands with:
make npm run eslint
make npm run eslint:fixmake pnpm run eslint
make pnpm run eslint:fixWith PNPM you can also run scripts without 'run' like
make pnpm eslint.
:pencil2: Editor / IDE integration
For ESLint to work, you need to set up your editor / IDE. See also https://eslint.style/guide/faq#how-to-auto-format-on-save
Visual Studio Code
- Install the ESLint extension
- Add the following settings via
Code→Preferences→Settings - Get linting :rocket:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}Additional Extensions
- Error Lens to get inline error messages
:warning: If you have the Prettier extension enabled, make sure to disable the extension for your project's workspace. This is because Prettier's rules will conflict with ours.
PhpStorm
Go to Preferences | Languages & Frameworks | JavaScript | Code Quality Tools | ESLint and set it to Automatic ESLint configuration
- Install the File Watchers plugin when not installed
- Add a new watcher in Preferences | Tools | File Watchers (\<custom>) with the follow data:
Name: ESLint
File type: Any
Scope: Project files
Program: $ProjectFileDir$/node_modules/.bin/eslint
Arguments: --fix $FilePath$
Output paths to refresh: $FileDir$
- Working directory & Environment variables -
Working directory: $ProjectFileDir$You can also select JavaScript, Vue.js or TypeScript files for File type, and copy the watcher for each needed file to only check those files
Or import the following xml file:
<TaskOptions>
<TaskOptions>
<option name="arguments" value="--fix $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="*" />
<option name="immediateSync" value="true" />
<option name="name" value="ESLint" />
<option name="output" value="$FileDir$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="$ProjectFileDir$/node_modules/.bin/eslint" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="$ProjectFileDir$" />
<envs />
</TaskOptions>
</TaskOptions>12 months ago
12 months ago
1 year ago
10 months ago
11 months ago
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago