My personal ESLint plugin.
npm install --save-dev eslint-plugin-wkovacs64
Be sure to install the appropriately versioned
eslint
peer dependency as well.
Several ESLint configs come bundled with this plugin. To use them, simply extend the relevant config(s) in your project's ESLint settings.
First, choose a single "core" config. It must come before the other configurations (described below)
in your extends
array.
Project Type | Extends |
---|---|
Base (no React) | 'plugin:wkovacs64/base' |
React | 'plugin:wkovacs64/react' |
Next, you may augment the core configuration by applying any combination of "feature" configs.
Feature | Extends |
---|---|
Jest | 'plugin:wkovacs64/jest' |
jest-dom | 'plugin:wkovacs64/jest-dom' |
Testing Library | 'plugin:wkovacs64/testing-library' |
TypeScript | 'plugin:wkovacs64/typescript' |
⚠️ Thetypescript
feature config requires theparserOptions.project
property to be set in your ESLint config. See the TypeScript parser options for more information.
- If you're using Cypress, you may need to add
ignorePatterns: ['cypress.config.ts']
to your ESLint config.- If you're using the
jest
feature config, you may need to disable the@typescript-eslint/unbound-method
rule and enable thejest/unbound-method
rule instead.
Finally, you may apply the Prettier config. This must be last in your
extends
array.
Extends |
---|
'prettier' |
Base "vanilla JS" project with Jest and Prettier:
module.exports = {
extends: ['plugin:wkovacs64/base', 'plugin:wkovacs64/jest', 'prettier'],
};
React project with Jest, jest-dom, Testing Library, and Prettier:
module.exports = {
extends: [
'plugin:wkovacs64/react',
'plugin:wkovacs64/jest',
'plugin:wkovacs64/jest-dom',
'plugin:wkovacs64/testing-library',
'prettier',
],
};
Base project with Jest, TypeScript, and Prettier:
module.exports = {
extends: [
'plugin:wkovacs64/base',
'plugin:wkovacs64/jest',
'plugin:wkovacs64/typescript',
'prettier',
],
parserOptions: {
project: 'tsconfig.json',
},
};
Kitchen sink:
module.exports = {
extends: [
'plugin:wkovacs64/react',
'plugin:wkovacs64/jest',
'plugin:wkovacs64/jest-dom',
'plugin:wkovacs64/testing-library',
'plugin:wkovacs64/typescript',
'prettier',
],
parserOptions: {
project: 'tsconfig.json',
},
ignorePatterns: ['cypress.config.ts'],
overrides: [
{
files: ['src/**/*.test.ts'],
rules: {
'@typescript-eslint/unbound-method': 'off',
'jest/unbound-method': 'error',
},
},
],
};
The dependency management overhead of separate shareable ESLint configs for each scenario finally
got to me. At the time of this writing, I no longer care if I get peerDependency warnings about
TypeScript in non-TypeScript projects (for example) anymore if it means managing a single dependency
(this package). The implementation details of this project were heavily inspired by
@shopify/eslint-plugin
.
The resolution of the "bundled" plugins may only be working as a happy accident due to Yarn (flatter
node_modules
) and possibly ESLint hoisting (unreliable). But until ESLint provides an official way
to include plugins as dependencies of shared configs, this will have to do. For reference:
This module is distributed under the MIT License.