Eslint config code complexity
- Add dev dependency:
npm install --save-dev eslint-config-code-complexity
yarn add -D eslint-config-code-complexity
- Add config extending in eslint config file (e.g.
... "extends": ["eslint-config-code-complexity"], ...
- complexity — Cyclomatic complexity measures the number of linearly independent paths through a program's source code. Complexity setted to 5 as maximum or error.
- max-params — Functions that take numerous parameters can be difficult to read and write because it requires the memorization of what each parameter is, its type, and the order they should appear in. As a result, many coders adhere to a convention that caps the number of parameters a function can take. This rule setted to 4 as maximum or error.
- max-statements — this rule specify the maximum number of statements allowed in a function. Setted to 7 as maximum or error.
- max-statements-per-line — A line of code containing too many statements can be difficult to read. Code is generally read from the top down, especially when scanning, so limiting the number of statements allowed on a single line can be very beneficial for readability and maintainability. This rule setted to 2 as maximum or error.
- max-depth — Many developers consider code difficult to read if blocks are nested beyond a certain depth. This rule setted to 3 as maximum or error.
- max-lines — Some people consider large files a code smell. Large files tend to do a lot of things and can make it hard following what's going. While there is not an objective maximum number of lines considered acceptable in a file, most people would agree it should not be in the thousands. Recommendations usually range from 100 to 500 lines. This rule setted to 150 as maximum or error.