@wesp-up/eslint-config v2.1.0
@wesp-up/eslint-config
This project maintains base ESLint configuration for TypeScript projects. Each file may be extended and custom configuration may be added. We use the recommended rules as much as possible to gain great default support.
For ultimate productivity, configure your IDE to auto-lint when saving changes.
Installation
npm install --save-dev @wesp-up/eslint-config eslintUsage
In your
eslint.config.js(or alternative config entry), extend the config files that suit your project. For example:import config from '@wesp-up/eslint-config'; export default [...config];In your
tsconfig.json, include all TypeScript and JavaScript files via the following, including dot files.{ "include": ["**/*", ".*"] }- Be sure to also
excludeany files from yourtsconfignow that it is being used for both linting and transpiling. To get the full capabilities of linting with TypeScript, the parser must use the transpiler. If you would like to use a different
tsconfigfor linting, you can specify a new one viatsconfig.eslint.jsonthen add the following to youreslint.config.jsfile.{ "extends": "./tsconfig.json", "include": ["**/*", ".*"] }// eslint.config.js import config from '@wesp-up/eslint-config'; export default [ ...config, { languageOptions: { parserOptions: { project: './tsconfig.eslint.json', }, }, }, ];
- Be sure to also
In your
package.jsonadd the following scripts.{ "scripts": { "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .", "lint:fix": "npm run lint -- --fix" } }- Now test out linting via
npm run lintand fixable issues withnpm run lint:fix.
API
Below are each of the configuration files available and their explanations. Each config is composable and can be included with the other configs. Extend any configs that fit your project.
index.js: Base config for all TypeScript projects.lib.js: Config for a shared library meant to be installed in other projects.
FAQ
- Why do I get the error
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.?
The full error will look like the following:
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: <insert-file-name>.
The file must be included in at least one of the projects providedThis happens when a file should be included in linting when the TypeScript tsconfig.json is not including it. ESLint requires it to be included for TypeScript projects. This is why we recommend including all files in your tsconfig.json. For example, { "include": ["**/*", ".*"] }. This allows the entire project to adhere to the same linting and formatting rules.
- I'm using
supertest, why do I get the ESLint errorvitest/expect-expect?
This is because there are no assertions in the Vitest format. The way supertest performs its assertions is not always readable. Rather than doing this:
import request from 'supertest';
await request(app).get('/route').expect(200);Prefer to explicitly pull out the fields and use regular assertions:
import request from 'supertest';
const { status, body } = await request(app).get('/route');
expect(status).toBe(200);
expect(body).toEqual('some plain text');