Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint: Add eslint-plugin-unicorn #5297

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima
dev,eslint-plugin-promise,ISC,jden and other contributors
dev,eslint-plugin-unicorn,MIT,Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson
dev,get-port,MIT,Copyright Sindre Sorhus
dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
Expand Down
105 changes: 92 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import stylistic from '@stylistic/eslint-plugin-js'
import mocha from 'eslint-plugin-mocha'
import n from 'eslint-plugin-n'
import eslintPluginJs from '@eslint/js'
import eslintPluginStylistic from '@stylistic/eslint-plugin-js'
import eslintPluginMocha from 'eslint-plugin-mocha'
import eslintPluginN from 'eslint-plugin-n'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import globals from 'globals'

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

plugins: {
n,
'@stylistic/js': stylistic
'@stylistic/js': eslintPluginStylistic,
n: eslintPluginN,
unicorn: eslintPluginUnicorn
},

languageOptions: {
Expand Down Expand Up @@ -88,11 +90,6 @@ export default [
'no-var': 'error' // Override (set to warn in standard)
}
},
{
name: 'mocha/recommnded',
...mocha.configs.flat.recommended,
files: TEST_FILES
},
{
name: 'dd-trace/src/all',
files: SRC_FILES,
Expand All @@ -106,9 +103,91 @@ export default [
name: 'semver',
message: 'Please use semifies instead.'
}
]]
]],

...eslintPluginUnicorn.configs.recommended.rules,

// Overriding recommended unicorn rules
'unicorn/catch-error-name': ['off', { name: 'err' }], // 166 errors
'unicorn/consistent-existence-index-check': 'off', // 4 errors
'unicorn/consistent-function-scoping': 'off', // 21 errors
'unicorn/empty-brace-spaces': 'off', // 15 errors
'unicorn/error-message': 'off', // 1 error
'unicorn/escape-case': 'off', // 8 errors
'unicorn/expiring-todo-comments': 'off',
'unicorn/explicit-length-check': 'off', // 68 errors
'unicorn/filename-case': ['off', { case: 'kebabCase' }], // 59 errors
'unicorn/import-style': 'off', // 9 errors - controversial
'unicorn/new-for-builtins': 'off', // 5 errors
'unicorn/no-abusive-eslint-disable': 'off', // 10 errors
'unicorn/no-anonymous-default-export': 'off', // only makes a difference for ESM
'unicorn/no-array-callback-reference': 'off', // too strict
'unicorn/no-array-for-each': 'off', // 122 errors
'unicorn/no-array-push-push': 'off', // 6 errors
'unicorn/no-array-reduce': 'off', // too strict
'unicorn/no-for-loop': 'off', // 15 errors
'unicorn/no-hex-escape': 'off', // too strict
'unicorn/no-instanceof-array': 'off', // 5 errors
'unicorn/no-instanceof-builtins': 'off', // 10 errors
'unicorn/no-lonely-if': 'off', // 19 errors
'unicorn/no-negated-condition': 'off', // too strict
'unicorn/no-nested-ternary': 'off', // too strict
'unicorn/no-new-array': 'off', // 6 errors
'unicorn/no-null': 'off', // too strict
'unicorn/no-object-as-default-parameter': 'off', // too strict
'unicorn/no-static-only-class': 'off', // 1 error
'unicorn/no-this-assignment': 'off', // too strict
'unicorn/no-typeof-undefined': 'off', // 1 error
'unicorn/no-unreadable-array-destructuring': 'off', // TODO: undecided
'unicorn/no-unreadable-iife': 'off', // too strict
'unicorn/no-useless-promise-resolve-reject': 'off', // 3 errors
'unicorn/no-useless-undefined': 'off', // 59 errors
'unicorn/no-zero-fractions': 'off', // 5 errors
'unicorn/number-literal-case': 'off', // 44 errors
'unicorn/numeric-separators-style': 'off', // 35 errors
'unicorn/prefer-array-flat-map': 'off', // 1 error
'unicorn/prefer-array-flat': 'off', // 9 errors
'unicorn/prefer-array-some': 'off', // 2 errors
'unicorn/prefer-at': 'off', // 47 errors
'unicorn/prefer-code-point': 'off', // 3 errors
'unicorn/prefer-default-parameters': 'off', // 1 error
'unicorn/prefer-event-target': 'off', // TODO: undecided (2 errors)
'unicorn/prefer-export-from': 'off', // 1 error
'unicorn/prefer-global-this': 'off', // 23 errors
'unicorn/prefer-includes': 'off', // 19 errors
'unicorn/prefer-logical-operator-over-ternary': 'off', // 15 errors
'unicorn/prefer-math-min-max': 'off', // 1 error
'unicorn/prefer-math-trunc': 'off', // 8 errors
'unicorn/prefer-module': 'off', // too strict
'unicorn/prefer-native-coercion-functions': 'off', // 18 errors
'unicorn/prefer-negative-index': 'off', // 1 error
'unicorn/prefer-node-protocol': 'off', // 148 errors
'unicorn/prefer-number-properties': 'off', // 56 errors
'unicorn/prefer-object-from-entries': 'off', // 3 errors
'unicorn/prefer-optional-catch-binding': 'off', // 62 errors
'unicorn/prefer-reflect-apply': 'off', // too strict
'unicorn/prefer-regexp-test': 'off', // 6 errors
'unicorn/prefer-set-has': 'off', // 18 errors
'unicorn/prefer-spread': 'off', // 36 errors
'unicorn/prefer-string-raw': 'off', // 22 errors
'unicorn/prefer-string-replace-all': 'off', // 33 errors
'unicorn/prefer-string-slice': 'off', // 53 errors
'unicorn/prefer-switch': 'off', // 8 errors
'unicorn/prefer-ternary': 'off', // 48 errors
'unicorn/prefer-top-level-await': 'off', // too strict
'unicorn/prefer-type-error': 'off', // 5 errors
'unicorn/prevent-abbreviations': 'off', // too strict
'unicorn/relative-url-style': 'off', // 1 error
'unicorn/switch-case-braces': 'off', // too strict
'unicorn/text-encoding-identifier-case': 'off', // 4 errors
'unicorn/throw-new-error': 'off' // 5 errors
}
},
{
name: 'mocha/recommended',
...eslintPluginMocha.configs.flat.recommended,
files: TEST_FILES
},
{
name: 'dd-trace/tests/all',
files: TEST_FILES,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-n": "^17.15.1",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-unicorn": "^57.0.0",
"express": "^4.21.2",
"get-port": "^3.2.0",
"glob": "^7.1.6",
Expand Down
Loading
Loading