@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
163 lines (162 loc) • 5.15 kB
JavaScript
//#region src/rules/javascript.ts
function getJavaScriptRules(options) {
const { maxDepth, functionStyle, maxNestedCallbacks, preferNamedExports } = options.configs.base;
const javascriptRules = {
"no-self-compare": "warn",
"no-await-in-loop": "error",
"no-unassigned-vars": "error",
"no-unreachable-loop": "warn",
"no-inner-declarations": "warn",
"require-atomic-updates": "warn",
"array-callback-return": "error",
"no-useless-assignment": "error",
"no-constructor-return": "error",
"no-async-promise-executor": "error",
"no-promise-executor-return": "error",
"no-template-curly-in-string": "error",
"no-unmodified-loop-condition": "error",
"use-isnan": ["error", { enforceForIndexOf: true }],
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"no-unsafe-negation": ["error", { enforceForOrderingRelations: true }],
"no-unsafe-optional-chaining": ["error", { disallowArithmeticOperators: true }],
"no-use-before-define": ["error", {
functions: false,
ignoreTypeReferences: false
}],
"no-duplicate-imports": ["error", {
includeExports: true,
allowSeparateTypeImports: true
}],
"yoda": "warn",
"strict": "error",
"no-var": "error",
"eqeqeq": "error",
"no-new": "error",
"new-cap": "warn",
"no-eval": "error",
"no-void": "error",
"no-proto": "warn",
"no-empty": "warn",
"camelcase": "warn",
"no-caller": "error",
"no-eq-null": "warn",
"complexity": "warn",
"sort-imports": "off",
"no-redeclare": "off",
"no-iterator": "warn",
"no-continue": "warn",
"no-new-func": "error",
"guard-for-in": "warn",
"no-loop-func": "warn",
"default-case": "warn",
"no-lonely-if": "error",
"no-label-var": "error",
"no-multi-str": "error",
"prefer-const": "error",
"require-await": "warn",
"dot-notation": "error",
"no-script-url": "error",
"no-undef-init": "error",
"no-extra-bind": "error",
"prefer-spread": "error",
"no-lone-blocks": "error",
"no-extra-label": "error",
"accessor-pairs": "error",
"prefer-template": "warn",
"no-invalid-this": "error",
"no-useless-call": "error",
"no-implied-eval": "error",
"consistent-this": "error",
"no-octal-escape": "error",
"no-new-wrappers": "error",
"block-scoped-var": "warn",
"object-shorthand": "warn",
"no-throw-literal": "error",
"no-extend-native": "error",
"default-case-last": "warn",
"no-nested-ternary": "warn",
"no-useless-return": "error",
"init-declarations": "error",
"consistent-return": "error",
"no-useless-concat": "error",
"no-useless-rename": "error",
"default-param-last": "warn",
"symbol-description": "warn",
"func-name-matching": "warn",
"prefer-rest-params": "error",
"operator-assignment": "error",
"no-unneeded-ternary": "error",
"no-implicit-globals": "error",
"prefer-destructuring": "warn",
"no-implicit-coercion": "error",
"no-array-constructor": "error",
"no-underscore-dangle": "error",
"prefer-object-spread": "error",
"radix": ["error", "as-needed"],
"curly": ["warn", "multi-line"],
"max-depth": ["warn", maxDepth],
"no-object-constructor": "error",
"prefer-object-has-own": "error",
"no-useless-constructor": "error",
"class-methods-use-this": "error",
"prefer-numeric-literals": "error",
"no-useless-computed-key": "error",
"prefer-named-capture-group": "warn",
"no-return-assign": ["error", "always"],
"prefer-exponentiation-operator": "error",
"no-bitwise": ["error", { int32Hint: true }],
"max-params": ["warn", { countVoidThis: true }],
"logical-assignment-operators": ["error", "always"],
"max-nested-callbacks": ["warn", maxNestedCallbacks],
"no-sequences": ["error", { allowInParentheses: false }],
"no-multi-assign": ["error", { ignoreNonDeclaration: true }],
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"prefer-arrow-callback": ["error", { allowUnboundThis: true }],
"no-shadow-restricted-names": ["warn", { reportGlobalThis: true }],
"func-style": [
"warn",
functionStyle,
{ allowTypeAnnotation: true }
],
"prefer-promise-reject-errors": ["error", { allowEmptyReject: true }],
"prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
"no-extra-boolean-cast": ["error", { enforceForInnerExpressions: true }],
"no-console": ["warn", { allow: [
"info",
"warn",
"error",
"table",
"group",
"groupEnd",
"groupCollapsed"
] }],
"no-shadow": ["error", {
hoist: "all",
allow: ["name"],
builtinGlobals: true,
ignoreTypeValueShadow: false,
ignoreFunctionTypeParameterNameValueShadow: false
}],
"no-restricted-exports": [preferNamedExports ? "error" : "off", { restrictDefaultExports: {
named: true,
namedFrom: true,
defaultFrom: true,
namespaceFrom: true
} }],
"no-empty-function": ["error", { allow: [
"overrideMethods",
"decoratedFunctions",
"privateConstructors",
"protectedConstructors"
] }],
"no-unused-expressions": ["error", {
allowTernary: true,
enforceForJSX: true,
allowShortCircuit: true,
allowTaggedTemplates: true
}]
};
return javascriptRules;
}
//#endregion
export { getJavaScriptRules };