Skip to content

Commit

Permalink
feat: remove unnecessary rules, migrate deprecated rules and tweak co…
Browse files Browse the repository at this point in the history
…nfigs
  • Loading branch information
frantic1048 committed Jul 9, 2024
1 parent 1dd301c commit 3b58e05
Show file tree
Hide file tree
Showing 25 changed files with 668 additions and 4,777 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"comment": "feat: remove unnecessary rules, migrate deprecated rules and tweak configs",
"type": "major",
"packageName": "@rightcapital/eslint-config-base",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"comment": "feat: remove unnecessary rules, migrate deprecated rules and tweak configs",
"type": "major",
"packageName": "@rightcapital/eslint-config-javascript",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"comment": "feat: remove unnecessary rules, migrate deprecated rules and tweak configs",
"type": "major",
"packageName": "@rightcapital/eslint-config-typescript-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
8 changes: 4 additions & 4 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib/index.js",
"lib/index.d.ts"
"lib"
],
"scripts": {
"prebuild": "pnpm run clean",
Expand All @@ -24,12 +23,13 @@
},
"dependencies": {
"@rushstack/eslint-patch": "1.10.3",
"@stylistic/eslint-plugin-js": "2.3.0",
"confusing-browser-globals": "1.0.11",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "npm:[email protected]",
"eslint-plugin-n": "17.9.0",
"eslint-plugin-simple-import-sort": "12.1.0",
"eslint-plugin-unicorn": "54.0.0",
"semver": "7.6.2"
"eslint-plugin-unicorn": "54.0.0"
},
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*",
Expand Down
69 changes: 1 addition & 68 deletions packages/eslint-config-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,15 @@ const config: Linter.Config = {
require.resolve('./rules/variables'),
require.resolve('./rules/es6'),
require.resolve('./rules/imports'),
require.resolve('./rules/strict'),
require.resolve('eslint-config-prettier'),
],
plugins: ['simple-import-sort', 'unicorn'],
env: { es6: true },
env: { es2024: true },
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
settings: {
'import/resolver': {
typescript: {},
},
},
reportUnusedDisableDirectives: true,
rules: {
curly: ['error', 'all'],

// not necessary or too opinionated
'default-param-last': 'off',
'class-methods-use-this': 'off',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',

/**
* We want to allow for...of statement, but airbnb config disables it.
* We override this rule from airbnb-base.
*
* airbnb config: https://github.com/airbnb/javascript/blob/5c01a1094986c4dd50a6ee4d9f7617abdfabb58a/packages/eslint-config-airbnb-base/rules/style.js#L338-L358
*/
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
{
/** https://stackoverflow.com/a/72903871/2488867 */
selector:
"MemberExpression[object.property.name='constructor'][property.name='name']",
message: 'constructor name is not reliable, do not use it.',
},
],

// MEMO: simple-import-sort/imports should not be used with import/order
'import/order': 'off',
'simple-import-sort/imports': 'error',

'simple-import-sort/exports': 'error',
'import/extensions': [
'warn',
'ignorePackages',
{
ts: 'never',
tsx: 'never',
js: 'never',
jsx: 'never',
},
],
'import/prefer-default-export': 'off',

'unicorn/prefer-node-protocol': 'error',
'unicorn/text-encoding-identifier-case': 'error',
},
};

