Skip to content

Commit

Permalink
Adopt eslint-plugin-unicorn (#1812)
Browse files Browse the repository at this point in the history
Start using `eslint-plugin-unicorn` to enforce opinionated stylistic
consistency. All rules are explicitly configured to ensure the code
follows the standard of this project. Also expand the coverage of
this and other general-purpose plugins from the `src/` code to all
JavaScript code.

This commit includes changes in compliance with these lint
changes.

Most rules are enabled as is. Some rules are disabled for various
reasons:
- `consistent-destructuring`: too situational to lint for in my opinion.
  Open to reconsider later.
- `import-style`: limited value while hard to configure. Default config
  not desired.
- `no-nested-ternary`: conflicts with Prettier.
- `no-null`: seems fine though I'm intrigued by the explanation given
  by the plugin. Open to reconsider later.
- `number-literal-case`: conflicts with Prettier.
- `prefer-spread`: imperfect rule that conflicts with this code base.
  Open to reconsider later.
- `prefer-string-raw`: I'm okay with escaping and am concerned about
  performance impacts of using `String.raw`.
- `prefer-ternary`: too situational to lint for in my opinion. Open to
  reconsider later.
- `prevent-abbreviations`: mainly don't have a solution for the "args"
  abbreviation. Open to reconsider later.

Lastly, the `unicorn/prefer-string-replace-all` rule is not in use
because it is not compatible with Node.js v14.18.0, which is still
supported by this package.
  • Loading branch information
ericcornelissen authored Dec 15, 2024
1 parent bcef0b5 commit 6098fc5
Show file tree
Hide file tree
Showing 54 changed files with 836 additions and 288 deletions.
188 changes: 166 additions & 22 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import jsdoc from "eslint-plugin-jsdoc";
import json from "@eslint/json";
import regexp from "eslint-plugin-regexp";
import top from "@ericcornelissen/eslint-plugin-top";
import unicorn from "eslint-plugin-unicorn";
import yml from "eslint-plugin-yml";

export default [
Expand All @@ -17,6 +18,15 @@ export default [
sourceType: "module",
},
},
{
name: "Dependencies",
files: ["**/*.js"],
plugins: { depend },
rules: {
// https://github.com/es-tooling/eslint-plugin-depend#readme
"depend/ban-dependencies": ["error"],
},
},
{
name: "JSDoc",
files: ["**/*.js"],
Expand Down Expand Up @@ -323,21 +333,10 @@ export default [
},
},
{
name: "Source",
files: ["src/**/*.js"],
plugins: { depend, jsdoc, regexp, top },
name: "Regular Expressions",
files: ["**/*.js"],
plugins: { regexp },
rules: {
// https://github.com/es-tooling/eslint-plugin-depend#readme
"depend/ban-dependencies": ["error"],

// https://github.com/gajus/eslint-plugin-jsdoc#readme
"jsdoc/check-values": [
"error",
{
allowedLicenses: ["MPL-2.0"],
},
],

// https://github.com/ota-meshi/eslint-plugin-regexp#readme
"regexp/confusing-quantifier": ["error"],
"regexp/control-character-escape": ["error"],
Expand Down Expand Up @@ -530,6 +529,151 @@ export default [
},
],
"regexp/use-ignore-case": ["error"],
},
},
{
name: "Style",
files: ["**/*.js"],
plugins: { unicorn },
rules: {
// https://github.com/sindresorhus/eslint-plugin-unicorn#readme
"unicorn/better-regex": ["error"],
"unicorn/catch-error-name": ["error"],
"unicorn/consistent-destructuring": ["off"],
"unicorn/consistent-empty-array-spread": ["error"],
"unicorn/consistent-existence-index-check": ["error"],
"unicorn/consistent-function-scoping": ["error"],
"unicorn/custom-error-definition": ["error"],
"unicorn/empty-brace-spaces": ["error"],
"unicorn/error-message": ["error"],
"unicorn/escape-case": ["error"],
"unicorn/expiring-todo-comments": ["error"],
"unicorn/explicit-length-check": ["error"],
"unicorn/filename-case": ["error"],
"unicorn/import-style": ["off"],
"unicorn/new-for-builtins": ["error"],
"unicorn/no-abusive-eslint-disable": ["error"],
"unicorn/no-anonymous-default-export": ["error"],
"unicorn/no-array-callback-reference": ["error"],
"unicorn/no-array-for-each": ["error"],
"unicorn/no-array-method-this-argument": ["error"],
"unicorn/no-array-push-push": ["error"],
"unicorn/no-array-reduce": ["error"],
"unicorn/no-await-expression-member": ["error"],
"unicorn/no-await-in-promise-methods": ["error"],
"unicorn/no-console-spaces": ["error"],
"unicorn/no-document-cookie": ["error"],
"unicorn/no-empty-file": ["error"],
"unicorn/no-for-loop": ["error"],
"unicorn/no-hex-escape": ["error"],
"unicorn/no-instanceof-array": ["error"],
"unicorn/no-invalid-fetch-options": ["error"],
"unicorn/no-invalid-remove-event-listener": ["error"],
"unicorn/no-keyword-prefix": ["error"],
"unicorn/no-length-as-slice-end": ["error"],
"unicorn/no-lonely-if": ["error"],
"unicorn/no-magic-array-flat-depth": ["error"],
"unicorn/no-negated-condition": ["error"],
"unicorn/no-negation-in-equality-check": ["error"],
"unicorn/no-nested-ternary": ["off"],
"unicorn/no-new-array": ["error"],
"unicorn/no-new-buffer": ["error"],
"unicorn/no-null": ["off"],
"unicorn/no-object-as-default-parameter": ["error"],
"unicorn/no-process-exit": ["error"],
"unicorn/no-single-promise-in-promise-methods": ["error"],
"unicorn/no-static-only-class": ["error"],
"unicorn/no-thenable": ["error"],
"unicorn/no-this-assignment": ["error"],
"unicorn/no-typeof-undefined": ["error"],
"unicorn/no-unnecessary-await": ["error"],
"unicorn/no-unnecessary-polyfills": ["error"],
"unicorn/no-unreadable-array-destructuring": ["error"],
"unicorn/no-unreadable-iife": ["error"],
"unicorn/no-unused-properties": ["error"],
"unicorn/no-useless-fallback-in-spread": ["error"],
"unicorn/no-useless-length-check": ["error"],
"unicorn/no-useless-promise-resolve-reject": ["error"],
"unicorn/no-useless-spread": ["error"],
"unicorn/no-useless-switch-case": ["error"],
"unicorn/no-useless-undefined": ["error"],
"unicorn/no-zero-fractions": ["error"],
"unicorn/number-literal-case": ["off"],
"unicorn/numeric-separators-style": ["error"],
"unicorn/prefer-add-event-listener": ["error"],
"unicorn/prefer-array-find": ["error"],
"unicorn/prefer-array-flat-map": ["error"],
"unicorn/prefer-array-flat": ["error"],
"unicorn/prefer-array-index-of": ["error"],
"unicorn/prefer-array-some": ["error"],
"unicorn/prefer-at": ["error"],
"unicorn/prefer-blob-reading-methods": ["error"],
"unicorn/prefer-code-point": ["error"],
"unicorn/prefer-date-now": ["error"],
"unicorn/prefer-default-parameters": ["error"],
"unicorn/prefer-dom-node-append": ["error"],
"unicorn/prefer-dom-node-dataset": ["error"],
"unicorn/prefer-dom-node-remove": ["error"],
"unicorn/prefer-dom-node-text-content": ["error"],
"unicorn/prefer-event-target": ["error"],
"unicorn/prefer-export-from": ["error"],
"unicorn/prefer-global-this": ["error"],
"unicorn/prefer-includes": ["error"],
"unicorn/prefer-json-parse-buffer": ["error"],
"unicorn/prefer-keyboard-event-key": ["error"],
"unicorn/prefer-logical-operator-over-ternary": ["error"],
"unicorn/prefer-math-min-max": ["error"],
"unicorn/prefer-math-trunc": ["error"],
"unicorn/prefer-modern-dom-apis": ["error"],
"unicorn/prefer-modern-math-apis": ["error"],
"unicorn/prefer-module": ["error"],
"unicorn/prefer-native-coercion-functions": ["error"],
"unicorn/prefer-negative-index": ["error"],
"unicorn/prefer-node-protocol": ["error"],
"unicorn/prefer-number-properties": ["error"],
"unicorn/prefer-object-from-entries": ["error"],
"unicorn/prefer-optional-catch-binding": ["error"],
"unicorn/prefer-prototype-methods": ["error"],
"unicorn/prefer-query-selector": ["error"],
"unicorn/prefer-reflect-apply": ["error"],
"unicorn/prefer-regexp-test": ["error"],
"unicorn/prefer-set-has": ["error"],
"unicorn/prefer-set-size": ["error"],
"unicorn/prefer-spread": ["off"],
"unicorn/prefer-string-raw": ["off"],
"unicorn/prefer-string-replace-all": ["off"],
"unicorn/prefer-string-slice": ["error"],
"unicorn/prefer-string-starts-ends-with": ["error"],
"unicorn/prefer-string-trim-start-end": ["error"],
"unicorn/prefer-structured-clone": ["error"],
"unicorn/prefer-switch": ["error"],
"unicorn/prefer-ternary": ["off"],
"unicorn/prefer-top-level-await": ["error"],
"unicorn/prefer-type-error": ["error"],
"unicorn/prevent-abbreviations": ["off"],
"unicorn/relative-url-style": ["error"],
"unicorn/require-array-join-separator": ["error"],
"unicorn/require-number-to-fixed-digits-argument": ["error"],
"unicorn/require-post-message-target-origin": ["error"],
"unicorn/string-content": ["error"],
"unicorn/switch-case-braces": ["error"],
"unicorn/template-indent": ["error"],
"unicorn/text-encoding-identifier-case": ["error"],
"unicorn/throw-new-error": ["error"],
},
},
{
name: "Source",
files: ["src/**/*.js"],
plugins: { jsdoc, top },
rules: {
// https://github.com/gajus/eslint-plugin-jsdoc#readme
"jsdoc/check-values": [
"error",
{
allowedLicenses: ["MPL-2.0"],
},
],

// https://github.com/ericcornelissen/eslint-plugin-top#readme
"top/no-top-level-side-effects": [
Expand All @@ -553,11 +697,8 @@ export default [
{
name: "Tests",
files: ["test/**/*.js"],
plugins: { ava, depend, jsdoc },
plugins: { ava, jsdoc },
rules: {
// https://github.com/es-tooling/eslint-plugin-depend#readme
"depend/ban-dependencies": ["error"],

// https://github.com/gajus/eslint-plugin-jsdoc#readme
"jsdoc/check-values": [
"error",
Expand Down Expand Up @@ -600,16 +741,16 @@ export default [
"ava/use-t-well": ["error"],
"ava/use-test": ["error"],
"ava/use-true-false": ["error"],

// https://github.com/sindresorhus/eslint-plugin-unicorn#readme
"unicorn/no-useless-undefined": ["off"],
},
},
{
name: "Scripts",
files: [".github/**/*.js", "script/**/*.js"],
plugins: { depend, jsdoc },
plugins: { jsdoc, unicorn },
rules: {
// https://github.com/es-tooling/eslint-plugin-depend#readme
"depend/ban-dependencies": ["error"],

// https://github.com/gajus/eslint-plugin-jsdoc#readme
"jsdoc/check-values": [
"error",
Expand All @@ -618,6 +759,9 @@ export default [
},
],
"jsdoc/require-jsdoc": ["off"],

// https://github.com/sindresorhus/eslint-plugin-unicorn#readme
"unicorn/no-process-exit": ["off"],
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion config/stryker/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
},
incremental: true,
incrementalFile: ".cache/stryker-incremental-integration.json",
timeoutMS: 10000,
timeoutMS: 10_000,
reporters: ["clear-text", "html", "progress"],
htmlReporter: {
fileName: "_reports/mutation/integration.html",
Expand Down
2 changes: 1 addition & 1 deletion config/stryker/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
},
incremental: true,
incrementalFile: ".cache/stryker-incremental-unit.json",
timeoutMS: 10000,
timeoutMS: 10_000,
reporters: ["clear-text", "html", "progress"],
htmlReporter: {
fileName: "_reports/mutation/unit.html",
Expand Down
Loading

0 comments on commit 6098fc5

Please sign in to comment.