@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
230 lines (229 loc) • 8.07 kB
JavaScript
import { isEnabled } from "../utils/isEnabled.mjs";
//#region src/rules/javascript.ts
function getJavaScriptRules(options) {
const { unicorn, typescript, javascript: { maxDepth, maxNestedCallbacks } } = options.configs;
const isUnicornEnabled = isEnabled(unicorn);
const isTypescriptEnabled = isEnabled(typescript);
return {
"array-callback-return": "error",
"constructor-super": isTypescriptEnabled ? "off" : "error",
"for-direction": "error",
"getter-return": isTypescriptEnabled ? "off" : ["error", { allowImplicit: true }],
"no-async-promise-executor": "error",
"no-await-in-loop": "error",
"no-case-declarations": "error",
"no-class-assign": isTypescriptEnabled ? "off" : "error",
"no-compare-neg-zero": "error",
"no-cond-assign": "error",
"no-const-assign": isTypescriptEnabled ? "off" : "error",
"no-constant-binary-expression": ["error", { checkRelationalComparisons: true }],
"no-constant-condition": "error",
"no-constructor-return": "error",
"no-control-regex": "error",
"no-debugger": "error",
"no-delete-var": "error",
"no-dupe-args": isTypescriptEnabled ? "off" : "error",
"no-dupe-class-members": isTypescriptEnabled ? "off" : "error",
"no-dupe-else-if": "error",
"no-dupe-keys": isTypescriptEnabled ? "off" : "error",
"no-duplicate-case": "error",
"no-duplicate-imports": ["error", {
includeExports: true,
allowSeparateTypeImports: true
}],
"no-empty-character-class": "error",
"no-empty-pattern": "error",
"no-empty-static-block": "error",
"no-ex-assign": "error",
"no-fallthrough": "error",
"no-func-assign": isTypescriptEnabled ? "off" : "error",
"no-global-assign": "error",
"no-import-assign": isTypescriptEnabled ? "off" : "error",
"no-inner-declarations": "warn",
"no-invalid-regexp": "error",
"no-irregular-whitespace": "warn",
"no-loss-of-precision": "error",
"no-misleading-character-class": "error",
"no-promise-executor-return": "error",
"no-self-compare": "warn",
"no-template-curly-in-string": "error",
"no-unassigned-vars": "error",
"no-unmodified-loop-condition": ["warn", { checkConditionalExpressions: true }],
"no-unreachable-loop": "warn",
"no-unsafe-negation": isTypescriptEnabled ? "off" : ["error", { enforceForOrderingRelations: true }],
"no-unsafe-optional-chaining": ["error", { disallowArithmeticOperators: true }],
"no-unused-vars": [isTypescriptEnabled ? "off" : "error", {
args: "all",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_"
}],
"no-use-before-define": ["error", {
functions: false,
ignoreTypeReferences: false
}],
"no-useless-assignment": "error",
"require-atomic-updates": "warn",
"use-isnan": ["error", { enforceForIndexOf: true }],
"valid-typeof": "error",
"accessor-pairs": "error",
"block-scoped-var": "warn",
"camelcase": ["warn", {
properties: "never",
ignoreImports: true,
ignoreDestructuring: true
}],
"class-methods-use-this": ["error", {
ignoreOverrideMethods: true,
ignoreClassesWithImplements: "public-fields"
}],
"complexity": "warn",
"consistent-return": isTypescriptEnabled ? "off" : "error",
"consistent-this": "error",
"curly": "warn",
"default-case": isTypescriptEnabled ? "off" : "warn",
"default-case-last": "warn",
"default-param-last": isTypescriptEnabled ? "off" : "warn",
"dot-notation": isTypescriptEnabled ? "off" : "warn",
"eqeqeq": "error",
"func-name-matching": "warn",
"func-names": ["warn", "as-needed"],
"guard-for-in": "warn",
"grouped-accessor-pairs": [
"warn",
"anyOrder",
{ enforceForTSTypes: true }
],
"init-declarations": "error",
"logical-assignment-operators": "warn",
"max-depth": ["warn", maxDepth],
"max-nested-callbacks": ["warn", maxNestedCallbacks],
"max-params": ["warn", { countThis: "always" }],
"new-cap": "warn",
"no-array-constructor": "error",
"no-caller": "error",
"no-console": ["warn", { allow: [
"info",
"warn",
"error",
"table",
"group",
"groupEnd",
"groupCollapsed"
] }],
"no-empty": ["warn", { allowEmptyCatch: true }],
"no-empty-function": ["error", { allow: [
"overrideMethods",
"decoratedFunctions",
"privateConstructors",
"protectedConstructors"
] }],
"no-eq-null": "warn",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-boolean-cast": ["error", { enforceForInnerExpressions: true }],
"no-extra-label": "error",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": isTypescriptEnabled ? "off" : "error",
"no-invalid-this": isTypescriptEnabled ? "off" : "error",
"no-iterator": "warn",
"no-label-var": "error",
"no-lone-blocks": "error",
"no-lonely-if": isUnicornEnabled ? "off" : "warn",
"no-loop-func": "warn",
"no-multi-assign": ["error", { ignoreNonDeclaration: true }],
"no-multi-str": "error",
"no-negated-condition": "warn",
"no-nested-ternary": isUnicornEnabled ? "off" : "warn",
"no-new": "error",
"no-new-func": "error",
"no-new-native-nonconstructor": isTypescriptEnabled || isUnicornEnabled ? "off" : "error",
"no-new-wrappers": "error",
"no-nonoctal-decimal-escape": "error",
"no-obj-calls": isTypescriptEnabled ? "off" : "error",
"no-object-constructor": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-param-reassign": "error",
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"no-proto": "warn",
"no-prototype-builtins": "error",
"no-regex-spaces": "error",
"no-return-assign": ["error", "always"],
"no-script-url": "error",
"no-self-assign": "error",
"no-sequences": ["error", { allowInParentheses: false }],
"no-setter-return": isTypescriptEnabled ? "off" : "error",
"no-shadow": ["error", {
hoist: "all",
builtinGlobals: true,
ignoreTypeValueShadow: false,
ignoreFunctionTypeParameterNameValueShadow: false,
allow: [
"name",
"event",
"status"
]
}],
"no-shadow-restricted-names": "warn",
"no-sparse-arrays": "error",
"no-this-before-super": isTypescriptEnabled ? "off" : "error",
"no-throw-literal": "error",
"no-undef": isTypescriptEnabled ? "off" : "error",
"no-undef-init": "error",
"no-unexpected-multiline": "error",
"no-unneeded-ternary": "error",
"no-unreachable": isTypescriptEnabled ? "off" : "error",
"no-unsafe-finally": "error",
"no-unused-expressions": ["error", {
allowTernary: true,
enforceForJSX: true,
allowShortCircuit: true,
allowTaggedTemplates: true
}],
"no-unused-labels": "error",
"no-unused-private-class-members": isTypescriptEnabled ? "off" : "error",
"no-useless-backreference": "error",
"no-useless-call": "error",
"no-useless-catch": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-var": "error",
"no-void": ["error", { allowAsStatement: true }],
"no-with": "error",
"object-shorthand": "warn",
"operator-assignment": "warn",
"prefer-arrow-callback": ["warn", { allowUnboundThis: true }],
"prefer-const": "error",
"prefer-destructuring": isTypescriptEnabled ? "off" : ["warn", {
object: true,
array: false
}],
"prefer-exponentiation-operator": "warn",
"prefer-named-capture-group": "warn",
"prefer-numeric-literals": "warn",
"prefer-object-has-own": "warn",
"prefer-object-spread": "warn",
"prefer-promise-reject-errors": isTypescriptEnabled ? "off" : ["warn", { allowEmptyReject: true }],
"prefer-regex-literals": ["warn", { disallowRedundantWrapping: true }],
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"prefer-template": "warn",
"preserve-caught-error": "warn",
"radix": "warn",
"require-await": isTypescriptEnabled ? "off" : "warn",
"require-yield": "error",
"strict": "error",
"symbol-description": "warn",
"yoda": "warn"
};
}
//#endregion
export { getJavaScriptRules };