export = config;
121 changes: 8 additions & 113 deletions packages/eslint-config-base/src/rules/best-practices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import type { Linter } from 'eslint';
// extracted from [email protected]
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-base-v15.0.0/packages/eslint-config-airbnb-base/rules/best-practices.js
const config: Linter.Config = {
plugins: ['unicorn'],
rules: {
// enforces getter/setter pairs in objects
// https://eslint.org/docs/rules/accessor-pairs
'accessor-pairs': 'off',

// enforces return statements in callbacks of array's methods
// https://eslint.org/docs/rules/array-callback-return
'array-callback-return': ['error', { allowImplicit: true }],
Expand All @@ -16,26 +13,13 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/block-scoped-var
'block-scoped-var': 'error',

// specify the maximum cyclomatic complexity allowed in a program
// https://eslint.org/docs/rules/complexity
complexity: ['off', 20],

// enforce that class methods use "this"
// https://eslint.org/docs/rules/class-methods-use-this
'class-methods-use-this': [
'error',
{
exceptMethods: [],
},
],

// require return statements to either always or never specify values
// https://eslint.org/docs/rules/consistent-return
'consistent-return': 'error',

// specify curly brace conventions for all control statements
// https://eslint.org/docs/rules/curly
curly: ['error', 'multi-line'], // multiline
curly: ['error', 'all'],

// require default case in switch statements
// https://eslint.org/docs/rules/default-case
Expand All @@ -45,17 +29,10 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/default-case-last
'default-case-last': 'error',

// https://eslint.org/docs/rules/default-param-last
'default-param-last': 'error',

// encourages use of dot notation whenever possible
// https://eslint.org/docs/rules/dot-notation
'dot-notation': ['error', { allowKeywords: true }],

// enforces consistent newlines before or after dots
// https://eslint.org/docs/rules/dot-location
'dot-location': ['error', 'property'],

// require the use of === and !==
// https://eslint.org/docs/rules/eqeqeq
eqeqeq: ['error', 'always', { null: 'ignore' }],
Expand Down Expand Up @@ -88,10 +65,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-constructor-return
'no-constructor-return': 'error',

// disallow division operators explicitly at beginning of regular expression
// https://eslint.org/docs/rules/no-div-regex
'no-div-regex': 'off',

// disallow else after a return in an if
// https://eslint.org/docs/rules/no-else-return
'no-else-return': ['error', { allowElseIf: false }],
Expand All @@ -109,10 +82,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-empty-pattern
'no-empty-pattern': 'error',

// disallow comparisons to null without a type-checking operator
// https://eslint.org/docs/rules/no-eq-null
'no-eq-null': 'off',

// disallow use of eval()
// https://eslint.org/docs/rules/no-eval
'no-eval': 'error',
Expand All @@ -133,42 +102,14 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-fallthrough
'no-fallthrough': 'error',

// disallow the use of leading or trailing decimal points in numeric literals
// https://eslint.org/docs/rules/no-floating-decimal
'no-floating-decimal': 'error',

// disallow reassignments of native objects or read-only globals
// https://eslint.org/docs/rules/no-global-assign
'no-global-assign': ['error', { exceptions: [] }],

// deprecated in favor of no-global-assign
// https://eslint.org/docs/rules/no-native-reassign
'no-native-reassign': 'off',

// disallow implicit type conversions
// https://eslint.org/docs/rules/no-implicit-coercion
'no-implicit-coercion': [
'off',
{
boolean: false,
number: true,
string: true,
allow: [],
},
],

// disallow var and named functions in global scope
// https://eslint.org/docs/rules/no-implicit-globals
'no-implicit-globals': 'off',

// disallow use of eval()-like methods
// https://eslint.org/docs/rules/no-implied-eval
'no-implied-eval': 'error',

// disallow this keywords outside of classes or class-like objects
// https://eslint.org/docs/rules/no-invalid-this
'no-invalid-this': 'off',

// disallow usage of __iterator__ property
// https://eslint.org/docs/rules/no-iterator
'no-iterator': 'error',
Expand All @@ -185,27 +126,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-loop-func
'no-loop-func': 'error',

// disallow magic numbers
// https://eslint.org/docs/rules/no-magic-numbers
'no-magic-numbers': [
'off',
{
ignore: [],
ignoreArrayIndexes: true,
enforceConst: true,
detectObjects: false,
},
],

// disallow use of multiple spaces
// https://eslint.org/docs/rules/no-multi-spaces
'no-multi-spaces': [
'error',
{
ignoreEOLComments: false,
},
],

// disallow use of multiline strings
// https://eslint.org/docs/rules/no-multi-str
'no-multi-str': 'error',
Expand Down Expand Up @@ -353,10 +273,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-throw-literal
'no-throw-literal': 'error',

// disallow unmodified conditions of loops
// https://eslint.org/docs/rules/no-unmodified-loop-condition
'no-unmodified-loop-condition': 'off',

// disallow usage of expressions in statement position
// https://eslint.org/docs/rules/no-unused-expressions
'no-unused-expressions': [
Expand All @@ -372,10 +288,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-unused-labels
'no-unused-labels': 'error',

// disallow unnecessary .call() and .apply()
// https://eslint.org/docs/rules/no-useless-call
'no-useless-call': 'off',

// Disallow unnecessary catch clauses
// https://eslint.org/docs/rules/no-useless-catch
'no-useless-catch': 'error',
Expand All @@ -396,13 +308,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/no-void
'no-void': 'error',

// disallow usage of configurable warning terms in comments: e.g. todo
// https://eslint.org/docs/rules/no-warning-comments
'no-warning-comments': [
'off',
{ terms: ['todo', 'fixme', 'xxx'], location: 'start' },
],

// disallow use of the with statement
// https://eslint.org/docs/rules/no-with
'no-with': 'error',
Expand All @@ -411,10 +316,6 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/prefer-promise-reject-errors
'prefer-promise-reject-errors': ['error', { allowEmptyReject: true }],

// Suggest using named capture group in regular expression
// https://eslint.org/docs/rules/prefer-named-capture-group
'prefer-named-capture-group': 'off',

// https://eslint.org/docs/rules/prefer-regex-literals
'prefer-regex-literals': [
'error',
Expand All @@ -427,25 +328,19 @@ const config: Linter.Config = {
// https://eslint.org/docs/rules/radix
radix: 'error',

// require `await` in `async function` (note: this is a horrible rule that should never be used)
// https://eslint.org/docs/rules/require-await
'require-await': 'off',

// Enforce the use of u flag on RegExp
// https://eslint.org/docs/rules/require-unicode-regexp
'require-unicode-regexp': 'off',

// requires to declare all vars on top of their containing scope
// https://eslint.org/docs/rules/vars-on-top
'vars-on-top': 'error',

// require immediate function invocation to be wrapped in parentheses
// https://eslint.org/docs/rules/wrap-iife.html
'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }],

// require or disallow Yoda conditions
// https://eslint.org/docs/rules/yoda
yoda: 'error',

// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md
'unicorn/prefer-node-protocol': 'error',

// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/text-encoding-identifier-case.md
'unicorn/text-encoding-identifier-case': 'error',
},
};

Expand Down
Loading

0 comments on commit 3b58e05

Please sign in to comment.