@finga/eslint-config

1.2.2 • Public • Published

@finga/eslint-config

This is a ready-for-action Eslint pack for TypeScript web projects and libs.

This pack verifies both syntax and semantics sanity, and formatting. So you do not need to use Prettier.

Install

npm i -D eslint @typescript-eslint/eslint-plugin@^5 \
github:fingerartur/eslint-plugin-import \
@finga/eslint-config

Configure

Create .eslintrc.js file with the following config:

// ./.eslintrc.js

module.exports = {
    root: true,
    extends: [ "@finga" ],
}

Create a dedicated tsconfig.eslint.json file, which will be used solely to tell Eslint what files it should process.

// ./tsconfig.eslint.json

{
  "include": [
    "**/*.ts",
    "**/*.js"
  ],
}

This tsconfig file is be used by default. If it does not exist, ESlint will still work, it will fall back to using tsconfig.json.

What does it do anyway?


It applies basic Eslint rules for JS and TS recommended by the authors of Eslint.

{
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
  ]
}

It applies awesome Eslint rules for import sorting and deduplication, with is a really powerful tool for resolving merge conflicts of module exports. (Just accept both changes and let Eslint do its magic.) Import sorting is powered by github:fingerartur/eslint-plugin-import.

{
  extends: [
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
  ]
}

It applies more relaxed Eslint rules for your JS config files, such as webpack.config.js, jest.config.js, etc.

(In general any JS file in the top level of your project is treated as a config file which runs in node environment, and it is not checked so strictly as source code.)


And lastly it applies a extra bunch of formatting rules

  • indent with 2 spaces
  • no semicolons
  • max line length 160 chars
  • enforce dangling comma
  • use single quotes only
  • enforce curly braces for if statements
  • enforce that object keys are not in quotes unless absolutely necessary
  • allow empty functions
  • allow rich auto-inference of TS types across functions and files

To learn precisely what configs are applied go and check out the config file.

Changelog

  • v1.2.2
    • Un-ignore directories lib, out, docs, doc.
  • v1.2.1
  • v1.2.0
    • Added support for JS config files such as webpack.config.js and jest.config.js
    • Automatically uses ./tsconfig.eslint.json if possible, the fallback is ./tsconfig.json if it exists, otherwise the TSconfig file must be configured manually
  • v1.1.0
    • Added rule to remove quotes around object keys
  • v1.0.0
    • TS, JS rules, import ordering, formatting rules

Readme

Keywords

Package Sidebar

Install

npm i @finga/eslint-config

Weekly Downloads

1

Version

1.2.2

License

MIT

Unpacked Size

10.5 kB

Total Files

5

Last publish

Collaborators

  • fingerartur