2.0.15 • Published 9 months ago

@petbee/eslint-config v2.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@petbee/eslint-config

This package provides Petbee's ESLint configuration as an extensible shared config, supporting both ESLint v9.x (flat config) and older versions (.eslintrc).

Installation

Give that you already have ESLint installed, run:

yarn add -D @petbee/eslint-config typescript prettier

Usage

For ESLint v8.x and older (legacy config)

// .eslintrc
{
  "extends": ["@petbee/eslint-config"]
}

For ESLint v9.x (flat config)

// eslint.config.js
import petbeeConfig from '@petbee/eslint-config'

export default [
  ...petbeeConfig,
  // Your custom configurations...
]

For projects using both ESLint versions

If you need to support both ESLint versions in the same project, you can:

// eslint.config.js
import petbeeConfig from '@petbee/eslint-config'

export default [
  ...petbeeConfig,
  // Your custom configurations...
]

And maintain a .eslintrc file:

// .eslintrc
{
  "extends": ["@petbee/eslint-config"]
}

As any other eslint preset, it's possible to override some rules and configurations. We encourage trying to keep the closest possible to the preset rules, but every project is different and sometimes overriding is needed, use it carefully.

For typescript

The preset will automatically load Typescript rules when dealing with .ts or .tsx files. However, there are some rules that require type-checking. This means that a tsconfig.json, which includes all files supposed to be linted, must be present. If your existing configuration does not include all of the files you would like to lint, you can create a separate tsconfig.eslint.json, at the root of your project, as follows:

// tsconfig.eslint.json
{
  "extends": "./tsconfig.json",
  "include": ["**/*.ts", "**/*.tsx", "**/*.js"],
  "exclude": []
}

And you should be good to go.

For NestJS

The preset will automatically load NestJS rules when your projects has @nestjs/core installed. However, if you are using NestJS with Typescript, you need to make sure that the tsconfig.json file is present at the root of your project. If you are using a custom tsconfig.json, you can create a separate tsconfig.eslint.json file as follows:

// tsconfig.eslint.json
{
  "extends": "./tsconfig.json",
  "include": ["**/*.ts", "**/*.tsx", "**/*.js"],
  "exclude": []
}

This will ensure that the ESLint parser can find all the files that need to be linted.

For Javascript

Sometimes you want to use modern, not yet officially supported, syntax in your Javascript files, such as dynamic import(). This can be achieved by using the babel-eslint parser. For size reasons, we don't include it in this preset but it's extremely simple to configure it:

yarn add -D babel-eslint
// .eslintrc
{
  "extends": "@petbee/eslint-config",
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module"
  }
}

If a project uses both Typescript and Javascript, you can configure the parser inside an override block:

// .eslintrc
{
  "extends": "@petbee/eslint-config",
  "overrides": [
    {
      "files": ["*.js", "*.jsx"],
      "parser": "babel-eslint",
      "parserOptions": {
        "sourceType": "module"
      }
    }
  ]
}

Please check the babel-eslint documentation for further options.

References

1.0.17

10 months ago

1.0.16

10 months ago

2.0.15

9 months ago

2.0.3

9 months ago

2.0.2

9 months ago

2.0.13

9 months ago

2.0.5

9 months ago

2.0.14

9 months ago

2.0.4

9 months ago

2.0.11

9 months ago

2.0.7

9 months ago

2.0.12

9 months ago

2.0.6

9 months ago

2.0.9

9 months ago

2.0.10

9 months ago

2.0.8

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.1-alpha-1.0

2 years ago