See https://www.npmjs.com/package/@jdpnielsen/eslint-flat-config
Provides extensible base eslint configuration. There are 4 variants;
npm install @noaignite-dk/eslint-config --save-dev
or
yarn add @noaignite-dk/eslint-config --dev
Use this configuration if your project uses JavaScript.
In your project's .eslintrc.js, add the following:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config'],
};
Use this configuration if your project uses TypeScript.
Create an eslint specific tsconfig file (tsconfig.eslint.json
) with the following contents:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": false,
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/.*.js",
],
"exclude": ["node_modules"]
}
Then, in your project's .eslintrc.js, add the following:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config/typescript'],
parserOptions: {
project: require.resolve('./tsconfig.eslint.json'),
},
};
Use this configuration if your project uses React + Typescript.
Create an eslint specific tsconfig file (tsconfig.eslint.json
) with the following contents:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": false,
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/.*.js",
],
"exclude": ["node_modules"]
}
Then, in your project's .eslintrc.js, add the following:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config/react'],
parserOptions: {
project: require.resolve('./tsconfig.eslint.json'),
},
};
Use this configuration if your project uses Next.js + Typescript.
Create an eslint specific tsconfig file (tsconfig.eslint.json
) with the following contents:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": false,
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/.*.js",
],
"exclude": ["node_modules"]
}
Then, in your project's .eslintrc.js, add the following:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config/next'],
parserOptions: {
project: require.resolve('./tsconfig.eslint.json'),
},
};
If Next.js isn't installed in your root directory (such as a monorepo) rootDir must be configured in .eslintrc.js
:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config/next'],
settings: {
next: {
rootDir: "packages/my-app/"
},
'import/resolver': {
typescript: {
project: require.resolve('./tsconfig.eslint.json'),
},
},
},
parserOptions: {
project: require.resolve('./tsconfig.eslint.json'),
},
};
Use this configuration to add sorting for your project.
Create an eslint specific tsconfig file (tsconfig.eslint.json
) with the following contents:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": false,
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/.*.js",
],
"exclude": ["node_modules"]
}
Then, in your project's .eslintrc.js, add the following:
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@noaignite-dk/eslint-config/import'],
};
This error typically occurs when eslint-import-resolver-typescript
cannot resolve the correct tsconfig.json
or a baseUrl
is missing.
Resolutions:
- Make sure a baseUrl is set:
(tsconfig.eslint.json
)
{
"compilerOptions": {
"baseUrl": "."
}
}
- Try explicitly passing the tsconfig to the resolver:
(.eslintrc.js
)
module.exports = {
// [...]
settings: {
'import/resolver': {
typescript: {
project: require.resolve('./tsconfig.eslint.json'),
},
},
},
parserOptions: {
project: require.resolve('./tsconfig.eslint.json'),
},
};
Install all necessary development dependencies by running npm install --dev