@stuzo/eslint-config-stuzo
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-rc17 • Public • Published

ESLint config

This library was generated with Nx

It's intended to use on Node.js backends written mainly by using TypeScript 3.7+

What does offer this config?

  • Prettier rules are enabled by default and inffered from you prettier config, you don't need to duplicate them in ESLint config in order to avoid conflict (ESLint and Prettir will format code by using own rules)
  • Embedded overrides for test files for max-lines-per-function and max-statements (due to common practice to write test inside describe and it functions)
  • Let you know when you have to avoid any mentions and probably have to define interfaces and types properly to make codebase easy to read and maintain

What's about usage for large codebases which have been developing for many years?

It's ok that we contanstaly add new rules and codebase is not ready for that but we don't want to turn off those rules at all / make them as warnings, cause developers still will be able to don't apply these rules on new code while working on new feature.

In case like that we recommend to set up rules which are configured to produce errors in the default config for particular files, but what to do if there are thousands files?

We've designed a cli tool to update all files that don't follow best practices from current config and then you will be able to follow best practices while you developing new feature, lib or application without need to disable the rule.

# you need to install ESLint config then you'll be able to use command below
npx configure-eslint-rules --help
# then you can pass a folder or some particular file to this cli
# it uses ESLint in order to find any ESLint issues then adds eslint comments for file's header, that's all!
NODE_OPTIONS=--max-old-space-size=4096 npx configure-eslint-rules src/

Quick setup

npx install-peerdeps @stuzo/eslint-config-stuzo --dev

Add .eslintrc.json to the repo with the content below.

echo '{ "extends": "@stuzo/stuzo" }' > .eslintrc.json

ESLint should look like that:

{ "extends": "@stuzo/stuzo" }

(Optional) Add .prettierrc config to the project with content below:

{
  "singleQuote": true,
  "trailingComma": "all",
  "arrowParens": "avoid",
  "endOfLine": "lf",
  "printWidth": 120,
  "semi": true,
  "quoteProps": "as-needed"
}

Add to package.json to scripts section commands:

"scripts": {
  // NODE_OPTIONS=--max-old-space-size=4096 is required for large codebases, you should add in case if without --max-old-space-size eslint fails
  "lint": "NODE_OPTIONS=--max-old-space-size=4096 npx eslint src --cache --quiet",
  // you must add this hook to ensure that your didn't add by accident to your local eslint config any rules
  // which conflict with prettier config
  // to run this command on CI is preferable way to avoid mistakes
  "prelint": "npx eslint-config-prettier .eslintrc.json"
}

or by using npm (must be v7+, packaged with Node.js v15+)

npm set-script lint "NODE_OPTIONS=--max-old-space-size=4096 npx eslint src --cache --quiet"
npm set-script prelint "npx eslint-config-prettier .eslintrc.json"

(Optional) And finally you need to add config for husky and lint-staged to package.json if you still don't use Nx Workspaces:

"lint-staged": {
  "src/**/*.ts": [
    "yarn lint --fix",
    // or if you use npm
    "npm run lint -- --fix",
    "git add"
  ]
},
"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},

Then you can lint your code by using command:

$ npm run lint
# or
$ yarn lint

Readme

Keywords

none

Package Sidebar

Install

npm i @stuzo/eslint-config-stuzo

Weekly Downloads

536

Version

0.0.1-rc17

License

none

Unpacked Size

43.7 kB

Total Files

27

Last publish

Collaborators

  • vitaly.krivtsov