This commit is contained in:
gcch 2026-04-03 23:57:57 +02:00
commit 0968f683df
24 changed files with 2762 additions and 2447 deletions

View file

@ -1,121 +1,774 @@
import type { DummyRuleMap } from "oxlint";
const unicornRules: DummyRuleMap = {
"unicorn/catch-error-name": "error",
"unicorn/consistent-date-clone": "error",
"unicorn/consistent-empty-array-spread": "error",
"unicorn/consistent-existence-index-check": "error",
"unicorn/custom-error-definition": "error",
"unicorn/error-message": "error",
"unicorn/escape-case": "error",
/**
* This rule enforces consistent and descriptive naming for error variables in `catch` statements, preventing the use
* of vague names like `badName` or _ when the error is used.
*
* Using non-descriptive names like `badName` or _ makes the code harder to read and understand, especially when
* debugging. It's important to use clear, consistent names to represent errors.
*/
"unicorn/catch-error-name": [
"deny",
{
ignore: ["_"],
},
],
/** Enforces consistent usage of the `assert` module. */
"unicorn/consistent-assert": "deny",
/**
* The `Date` constructor can clone a `Date` object directly when passed as an argument, making timestamp conversion
* unnecessary. This rule enforces the use of the direct `Date` cloning instead of using `.getTime()` for conversion.
*
* Using `.getTime()` to convert a `Date` object to a timestamp and then back to a `Date` is redundant and
* unnecessary. Simply passing the `Date` object to the `Date` constructor is cleaner and more efficient.
*/
"unicorn/consistent-date-clone": "deny",
/**
* When spreading a ternary in an array, we can use both `[]` and `''` as fallbacks, but it's better to have
* consistent types in both branches.
*/
"unicorn/consistent-empty-array-spread": "deny",
/**
* Enforce consistent style for element existence checks with `indexOf()`, `lastIndexOf()`, `findIndex()`, and
* `findLastIndex()`. This ensures that comparisons are performed in a standard and clear way.
*
* This rule is meant to enforce a specific style and improve code clarity. Using inconsistent comparison styles
* (e.g., `index < 0`, `index >= 0`) can make the intention behind the code unclear, especially in large codebases.
*/
"unicorn/consistent-existence-index-check": "deny",
/**
* Disallow functions that are declared in a scope which does not capture any variables from the outer scope.
*
* Moving function declarations to the highest possible scope improves readability, directly improves performance and allows JavaScript engines to better optimize your performance.
*/
"unicorn/consistent-function-scoping": [
"deny",
{
/** Whether to check scoping with arrow functions. */
checkArrowFunctions: true,
},
],
/**
* Enforces the only valid way of `Error` subclassing. It works with any super class that ends in `Error`.
*
* Incorrectly defined custom errors can lead to unexpected behavior when catching and identifying errors. Missing
* `super()` calls, wrong `name` property values, or non-standard class names make error handling unreliable.
*/
"unicorn/custom-error-definition": "deny",
/**
* Removes the extra spaces or new line characters inside a pair of braces that does not contain additional code. This
* ensures that braces are clean and do not contain unnecessary spaces or newlines.
*
* Extra spaces inside braces can negatively impact the readability of the code. Keeping braces clean and free of
* unnecessary characters improves consistency and makes the code easier to understand and maintain.
*/
"unicorn/empty-brace-spaces": "deny",
/**
* Enforces providing a `message` when creating built-in `Error` objects to improve readability and debugging.
*
* Throwing an `Error` without a message, like throw new `Error()`, provides no context on what went wrong, making
* debugging harder. A clear error message improves code clarity and helps developers quickly identify issues.
*/
"unicorn/error-message": "deny",
/**
* Enforces defining escape sequence values with uppercase characters rather than lowercase ones. This promotes
* readability by making the escaped value more distinguishable from the identifier.
*/
"unicorn/escape-case": "deny",
/** Enforce explicitly comparing the `length` or `size` property of a value. */
"unicorn/explicit-length-check": [
"error",
"deny",
{
"non-zero": "not-equal",
},
],
"unicorn/new-for-builtins": "error",
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-accessor-recursion": "error",
"unicorn/no-anonymous-default-export": "error",
"unicorn/no-array-method-this-argument": "error",
"unicorn/no-array-reverse": "error",
"unicorn/no-array-sort": "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-hex-escape": "error",
"unicorn/no-instanceof-builtins": "error",
"unicorn/no-invalid-fetch-options": "error",
"unicorn/no-invalid-remove-event-listener": "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": "error",
"unicorn/no-new-array": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-null": "error",
"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-array-flat-depth": "error",
"unicorn/no-unnecessary-array-splice-count": "error",
"unicorn/no-unnecessary-await": "error",
"unicorn/no-unnecessary-slice-end": "error",
"unicorn/no-unreadable-array-destructuring": "error",
"unicorn/no-unreadable-iife": "error",
"unicorn/no-useless-collection-argument": "error",
"unicorn/no-useless-error-capture-stack-trace": "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": "error",
"unicorn/numeric-separators-style": "error",
"unicorn/prefer-add-event-listener": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-bigint-literals": "error",
"unicorn/prefer-blob-reading-methods": "error",
"unicorn/prefer-class-fields": "error",
"unicorn/prefer-classlist-toggle": "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-remove": "error",
"unicorn/prefer-dom-node-text-content": "error",
"unicorn/prefer-event-target": "error",
"unicorn/prefer-global-this": "error",
"unicorn/prefer-includes": "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-reflect-apply": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-response-static-json": "error",
"unicorn/prefer-set-has": "error",
"unicorn/prefer-set-size": "error",
"unicorn/prefer-string-raw": "error",
"unicorn/prefer-string-replace-all": "error",
"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-ternary": "off",
"unicorn/prefer-top-level-await": "error",
"unicorn/prefer-type-error": "error",
"unicorn/relative-url-style": "error",
"unicorn/require-array-join-separator": "error",
"unicorn/require-module-attributes": "error",
"unicorn/require-module-specifiers": "error",
"unicorn/require-number-to-fixed-digits-argument": "error",
"unicorn/text-encoding-identifier-case": "error",
"unicorn/throw-new-error": "error",
/**
* Enforces a consistent case style for filenames to improve project organization and maintainability. By default,
* `kebab-case` is enforced, but other styles can be configured.
*
* Files named `index.js`, `index.ts`, etc. are exempt from this rule as they cannot reliably be renamed to other
* casings (mainly just a problem with PascalCase).
*
* Inconsistent file naming conventions make it harder to locate files, navigate projects, and enforce consistency
* across a codebase. Standardizing naming conventions improves readability, reduces cognitive overhead, and aligns
* with best practices in large-scale development.
*/
"unicorn/filename-case": [
"deny",
{
case: "kebabCase",
ignore: "",
multipleFileExtensions: true,
},
],
/** Enforces the use of `new` for many builtins and disallow it for some other. */
"unicorn/new-for-builtins": "deny",
/** Disallows `oxlint-disable` or `eslint-disable` comments without specifying rules. */
"unicorn/no-abusive-eslint-disable": "deny",
/**
* Disallow recursive access to `this` within getters and setters.
*
* This rule prevents recursive access to `this` within getter and setter methods in objects and classes, avoiding infinite recursion and stack overflow errors.
*/
"unicorn/no-accessor-recursion": "deny",
/** Disallows anonymous functions and classes as default exports. */
"unicorn/no-anonymous-default-export": "deny",
/**
* Prevents passing a function reference directly to iterator methods.
*
* Passing functions to iterator methods can cause issues when the function is changed without realizing that the
* iterator passes 2 more parameters to it (index and array). This can lead to unexpected behavior when the function
* signature changes.
*
* Cause des soucis avec les pipelines `Effect`.
*/
"unicorn/no-array-callback-reference": "allow",
/**
* Forbids the use of Array#forEach in favor of a for loop.
*
* Je préfère utiliser les méthodes `.forEach` dans les pipelines.
*/
"unicorn/no-array-for-each": "allow",
/**
* Disallows the use of the `thisArg` parameter in array iteration methods such as `map`, `filter`, `some`, `every`,
* and similar.
*
* The `thisArg` parameter makes code harder to understand and reason about. Instead, prefer arrow functions or bind
* explicitly in a clearer way. Arrow functions inherit `this` from the lexical scope, which is more intuitive and
* less error-prone.
*
* Cause des soucis avec les pipelines `Effect`.
*/
"unicorn/no-array-method-this-argument": "allow",
/**
* Disallow `Array#reduce()` and `Array#reduceRight()`.
*
* `reduce()` est utile dans certains cas.
*/
"unicorn/no-array-reduce": "allow",
/**
* Prefer using `Array#toReversed()` over `Array#reverse()`.
*
* `Array#reverse()` modifies the original array in place, which can lead to unintended side effectsespecially when the original array is used elsewhere in the code.
*/
"unicorn/no-array-reverse": [
"deny",
{
/** This rule allows `array.reverse()` as an expression statement by default. Set to `false` to forbid `Array#reverse()` even if it's an expression statement. */
allowExpressionStatement: false,
},
],
/**
* Prefer using `Array#toSorted()` over `Array#sort()`.
*
* `Array#sort()` modifies the original array in place, which can lead to unintended side effectsespecially when the original array is used elsewhere in the code.
*/
"unicorn/no-array-sort": [
"deny",
{
/** When set to `true` (default), allows `array.sort()` as an expression statement. Set to `false` to forbid `Array#sort()` even if it's an expression statement. */
allowExpressionStatement: false,
},
],
/**
* Disallows member access from `await` expressions.
*
* When accessing a member from an `await` expression, the `await` expression has to be parenthesized, which is not
* readable.
*/
"unicorn/no-await-expression-member": "deny",
/** Disallow using await in Promise method parameters. */
"unicorn/no-await-in-promise-methods": "deny",
/**
* Disallows leading/trailing space inside `console.log()` and similar methods.
*
* The `console.log()` method and similar methods join the parameters with a space so adding a leading/trailing space
* to a parameter, results in two spaces being added.
*/
"unicorn/no-console-spaces": "deny",
/** Disallows direct use of [`document.cookie`](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie). */
"unicorn/no-document-cookie": "deny",
/** Disallows files that do not contain any meaningful code. */
/** Disallows files that do not contain any meaningful code. */
"unicorn/no-empty-file": "deny",
/** Enforces a convention of using Unicode escapes instead of hexadecimal escapes for consistency and clarity. */
"unicorn/no-hex-escape": "deny",
/** Disallows mutating a variable immediately after initialization. */
"unicorn/no-immediate-mutation": "deny",
/** Require `Array.isArray()` instead of `instanceof Array`. */
"unicorn/no-instanceof-array": "deny",
/**
* Disallows the use of `instanceof` with ECMAScript built-in constructors because:
*
* - it breaks across execution contexts (`iframe`, Web Worker, Node VM, etc.);
* - it is often misleading (e.g. `instanceof Array` fails for a subclass);
* - there is always a clearer and safer alternative `(Array.isArray`, `typeof`, `Buffer.isBuffer`, ).
*
* `instanceof` breaks across execution contexts (`iframe`, Web Worker, Node `vm`), and may give misleading results for subclasses or exotic objects.
*/
"unicorn/no-instanceof-builtins": [
"deny",
{
/** Constructor names to exclude from checking. */
exlude: [],
/** Additional constructor names to check beyond the default set. Use this to extend the rule with additional constructors. */
include: [],
/**
* Controls which built-in constructors are checked.
*
* - `"loose"` (default): Only checks `Array`, `Function`, `Error` (if `useErrorIsError` is `true`), and primitive wrappers;
* - `"strict"`: Additionally checks `Error` types, collections, typed arrays, and other built-in constructors.
*/
strategy: "strict",
/**
* When `true`, checks `instanceof Error` and suggests using `Error.isError()` instead. Requires the `Error.isError()` function to be available.
*/
useErrorIsError: true,
},
],
/**
* Disallow invalid options in `fetch()` and new `Request().` Specifically, this rule ensures that a body is not
* provided when the method is `GET` or `HEAD,` as it will result in a `TypeError.`
*/
"unicorn/no-invalid-fetch-options": "deny",
/** It warns when you use a non-function value as the second argument of `removeEventListener`. */
"unicorn/no-invalid-remove-event-listener": "deny",
/** Disallow using `length` as the end argument of a `slice` call. */
"unicorn/no-length-as-slice-end": "deny",
/** Disallow `if` statements as the only statement in `if` blocks without `else`. */
"unicorn/no-lonely-if": "deny",
/**
* Disallow magic numbers for
* [`Array.prototype.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
* depth.
*
* Magic numbers are hard to understand and maintain. When calling `Array.prototype.flat`, it is usually called with
* `1`, or `Infinity`. If you are using a different number, it is better to add a comment explaining the reason for
* the depth provided.
*/
"unicorn/no-magic-array-flat-depth": "deny",
"unicorn/no-negated-condition": "deny",
/** Disallow negated expressions on the left of (in)equality checks. */
"unicorn/no-negation-in-equality-check": "deny",
/**
* This rule disallows deeply nested ternary expressions. Nested ternary expressions that are only one level deep and
* wrapped in parentheses are allowed.
*
* Nesting ternary expressions can make code more difficult to understand.
*/
"unicorn/no-nested-ternary": "deny",
/** Disallow new `Array()`. */
"unicorn/no-new-array": "deny",
/** Disallows the deprecated new `Buffer()` constructor. */
"unicorn/no-new-buffer": "deny",
/**
* Disallow the use of the `null` literal, to encourage using undefined instead.
*
* There are some reasons for using `undefined` instead of `null`.
*
* - From experience, most developers use `null` and `undefined` inconsistently and interchangeably, and few know when
* to use which.
* - Supporting both `null` and `undefined` complicates input validation.
* - Using `null` makes TypeScript types more verbose: `type A = {foo?: string | null} vs type A = {foo?: string}`.
*/
"unicorn/no-null": [
"deny",
{
checkStrictEquality: true,
},
],
/** Disallow the use of an object literal as a default value for a parameter. */
"unicorn/no-object-as-default-parameter": "deny",
/**
* Disallow all usage of `process.exit()`.
*
* `process.exit()` should generally only be used in command-line utilities. In all other types of applications, the
* code should throw an error instead.
*/
"unicorn/no-process-exit": "deny",
/** Disallow passing single-element arrays to `Promise` methods. */
"unicorn/no-single-promise-in-promise-methods": "deny",
/** Disallow `class` declarations that exclusively contain `static` members. */
"unicorn/no-static-only-class": "deny",
/** Disallow defining a `then` property. */
"unicorn/no-thenable": "deny",
/** Disallow assigning `this` to a variable. */
"unicorn/no-this-assignment": "deny",
/** Disallow `typeof` comparisons with `undefined`. */
"unicorn/no-typeof-undefined": "deny",
/** Disallows passing `1` to `Array.prototype.flat`. */
"unicorn/no-unnecessary-array-flat-depth": "deny",
/**
* Disallows passing `.length` or `Infinity` as the `deleteCount` or `skipCount` argument of `Array#splice()` or
* `Array#toSpliced()`.
*/
"unicorn/no-unnecessary-array-splice-count": "deny",
/** Disallow awaiting on non-`Promise` values. */
"unicorn/no-unnecessary-await": "deny",
/** Disallows unnecessarily passing a second argument to `slice(...)`, for cases where it would not change the result. */
"unicorn/no-unnecessary-slice-end": "deny",
/**
* Disallows destructuring values from an array in ways that are difficult to read.
*
* Destructuring can be very useful, but it can also make some code harder to read. This rule prevents ignoring
* consecutive values (e.g. `let [,,foo] = array`) when destructuring from an array.
*/
"unicorn/no-unreadable-array-destructuring": "deny",
/** This rule disallows IIFEs with a parenthesized arrow function body. */
"unicorn/no-unreadable-iife": "deny",
/**
* Disallow useless values or fallbacks in `Set`, `Map`, `WeakSet`, or `WeakMap`.
*
* It is unnecessary to pass an empty array or empty string when constructing a `Set`, `Map`, `WeakSet`, or `WeakMap`,
* since they accept nullish values.
*
* It is also unnecessary to provide a fallback for possible nullish values.
*/
"unicorn/no-useless-collection-argument": "deny",
/**
* Disallows unnecessary `Error.captureStackTrace(…)` in error constructors.
*
* Calling `Error.captureStackTrace(…)` inside the constructor of a built-in `Error` subclass is unnecessary, since
* the `Error` constructor calls it automatically.
*/
"unicorn/no-useless-error-capture-stack-trace": "deny",
/** Disallow useless fallback when spreading in object litterals. */
"unicorn/no-useless-fallback-in-spread": "deny",
/** It checks for an unnecessary array length check in a logical expression. */
"unicorn/no-useless-length-check": "deny",
/**
* Disallows returning values wrapped in `Promise.resolve` or `Promise.reject` in an async function or a
* `Promise#then/catch/finally` callback.
*/
"unicorn/no-useless-promise-resolve-reject": [
"deny",
{
allowReject: false,
},
],
/**
* Disallows using spread syntax in following, unnecessary cases:
*
* - Spread an array literal as elements of an array literal
* - Spread an array literal as arguments of a call or a new call
* - Spread an object literal as properties of an object literal
* - Use spread syntax to clone an array created inline
*/
"unicorn/no-useless-spread": "deny",
/** Disallows useless `default` cases in `switch` statements. */
"unicorn/no-useless-switch-case": "deny",
/** Prevents usage of undefined in cases where it would be useless. */
"unicorn/no-useless-undefined": "deny",
/**
* Prevents the use of zero fractions.
*
* There is no difference in JavaScript between, for example, `1,` `1.0` and `1.`, so prefer the former for consistency and brevity.
*/
"unicorn/no-zero-fractions": "deny",
/**
* This rule enforces proper case for numeric literals.
*
* When both an identifier and a numeric literal are in lower case, it can be hard to differentiate between them.
*/
"unicorn/number-literal-case": "deny",
/**
* Enforces a convention of grouping digits using numeric separators.
*
* A long series of digits can be difficult to read, and it can be difficult to determine the value of the number at a glance. Breaking up the digits with numeric separators (`_`) can greatly improve readability.
*/
"unicorn/numeric-separators-style": [
"deny",
{
binary: {
groupLength: 3,
minimumDigits: 4,
},
hexadecimal: {
groupLength: 3,
minimumDigits: 4,
},
number: {
groupLength: 3,
minimumDigits: 4,
},
octal: {
groupLength: 3,
minimumDigits: 4,
},
onlyIfContainsSeparator: false,
},
],
/**
* Enforces the use of `.addEventListener()` and `.removeEventListener()` over their on-function counterparts.
*
* For example, `foo.addEventListener('click', handler);` is preferred over `foo.onclick = handler;` for HTML DOM Events.
*
* There are numerous advantages of using `addEventListener`. Some of these advantages include registering unlimited event handlers and optionally having the event handler invoked only once.
*/
"unicorn/prefer-add-event-listener": "deny",
/**
* Encourages using `Array.prototype.find` instead of `filter(...)[0]` or similar patterns when only the first
* matching element is needed.
*/
"unicorn/prefer-array-find": "deny",
/** Prefers `Array#flat()` over legacy techniques to flatten arrays. */
"unicorn/prefer-array-flat": "deny",
/** Prefers the use of `.flatMap()` when `map().flat()` are used together. */
"unicorn/prefer-array-flat-map": "deny",
/**
* Enforces using `indexOf` or `lastIndexOf` instead of `findIndex` or `findLastIndex` when the callback is a simple strict equality comparison.
*
* Using `findIndex(x => x === value)` is unnecessarily verbose when `indexOf(value)` accomplishes the same thing more concisely and clearly. It also avoids the overhead of creating a callback function.
*/
"unicorn/prefer-array-index-of": "deny",
/**
* Prefers using `Array#some()` over `Array#find()`, `Array#findLast()` with comparing to `undefined`, or
* `Array#findIndex()`, `Array#findLastIndex()` and a non-zero length check on the result of `Array#filter()`.
*/
"unicorn/prefer-array-some": "deny",
/**
* Prefer the `Array#at()` and `String#at()` methods for index access.
*
* This rule also discourages using `String#charAt()`.
*/
"unicorn/prefer-at": [
"deny",
{
/**
* Check all index access, not just special patterns like `array.length - 1`. When enabled, `array[0]`,
* `array[1]`, etc. will also be flagged.
*/
checkAllIndexAccess: true,
/**
* List of function names to treat as "get last element" functions. These functions will be checked for `.at(-1)`
* usage.
*/
getLastElementFunctions: [],
},
],
/**
* Requires using `BigInt` literals (e.g. `123n`) instead of calling the `BigInt()` constructor with literal arguments such as numbers or numeric strings.
*
* Using `BigInt(…)` with literal values is unnecessarily verbose and less idiomatic than using a `BigInt` literal.
*/
"unicorn/prefer-bigint-literals": "deny",
/**
* Recommends using `Blob#text()` and `Blob#arrayBuffer()` over `FileReader#readAsText()` and
* `FileReader#readAsArrayBuffer()`.
*/
"unicorn/prefer-blob-reading-methods": "deny",
/**
* Prefers class field declarations over `this` assignments in constructors for static values.
*
* Class field declarations are more readable and less error-prone than assigning static values to `this` in the constructor. Using class fields keeps the constructor cleaner and makes the intent clearer.
*/
"unicorn/prefer-class-fields": "deny",
/**
* Prefers the use of `element.classList.toggle(className, condition)` over conditional add/remove patterns.
*
* The `toggle()` method is more concise and expressive than using conditional logic to switch between `add()` and `remove()`.
*/
"unicorn/prefer-classlist-toggle": "deny",
/**
* Prefers usage of `String.prototype.codePointAt` over `String.prototype.charCodeAt.` Prefers usage of
* `String.fromCodePoint` over `String.fromCharCode`.
*/
"unicorn/prefer-code-point": "deny",
/** Prefers use of `Date.now()` over new `Date().getTime()` or new `Date().valueOf()`. */
"unicorn/prefer-date-now": "deny",
/**
* Instead of reassigning a function parameter, default parameters should be used. The `foo = foo || 123` statement evaluates to `123` when `foo` is falsy, possibly leading to confusing behavior, whereas default parameters only apply when passed an `undefined` value. This rule only reports reassignments to literal values.
*
*You should disable this rule if you want your functions to deal with `null` and other falsy values the same way as `undefined`. Default parameters are exclusively applied when undefined is received.. However, we recommend moving away from null.
*
* Using default parameters makes it clear that a parameter has a default value, improving code readability and maintainability.
*/
"unicorn/prefer-default-parameters": "deny",
/**
* Enforces the use of, for example, `document.body.append(div);` over `document.body.appendChild(div);` for DOM
* nodes.
*/
"unicorn/prefer-dom-node-append": "deny",
/**
* Use `.dataset` on DOM elements over `getAttribute(…)`, `.setAttribute(…)`, `.removeAttribute(…)` and
* ``.hasAttribute()`.
*/
"unicorn/prefer-dom-node-dataset": "allow",
/** Prefers the use of `child.remove()` over `parentNode.removeChild(child)`. */
"unicorn/prefer-dom-node-remove": "deny",
/**
* Enforces the use of `.textContent` over `.innerText` for DOM nodes.
*
* There are some disadvantages of using `.innerText`.
*
* - `.innerText` is much more performance-heavy as it requires layout information to return the result.
* - `.innerText` is defined only for `HTMLElement` objects, while `.textContent` is defined for all `Node` objects.
* - `.innerText` is not standard, for example, it is not present in Firefox.
*/
"unicorn/prefer-dom-node-text-content": "deny",
/**
* Prefers `EventTarget` over `EventEmitter`.
*
* This rule reduces the bundle size and makes your code more cross-platform friendly.
*/
"unicorn/prefer-event-target": "deny",
/**
* Enforces the use of `globalThis` instead of environmentspecific global object aliases `(window,` `self,` or `global`).
*
* Using the standard `globalThis` makes your code portable across browsers, Web Workers, Node.js, and future JavaScript runtimes.
*
* `window` is only defined in browser main threads, `self` is used in Web Workers, and `global` is Nodespecific. Choosing the wrong alias causes runtime crashes when the code is executed outside of its original environment.
*
* `globalThis` clearly communicates that you are referring to the global object itself rather than a particular platform.
*/
"unicorn/prefer-global-this": "deny",
/**
* Prefer `includes()` over `indexOf()` when checking for existence or non-existence. All built-ins have `.includes()` in addition to `.indexOf()`.
*
* The `.includes()` method is more readable and less error-prone than `.indexOf()`.
*/
"unicorn/prefer-includes": "deny",
/**
* Enforces the use of `KeyboardEvent#key` over `KeyboardEvent#keyCode`, which is deprecated.
*
*The `.key` property is also more semantic and readable.
*
* The `keyCode,` `which`, and `charCode` properties are deprecated and should be avoided in favor of the `key` property.
*/
"unicorn/prefer-keyboard-event-key": "deny",
/**
* This rule finds ternary expressions that can be simplified to a logical operator.
*
* Using a logical operator is shorter and simpler than a ternary expression.
*/
"unicorn/prefer-logical-operator-over-ternary": "deny",
/** Prefers use of `Math.min()` and `Math.max()` instead of ternary expressions when performing simple comparisons. */
"unicorn/prefer-math-min-max": "deny",
/** Prefers use of `Math.trunc()` instead of bitwise operations for clarity and more reliable results. */
"unicorn/prefer-math-trunc": "deny",
/**
* Enforces the use of:
*
* - `childNode.replaceWith(newNode)` over `parentNode.replaceChild(newNode, oldNode)` ;
* - `referenceNode.before(newNode)` over `parentNode.insertBefore(newNode, referenceNode)` ;
* - `referenceNode.before('text')` over `referenceNode.insertAdjacentText('beforebegin', 'text')` ;
* - `referenceNode.before(newNode)` over `referenceNode.insertAdjacentElement('beforebegin', newNode)`.
*/
"unicorn/prefer-modern-dom-apis": "deny",
/**
* Checks for usage of legacy patterns for mathematical operations.
*
* Modern JavaScript provides more concise and readable alternatives to legacy patterns.
*
* Currently, the following cases are checked:
*
* - Prefer `Math.log10(x)` over alternatives
* - Prefer `Math.hypot(…)` over alternatives
*/
"unicorn/prefer-modern-math-apis": "deny",
/**
* Prefer JavaScript modules (ESM) over CommonJS.
*
* CommonJS globals and patterns (`require`, `module`, `exports`, `__filename`, `__dirname`) make code harder to
* migrate and can block ESM-only features.
*/
"unicorn/prefer-module": "deny",
/** Prefers built in functions, over custom ones with the same functionality. */
"unicorn/prefer-native-coercion-functions": "deny",
/**
* Prefer using a negative index over `.length - index` when possible.
*
* Using a negative index with `at` or `slice` is generally more readable and concise than using `.length - index`.
*/
"unicorn/prefer-negative-index": "deny",
/**
* Prefer using the `node:protocol` when importing Node.js builtin modules.
*
* Node.js builtin modules should be imported using the `node:` protocol to avoid ambiguity with local modules.
*/
"unicorn/prefer-node-protocol": "deny",
/**
* Disallows use of parseInt(), parseFloat(), isNan(), isFinite(), Nan, Infinity and -Infinity as global variables.
*
* ECMAScript 2015 moved globals onto the Number constructor for consistency and to slightly improve them. This rule
* enforces their usage to limit the usage of globals:
*
* - `Number.parseInt()` over `parseInt()`
* - `Number.parseFloat()` over `parseFloat()`
* - `Number.isNaN()` over `isNaN()` (they have slightly different behavior)
* - `Number.isFinite()` over `isFinite()` (they have slightly different behavior)
* - `Number.NaN` over `NaN`
* - `Number.POSITIVE_INFINITY` over `Infinity`
* - `Number.NEGATIVE_INFINITY` over `-Infinity`
*/
"unicorn/prefer-number-properties": [
"deny",
{
/** If set to `true`, checks for usage of `Infinity` and `-Infinity` as global variables. */
checkInfinity: true,
/** If set to `true`, checks for usage of `NaN` as a global variable. */
checkNaN: true,
},
],
/**
* Encourages using `Object.fromEntries` when converting an array of key-value pairs into an object.
*
* Manually constructing objects from key-value pairs using `reduce` or `forEach` is more verbose, error-prone, and harder to understand. The `Object.fromEntries` method is clearer, more declarative, and built for exactly this purpose.
*/
"unicorn/prefer-object-from-entries": "deny",
/**
* Prefers omitting the catch binding parameter if it is unused.
*
* It is unnecessary to bind the error to a variable if it is not used.
*/
"unicorn/prefer-optional-catch-binding": "deny",
/**
* Borrowing a method from an instance of `Array` or `Object` is less clear than getting it from the corresponding
* prototype.
*/
"unicorn/prefer-prototype-methods": "deny",
/**
* Prefer `.querySelector()` over `.getElementById().` And prefer `.querySelectorAll()` over
* `.getElementsByClassName()`, `.getElementsByTagName()`, and `.getElementsByName()`.
*/
"unicorn/prefer-query-selector": "deny",
/**
* Disallows the use of `Function.prototype.apply()` and suggests using `Reflect.apply()` instead.
*
* `Reflect.apply()` is arguably less verbose and easier to understand. In addition, when you accept arbitrary methods, it's not safe to assume `.apply()` exists or is not overridden.
*/
"unicorn/prefer-reflect-apply": "deny",
/** Prefers `RegExp#test()` over `String#match()` and `String#exec()`. */
"unicorn/prefer-regexp-test": "deny",
/**
* Enforces the use of `Response.json()` over `new Response(JSON.stringify())`.
*
* `Response.json()` is a more concise and semantically clear way to create JSON responses. It automatically sets the correct `Content-Type` header (`application/json`) and handles serialization, making the code more maintainable and less error-prone.
*/
"unicorn/prefer-response-static-json": "deny",
/** Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence. */
"unicorn/prefer-set-has": "deny",
/** Prefer `Set#size` over `Set#length` when the `Set` is converted to an array. */
"unicorn/prefer-set-size": "deny",
/**
* Enforces the use of the spread operator (...) over outdated patterns.
*
* Using the spread operator is more concise and readable.
*/
"unicorn/prefer-spread": "deny",
/**
* Prefers use of `String.raw` to avoid escaping `\`.
*
* Excessive backslashes can make string values less readable which can be avoided by using `String.raw`.
*/
"unicorn/prefer-string-raw": "deny",
/** Prefers `String#replaceAll()` over `String#replace()` when using a regex with the global flag. */
"unicorn/prefer-string-replace-all": "deny",
/** Prefer `String#slice()` over `String#substr()` and `String#substring()`. */
"unicorn/prefer-string-slice": "deny",
/** Prefer `String#startsWith()` and `String#endsWith()` over using a regex with `/^foo/` or `/foo$/`. */
"unicorn/prefer-string-starts-ends-with": "deny",
/**
* `String#trimLeft()` and `String#trimRight()` are aliases of `String#trimStart()` and `String#trimEnd()`. This is to ensure consistency and use direction-independent wording.
*
* The `trimLeft` and `trimRight` names are confusing and inconsistent with the rest of the language.
*/
"unicorn/prefer-string-trim-start-end": "deny",
/**
* Prefer using `structuredClone` to create a deep clone.
*
* `structuredClone` is the modern way to create a deep clone of a value.
*/
"unicorn/prefer-structured-clone": "deny",
/**
* Prefers ternary expressions over simple `if/else` statements.
*
* Simple `if/else` branches for the same operation are often shorter and clearer when expressed as a ternary.
*
* Je n'aime pas les ternaires.
*/
"unicorn/prefer-ternary": "allow",
/** Prefer top-level await over top-level promises and async function calls. */
"unicorn/prefer-top-level-await": "deny",
/** Enforce throwing a `TypeError` instead of a generic `Error` after a type checking if-statement. */
"unicorn/prefer-type-error": "deny",
/**
* Enforce consistent relative URL style.
*
* When using a relative URL in `new URL()`, the URL should either never or always use the `./` prefix consistently.
*/
"unicorn/relative-url-style": [
"deny",
/* Always add a ./ prefix to the relative URL when possible. */
"always",
],
/**
* Enforce using the separator argument with `Array#join()`.
*
* It's better to make it clear what the separator is when calling `Array#join()`, instead of relying on the default comma (`','`) separator.
*/
"unicorn/require-array-join-separator": "deny",
/**
* This rule enforces non-empty attribute list in `import`/`export` statements and `import()` expressions.
*
* Import attributes are meant to provide metadata about how a module should be loaded (e.g., with `{ type: "json"
* }`). An empty attribute object provides no information and should be removed.
*/
"unicorn/require-module-attributes": "deny",
/**
* Enforce non-empty specifier list in `import` and `export` statements.
*
* Empty `import`/`export` specifiers add no value and can be confusing. If you want to import a module for side effects, use `import 'module'` instead.
*/
"unicorn/require-module-specifiers": "deny",
/** Enforce using the digits argument with `Number#toFixed()`. */
"unicorn/require-number-to-fixed-digits-argument": "deny",
/**
* Enforce using the `targetOrigin` argument with `window.postMessage()`.
*
* Note that this rule may have false positives, as it is not capable of detecting all cases correctly without type information. As such, it may not be a good idea to enable in cases where `postMessage()` may be used with `BroadcastChannel` or worker/service worker contexts (for example, `WorkerGlobalScope#postMessage`, where the second argument is a transfer list or options object, not `targetOrigin`).
*
* When calling `window.postMessage()` without the `targetOrigin` argument, the message cannot be received by any window.
*/
"unicorn/require-post-message-target-origin": "deny",
/**
* Requires empty switch cases to omit braces, while non-empty cases must use braces. This reduces visual clutter for
* empty cases and enforces proper scoping for non-empty ones.
*
* Using braces unnecessarily for empty cases adds visual noise, while omitting braces in non-empty cases can lead to
* scoping issues.
*/
"unicorn/switch-case-braces": [
"deny",
/* Allow braces only when needed for scoping (e.g., variable or function declarations). */
"avoid",
],
/**
* Enforce consistent `break`/`return`/`continue`/`throw` position in case clauses.
*
* Enforce that terminating statements (`break`, `return`, `continue`, `throw`) appear inside the block statement of a `case` clause, not after it. This can happen when refactoring for example, removing an `if` wrapper but leaving the `break` outside the braces.
*/
"unicorn/switch-case-break-position": "deny",
/**
* This rule enforces consistent casing for text encoding identifiers, specifically:
*
* - `'utf8'` instead of `'UTF-8'` or `'utf-8'` (or `'utf-8'` if `withDash` is enabled) ;
* - `'ascii'` instead of `'ASCII'`.
*
* Inconsistent casing of encoding identifiers reduces code readability and can lead to subtle confusion across a
* codebase. Although casing is not strictly enforced by ECMAScript or Node.js, using lowercase is the conventional
* and widely recognized style.
*/
"unicorn/text-encoding-identifier-case": "deny",
/**
* This rule makes sure you always use new when throwing an error.
*
* In JavaScript, omitting `new` (e.g., `throw Error('message')`) is allowed, but it does not properly initialize the
* error object. This can lead to missing stack traces or incorrect prototype chains. Using `new` makes the intent
* clear, ensures consistent behavior, and helps avoid subtle bugs.
*/
"unicorn/throw-new-error": "deny",
};
export default unicornRules;