npm.io
13.1.1 • Published 5 months ago

@doist/eslint-config

Licence
MIT
Version
13.1.1
Deps
5
Size
30 kB
Vulns
0
Weekly
0

@doist/eslint-config

Doist ESLint config.

Usage

Install

npm install --save-dev @doist/eslint-config
Flat Config
// eslint.config.js
import eslintConfig from '@doist/eslint-config'

export default [
    // Core set of rules, recommended for all JS projects
    ...eslintConfig.recommended,
    // OR
    // Core set of rules, recommended for all TS projects
    ...eslintConfig.recommendedTypeChecked,

    // Additional rules for sorting/grouping import statements (optional)
    ...eslintConfig.simpleImportSort,

    // Recommended for projects using React.
    ...eslintConfig.react,
]
.eslintrc Config (Legacy)

In .eslintrc:

{
    // ...
    "extends": [
        // ...

        // Core set of rules, recommended for all projects.
        "@doist/eslint-config/eslintrc/recommended",

        // Additional rules requiring type information (recommended for TypeScript projects).
        "@doist/eslint-config/eslintrc/recommended-type-checked",

        // Additional rules for sorting/grouping import statements (optional)
        "@doist/eslint-config/eslintrc/simple-import-sort"

        // Recommended for projects using React.
        "@doist/eslint-config/eslintrc/react"
    ],

    // When using `recommended-type-checked`,
    // you need to link to `tsconfig.eslint.json` file (see section below) for the project.
    "parserOptions": {
        "project": "tsconfig.eslint.json"
    }
}
Path alias support for import sorting

If your project uses path aliases (e.g. @components maps to src/components/), you can configure simple-import-sort to group them together, between third-party and relative imports, by using simpleImportSortFactory.

Flat config:

// eslint.config.js
import eslintConfig from '@doist/eslint-config'

export default [
    ...eslintConfig.recommended,
    // Replace ...eslintConfig.simpleImportSort with a custom config:
    ...eslintConfig.simpleImportSortFactory({ aliases: ['@app', '@components'] }),
]

Legacy config — override the rule in .eslintrc:

const config = {
    extends: ['@doist/eslint-config/eslintrc/simple-import-sort'],
    rules: {
        'simple-import-sort/imports':
            require('@doist/eslint-config/lib/create-simple-import-sort').createSimpleImportSortConfig(
                { aliases: ['@app', '@components'] },
            ),
    },
}

Aliases are grouped together (no blank lines between them), ordered by their position in the array.

Configuring with type-checking

For type-based rules to work, project's tsconfig.json file needs to be specified in parserOptions.project. If you want to lint files not included in build, we recommend creating a separate tsconfig.eslint.json config and specifying it instead of the default one.

Note: In flat config, recommendedTypeChecked sets project: true by default, which auto-detects tsconfig.json.

Release a new package

This project uses semantic versioning. A new version will be published to both npm and GitHub Package Registry when a new tag is pushed. Please make sure an entry is added to CHANGELOG.md.

git checkout main
npm version <major|minor|patch>
git push --follow-tags