NoA-Ignite-dk / eslint-config

ESLint config for JS projects
0 stars 0 forks source link

THIS IS NOW ARCHIVED - DO NOT USE IN NEW PROJECTS

See https://www.npmjs.com/package/@jdpnielsen/eslint-flat-config

@noaignite-dk/eslint-config

Commitizen friendly

Provides extensible base eslint configuration. There are 4 variants;

Installation

npm install @noaignite-dk/eslint-config --save-dev

or

yarn add @noaignite-dk/eslint-config --dev

@noaignite-dk/eslint-config

Use this configuration if your project uses JavaScript.

Usage

In your project's .eslintrc.js, add the following:

/** @type {import('eslint').Linter.Config} */
module.exports = {
    extends: ['@noaignite-dk/eslint-config'],
};

@noaignite-dk/eslint-config/typescript

Use this configuration if your project uses TypeScript.

Usage

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'),
    },
};

@noaignite-dk/eslint-config/react

Use this configuration if your project uses React + Typescript.

Usage

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'),
    },
};

@noaignite-dk/eslint-config/next

Use this configuration if your project uses Next.js + Typescript.

Usage

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'),
    },
};

@noaignite-dk/eslint-config/import

Use this configuration to add sorting for your project.

Usage

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'],
};

Common errors

1. Unable to resolve path to module '@alias/file'. eslint(import/no-unresolved)

This error typically occurs when eslint-import-resolver-typescript cannot resolve the correct tsconfig.json or a baseUrl is missing.

Resolutions:

  1. Make sure a baseUrl is set:

(tsconfig.eslint.json)

{
  "compilerOptions": {
    "baseUrl": "."
  }
}
  1. 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'),
    },
};

Development

Install all necessary development dependencies by running npm install --dev