import type { DummyRuleMap } from "oxlint"; const unicornRules: DummyRuleMap = { /** * 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: ["_"], name: "error", }, ], /** 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", /** * 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": [ "deny", { "non-zero": "not-equal", }, ], /** * 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", "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", "unicorn/no-array-reverse": "deny", "unicorn/no-array-sort": "deny", /** * 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. */ "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", "unicorn/no-instanceof-builtins": "deny", /** * 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", "unicorn/no-nested-ternary": "deny", /** Disallow new `Array()`. */ "unicorn/no-new-array": "deny", /** Disallows the deprecated new `Buffer()` constructor. */ "unicorn/no-new-buffer": "deny", "unicorn/no-null": "deny", /** 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", "unicorn/no-unreadable-array-destructuring": "deny", /** This rule disallows IIFEs with a parenthesized arrow function body. */ "unicorn/no-unreadable-iife": "deny", "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", "unicorn/no-zero-fractions": "deny", "unicorn/number-literal-case": "deny", "unicorn/numeric-separators-style": "deny", "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", "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: [], }, ], "unicorn/prefer-bigint-literals": "deny", /** * Recommends using `Blob#text()` and `Blob#arrayBuffer()` over `FileReader#readAsText()` and * `FileReader#readAsArrayBuffer()`. */ "unicorn/prefer-blob-reading-methods": "deny", "unicorn/prefer-class-fields": "deny", "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", "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", "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", "unicorn/prefer-global-this": "deny", "unicorn/prefer-includes": "deny", "unicorn/prefer-keyboard-event-key": "deny", "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", "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", "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, }, ], "unicorn/prefer-object-from-entries": "deny", "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", "unicorn/prefer-reflect-apply": "deny", /** Prefers `RegExp#test()` over `String#match()` and `String#exec()`. */ "unicorn/prefer-regexp-test": "deny", "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", "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", "unicorn/prefer-string-trim-start-end": "deny", "unicorn/prefer-structured-clone": "deny", "unicorn/prefer-ternary": "off", /** 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", "unicorn/relative-url-style": "deny", "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", "unicorn/require-module-specifiers": "deny", /** Enforce using the digits argument with `Number#toFixed()`. */ "unicorn/require-number-to-fixed-digits-argument": "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", "avoid"], /** * 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;