@cruk/eslint-config
Version:
eslint rules for cruk typescript projects
78 lines (59 loc) • 2.19 kB
Markdown
These are settings for ESLint
This setup lints your JavaScript and TypeScript code based on the current recommended best practices.
```bash
npm i -D @cruk/eslint-config
```
If you are using a monorepo tool like NX with `nx run many -t=eslint` then you need to install dependencies for eslint in the root.
If you are using a monorepo tool like npm workspaces with `npm run eslint --ws --if-present` then you will need to install the eslint dependencies in each package
Create (or update) an `eslint.config.mjs` file in the root of your repo or if you have a mono repo in the root of each package. This is especially recommended if you have a large monorepo with many packages because running eslint on all packages at the same time could exceed JS heap size limits.
Kitchen sink expample where older configs are also included using some compatability tools:
```js
import { FlatCompat } from "@eslint/eslintrc";
import tsParser from "@typescript-eslint/parser";
import path from "path";
import { fileURLToPath } from "url";
import { fixupConfigRules } from "@eslint/compat";
import { config as crukConfig } from "@cruk/eslint-config";
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
const compat = new FlatCompat({
// import.meta.dirname is available after Node.js v20.11.0
baseDirectory: import.meta.dirname,
});
const config = [
...crukConfig,
...compat.config({
extends: ["next"],
settings: {
next: {
rootDir: ".",
},
},
}),
{
languageOptions: {
parser: tsParser,
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
},
rules: {
"@next/next/no-img-element": "off",
},
files: ["src/**/*.ts", "src/**/*.tsx", "playwright/**/*.ts"],
ignores: [".next", ".swc", "test-results", "node_modules"],
},
];
export default fixupConfigRules(config);
```
You can test your setup is correct by running
```
npx eslint --fix-dry-run .
```