├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── index.js ├── internal-eslintrc.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Lockfile 2 | package-lock.json 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (http://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # Typescript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | internal-eslintrc.js -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License (ISC) 2 | 3 | Copyright 2017 Ryan Zimmerman 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose 6 | with or without fee is hereby granted, provided that the above copyright notice 7 | and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 11 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 13 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 14 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 15 | THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eslint-config-problems 2 | 3 | `eslint-config-problems` is an [ESLint](http://eslint.org/) config that doesn't regulate your code style. It only catches actual problems with your code. 4 | 5 | It's designed for use with [Prettier](https://prettier.io/), the opinionated code formatter. 6 | 7 | ## Contents 8 | 9 | 10 | 11 | 12 | - [Rules](#rules) 13 | - [I disagree with rule X; you missed rule Y](#i-disagree-with-rule-x-you-missed-rule-y) 14 | - [Installation & Usage](#installation--usage) 15 | - [License](#license) 16 | 17 | 18 | 19 | ## Rules 20 | 21 | Rules were chosen based on the following criteria: 22 | 23 | - No stylistic rules; nothing that Prettier can fix 24 | - Prevent guaranteed runtime errors (i.e. no undefined variables) 25 | - Disallow "evil" things like `eval` 26 | - Disallow archaic language features like `with` 27 | - Disallow obvious bad practices like `new Number(13)` 28 | - Force usage of ES2015+ features 29 | - Point out places the code could be made shorter. For example: 30 | ```js 31 | if (someCondition) return someValue; 32 | else { 33 | // Do something else 34 | } 35 | ``` 36 | The `else` block is unneeded, since the `if` block contains a `return` statement. `eslint-config-problems` will point this out to you (or auto-fix with the `--fix` option). 37 | 38 | ### I disagree with rule X; you missed rule Y 39 | 40 | If you disagree; feel free to open an issue. I'm open to changing rules if you have a good reason. 41 | 42 | If I missed a rule that prevents an actual problem or is otherwise in keeping with the general guidelines above, please open an issue as well; I just might add it. 43 | 44 | ## Installation & Usage 45 | 46 | _`eslint-config-problems` is designed to work with ESLint v9+; if you're still using ESLint v8 or earlier, use `eslint-config-problems` v8.0.0._ 47 | 48 | --- 49 | 50 | npm install -D eslint eslint-config-problems 51 | 52 | In your **eslint.config.js**: 53 | 54 | ```js 55 | import problems from 'eslint-config-problems'; 56 | 57 | export default [ 58 | problems, 59 | { 60 | rules: { 61 | // custom rules 62 | }, 63 | }, 64 | ]; 65 | ``` 66 | 67 | ## License 68 | 69 | [ISC](LICENSE) 70 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const js = require('@eslint/js'); 3 | 4 | module.exports = { 5 | rules: { 6 | ...js.configs.recommended.rules, 7 | // OVERRIDES FOR '@eslint/js' reccommended 8 | 'no-debugger': 'warn', 9 | 'no-empty': ['error', { allowEmptyCatch: true }], // Allow empty catch statements 10 | 'no-constant-condition': ['error', { checkLoops: false }], // Allow while (true) 11 | // WARNINGS 12 | 'no-console': 'warn', 13 | 'no-alert': 'warn', 14 | // PROBLEMS 15 | // https://eslint.org/docs/latest/rules/#possible-problems 16 | 'array-callback-return': ['error', { checkForEach: true }], 17 | 'no-constructor-return': 'error', 18 | 'no-duplicate-imports': 'error', 19 | 'no-promise-executor-return': 'error', 20 | 'no-self-compare': 'error', 21 | 'no-unmodified-loop-condition': 'error', 22 | 'no-unreachable-loop': 'error', 23 | 'no-use-before-define': ['error', { functions: false }], 24 | 'no-useless-assignment': 'error', 25 | 'require-atomic-updates': 'error', 26 | // https://eslint.org/docs/latest/rules/#suggestions 27 | 'accessor-pairs': 'error', 28 | 'dot-notation': 'error', 29 | 'eqeqeq': ['error', 'smart'], 30 | 'no-array-constructor': 'error', 31 | 'no-caller': 'error', 32 | 'no-else-return': 'error', 33 | 'no-eval': 'error', 34 | 'no-extend-native': 'error', 35 | 'no-extra-bind': 'error', 36 | 'no-implied-eval': 'error', 37 | 'no-iterator': 'error', 38 | 'no-labels': 'error', 39 | 'no-lone-blocks': 'error', 40 | 'no-lonely-if': 'error', 41 | 'no-loop-func': 'error', 42 | 'no-multi-str': 'error', 43 | 'no-new-func': 'error', 44 | 'no-new-wrappers': 'error', 45 | 'no-object-constructor': 'error', 46 | 'no-octal-escape': 'error', 47 | 'no-proto': 'error', 48 | 'no-script-url': 'error', 49 | 'no-sequences': 'error', 50 | 'no-undef-init': 'error', 51 | 'no-unneeded-ternary': ['error', { defaultAssignment: false }], 52 | 'no-useless-call': 'error', 53 | 'no-useless-computed-key': 'error', 54 | 'no-useless-constructor': 'error', 55 | 'no-useless-rename': 'error', 56 | 'no-useless-return': 'error', 57 | 'no-var': 'error', 58 | 'object-shorthand': 'error', 59 | 'prefer-arrow-callback': 'error', 60 | 'prefer-const': 'error', 61 | 'prefer-destructuring': [ 62 | 'error', 63 | { 64 | VariableDeclarator: { array: false, object: true }, 65 | AssignmentExpression: { array: false, object: false }, 66 | }, 67 | ], 68 | 'prefer-exponentiation-operator': 'error', 69 | 'prefer-numeric-literals': 'error', 70 | 'prefer-object-spread': 'error', 71 | 'prefer-regex-literals': 'error', 72 | 'prefer-rest-params': 'error', 73 | 'prefer-spread': 'error', 74 | 'prefer-template': 'error', 75 | 'strict': 'error', 76 | 'yoda': ['error', 'never', { onlyEquality: true }], 77 | }, 78 | }; 79 | -------------------------------------------------------------------------------- /internal-eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is the internal config used for linting the code of 4 | // eslint-config-problems itself 5 | 6 | module.exports = [ 7 | require('./index.js'), 8 | { 9 | languageOptions: { 10 | sourceType: 'commonjs', 11 | }, 12 | }, 13 | ]; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-problems", 3 | "version": "9.0.0", 4 | "description": "An eslint config that catches problems in your code, without checking style. For use with prettier.", 5 | "keywords": [ 6 | "eslint", 7 | "eslint-config", 8 | "eslintconfig", 9 | "formatting", 10 | "prettier" 11 | ], 12 | "homepage": "https://github.com/ryanzim/eslint-config-problems#readme", 13 | "bugs": { 14 | "url": "https://github.com/ryanzim/eslint-config-problems/issues" 15 | }, 16 | "license": "ISC", 17 | "author": "Ryan Zimmerman ", 18 | "main": "index.js", 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/ryanzim/eslint-config-problems.git" 22 | }, 23 | "scripts": { 24 | "eslint": "eslint -c internal-eslintrc.js .", 25 | "format": "npm run prettier -- --write && npm run eslint -- --fix", 26 | "test": "npm run eslint && npm run prettier -- --list-different", 27 | "toc": "doctoc README.md && prettier README.md --write", 28 | "prettier": "prettier \"**/*.{js,md,json}\"" 29 | }, 30 | "dependencies": { 31 | "@eslint/js": "^9.19.0" 32 | }, 33 | "devDependencies": { 34 | "doctoc": "^2.0.0", 35 | "eslint": "~9.19.0", 36 | "prettier": "^3.0.0" 37 | }, 38 | "peerDependencies": { 39 | "eslint": "^9.19.0" 40 | }, 41 | "prettier": { 42 | "singleQuote": true, 43 | "quoteProps": "consistent" 44 | }, 45 | "renovate": { 46 | "extends": [ 47 | "config:base", 48 | ":preserveSemverRanges", 49 | ":label(deps)" 50 | ] 51 | } 52 | } 53 | --------------------------------------------------------------------------------