Skip to content

Commit 8e6c297

Browse files
authored
ESLint: Add eslint-plugin-unicorn (#5297)
* ESLint: Add eslint-plugin-unicorn * ESLint: Clean up config * Enable recommended unicorn rules that doesn't error
1 parent 696cf86 commit 8e6c297

File tree

4 files changed

+350
-63
lines changed

4 files changed

+350
-63
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
5454
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
5555
dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima
5656
dev,eslint-plugin-promise,ISC,jden and other contributors
57+
dev,eslint-plugin-unicorn,MIT,Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
5758
dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson
5859
dev,get-port,MIT,Copyright Sindre Sorhus
5960
dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors

eslint.config.mjs

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import path from 'node:path'
22
import { fileURLToPath } from 'node:url'
33

44
import { FlatCompat } from '@eslint/eslintrc'
5-
import js from '@eslint/js'
6-
import stylistic from '@stylistic/eslint-plugin-js'
7-
import mocha from 'eslint-plugin-mocha'
8-
import n from 'eslint-plugin-n'
5+
import eslintPluginJs from '@eslint/js'
6+
import eslintPluginStylistic from '@stylistic/eslint-plugin-js'
7+
import eslintPluginMocha from 'eslint-plugin-mocha'
8+
import eslintPluginN from 'eslint-plugin-n'
9+
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
910
import globals from 'globals'
1011

1112
const __filename = fileURLToPath(import.meta.url)
@@ -48,14 +49,15 @@ export default [
4849
'packages/dd-trace/src/payload-tagging/jsonpath-plus.js' // Vendored
4950
]
5051
},
51-
{ name: '@eslint/js/recommnded', ...js.configs.recommended },
52+
{ name: '@eslint/js/recommnded', ...eslintPluginJs.configs.recommended },
5253
...compat.extends('standard').map((config, i) => ({ name: config.name || `standard/${i + 1}`, ...config })),
5354
{
5455
name: 'dd-trace/defaults',
5556

5657
plugins: {
57-
n,
58-
'@stylistic/js': stylistic
58+
'@stylistic/js': eslintPluginStylistic,
59+
n: eslintPluginN,
60+
unicorn: eslintPluginUnicorn
5961
},
6062

6163
languageOptions: {
@@ -88,11 +90,6 @@ export default [
8890
'no-var': 'error' // Override (set to warn in standard)
8991
}
9092
},
91-
{
92-
name: 'mocha/recommnded',
93-
...mocha.configs.flat.recommended,
94-
files: TEST_FILES
95-
},
9693
{
9794
name: 'dd-trace/src/all',
9895
files: SRC_FILES,
@@ -106,9 +103,91 @@ export default [
106103
name: 'semver',
107104
message: 'Please use semifies instead.'
108105
}
109-
]]
106+
]],
107+
108+
...eslintPluginUnicorn.configs.recommended.rules,
109+
110+
// Overriding recommended unicorn rules
111+
'unicorn/catch-error-name': ['off', { name: 'err' }], // 166 errors
112+
'unicorn/consistent-existence-index-check': 'off', // 4 errors
113+
'unicorn/consistent-function-scoping': 'off', // 21 errors
114+
'unicorn/empty-brace-spaces': 'off', // 15 errors
115+
'unicorn/error-message': 'off', // 1 error
116+
'unicorn/escape-case': 'off', // 8 errors
117+
'unicorn/expiring-todo-comments': 'off',
118+
'unicorn/explicit-length-check': 'off', // 68 errors
119+
'unicorn/filename-case': ['off', { case: 'kebabCase' }], // 59 errors
120+
'unicorn/import-style': 'off', // 9 errors - controversial
121+
'unicorn/new-for-builtins': 'off', // 5 errors
122+
'unicorn/no-abusive-eslint-disable': 'off', // 10 errors
123+
'unicorn/no-anonymous-default-export': 'off', // only makes a difference for ESM
124+
'unicorn/no-array-callback-reference': 'off', // too strict
125+
'unicorn/no-array-for-each': 'off', // 122 errors
126+
'unicorn/no-array-push-push': 'off', // 6 errors
127+
'unicorn/no-array-reduce': 'off', // too strict
128+
'unicorn/no-for-loop': 'off', // 15 errors
129+
'unicorn/no-hex-escape': 'off', // too strict
130+
'unicorn/no-instanceof-array': 'off', // 5 errors
131+
'unicorn/no-instanceof-builtins': 'off', // 10 errors
132+
'unicorn/no-lonely-if': 'off', // 19 errors
133+
'unicorn/no-negated-condition': 'off', // too strict
134+
'unicorn/no-nested-ternary': 'off', // too strict
135+
'unicorn/no-new-array': 'off', // 6 errors
136+
'unicorn/no-null': 'off', // too strict
137+
'unicorn/no-object-as-default-parameter': 'off', // too strict
138+
'unicorn/no-static-only-class': 'off', // 1 error
139+
'unicorn/no-this-assignment': 'off', // too strict
140+
'unicorn/no-typeof-undefined': 'off', // 1 error
141+
'unicorn/no-unreadable-array-destructuring': 'off', // TODO: undecided
142+
'unicorn/no-unreadable-iife': 'off', // too strict
143+
'unicorn/no-useless-promise-resolve-reject': 'off', // 3 errors
144+
'unicorn/no-useless-undefined': 'off', // 59 errors
145+
'unicorn/no-zero-fractions': 'off', // 5 errors
146+
'unicorn/number-literal-case': 'off', // 44 errors
147+
'unicorn/numeric-separators-style': 'off', // 35 errors
148+
'unicorn/prefer-array-flat-map': 'off', // 1 error
149+
'unicorn/prefer-array-flat': 'off', // 9 errors
150+
'unicorn/prefer-array-some': 'off', // 2 errors
151+
'unicorn/prefer-at': 'off', // 47 errors
152+
'unicorn/prefer-code-point': 'off', // 3 errors
153+
'unicorn/prefer-default-parameters': 'off', // 1 error
154+
'unicorn/prefer-event-target': 'off', // TODO: undecided (2 errors)
155+
'unicorn/prefer-export-from': 'off', // 1 error
156+
'unicorn/prefer-global-this': 'off', // 23 errors
157+
'unicorn/prefer-includes': 'off', // 19 errors
158+
'unicorn/prefer-logical-operator-over-ternary': 'off', // 15 errors
159+
'unicorn/prefer-math-min-max': 'off', // 1 error
160+
'unicorn/prefer-math-trunc': 'off', // 8 errors
161+
'unicorn/prefer-module': 'off', // too strict
162+
'unicorn/prefer-native-coercion-functions': 'off', // 18 errors
163+
'unicorn/prefer-negative-index': 'off', // 1 error
164+
'unicorn/prefer-node-protocol': 'off', // 148 errors
165+
'unicorn/prefer-number-properties': 'off', // 56 errors
166+
'unicorn/prefer-object-from-entries': 'off', // 3 errors
167+
'unicorn/prefer-optional-catch-binding': 'off', // 62 errors
168+
'unicorn/prefer-reflect-apply': 'off', // too strict
169+
'unicorn/prefer-regexp-test': 'off', // 6 errors
170+
'unicorn/prefer-set-has': 'off', // 18 errors
171+
'unicorn/prefer-spread': 'off', // 36 errors
172+
'unicorn/prefer-string-raw': 'off', // 22 errors
173+
'unicorn/prefer-string-replace-all': 'off', // 33 errors
174+
'unicorn/prefer-string-slice': 'off', // 53 errors
175+
'unicorn/prefer-switch': 'off', // 8 errors
176+
'unicorn/prefer-ternary': 'off', // 48 errors
177+
'unicorn/prefer-top-level-await': 'off', // too strict
178+
'unicorn/prefer-type-error': 'off', // 5 errors
179+
'unicorn/prevent-abbreviations': 'off', // too strict
180+
'unicorn/relative-url-style': 'off', // 1 error
181+
'unicorn/switch-case-braces': 'off', // too strict
182+
'unicorn/text-encoding-identifier-case': 'off', // 4 errors
183+
'unicorn/throw-new-error': 'off' // 5 errors
110184
}
111185
},
186+
{
187+
name: 'mocha/recommended',
188+
...eslintPluginMocha.configs.flat.recommended,
189+
files: TEST_FILES
190+
},
112191
{
113192
name: 'dd-trace/tests/all',
114193
files: TEST_FILES,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
"eslint-plugin-mocha": "^10.5.0",
140140
"eslint-plugin-n": "^17.15.1",
141141
"eslint-plugin-promise": "^7.2.1",
142+
"eslint-plugin-unicorn": "^57.0.0",
142143
"express": "^4.21.2",
143144
"get-port": "^3.2.0",
144145
"glob": "^7.1.6",

0 commit comments

Comments
 (0)