|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import eslint from '@eslint/js'; |
|
import globals from 'globals'; |
|
import tseslint from 'typescript-eslint'; |
|
import stylistic from '@stylistic/eslint-plugin'; |
|
|
|
|
|
|
|
|
|
|
|
export { eslint, globals, tseslint, stylistic }; |
|
|
|
|
|
export const plugin = { |
|
plugins: { |
|
'@stylistic': stylistic, |
|
'@typescript-eslint': tseslint.plugin, |
|
}, |
|
}; |
|
|
|
|
|
export const configure = (...args) => [ |
|
plugin, |
|
...tseslint.config(...args), |
|
]; |
|
|
|
|
|
export const defaultRules = { |
|
...stylistic.configs.customize({ |
|
braceStyle: '1tbs', |
|
indent: 'tab', |
|
semi: true, |
|
jsx: true, |
|
|
|
}).rules, |
|
|
|
|
|
|
|
|
|
|
|
"@stylistic/no-mixed-operators": "off", |
|
|
|
|
|
|
|
|
|
"no-unused-vars": ["warn", { |
|
args: "all", |
|
argsIgnorePattern: ".", |
|
caughtErrors: "all", |
|
destructuredArrayIgnorePattern: ".", |
|
ignoreRestSiblings: true, |
|
}], |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"@stylistic/max-len": ["warn", { |
|
"code": 120, "tabWidth": 0, |
|
|
|
"ignorePattern": "^\\s*(?:\\/\\/ \\s*)?(?:(?:export )?(?:let |const |readonly )?[a-zA-Z0-9_$.]+(?: \\+?=>? )|[a-zA-Z0-9$]+: \\[?|(?:return |throw )?(?:new )?(?:[a-zA-Z0-9$.]+\\()?)?(?:Utils\\.html|(?:this\\.)?(?:room\\.)?tr|\\$\\()?['\"`/]", |
|
}], |
|
"prefer-const": ["warn", { "destructuring": "all" }], |
|
|
|
|
|
|
|
"@stylistic/new-parens": "off", |
|
"no-prototype-builtins": "off", |
|
|
|
|
|
|
|
"no-empty": ["error", { "allowEmptyCatch": true }], |
|
"no-case-declarations": "off", |
|
|
|
|
|
|
|
"array-callback-return": "error", |
|
"no-constructor-return": "error", |
|
"no-dupe-class-members": "error", |
|
"no-extend-native": "error", |
|
"no-extra-bind": "warn", |
|
"no-extra-label": "warn", |
|
"no-eval": "error", |
|
"no-implied-eval": "error", |
|
"no-inner-declarations": ["error", "functions"], |
|
"no-iterator": "error", |
|
"no-fallthrough": ["error", { allowEmptyCase: true, reportUnusedFallthroughComment: true }], |
|
"no-promise-executor-return": ["error", { allowVoid: true }], |
|
"no-return-assign": "error", |
|
"no-self-compare": "error", |
|
"no-sequences": "error", |
|
"no-shadow": "error", |
|
"no-template-curly-in-string": "error", |
|
"no-throw-literal": "warn", |
|
"no-unmodified-loop-condition": "error", |
|
|
|
|
|
|
|
|
|
"no-unused-expressions": ["error", { allowTernary: true, allowTaggedTemplates: true, enforceForJSX: true }], |
|
"no-useless-call": "error", |
|
|
|
"require-atomic-updates": "error", |
|
|
|
|
|
|
|
"@stylistic/member-delimiter-style": ["error", { |
|
multiline: { delimiter: "comma", requireLast: true }, |
|
singleline: { delimiter: "comma", requireLast: false }, |
|
overrides: { interface: { |
|
multiline: { delimiter: "semi", requireLast: true }, |
|
singleline: { delimiter: "semi", requireLast: false }, |
|
} }, |
|
}], |
|
"default-case-last": "error", |
|
"eqeqeq": ["error", "always", { null: "ignore" }], |
|
"no-array-constructor": "error", |
|
"no-duplicate-imports": "error", |
|
"no-implicit-coercion": ["error", { allow: ["!!", "+"] }], |
|
"no-multi-str": "error", |
|
"no-object-constructor": "error", |
|
"no-proto": "error", |
|
"no-unneeded-ternary": "error", |
|
"no-useless-computed-key": "error", |
|
"no-useless-constructor": "error", |
|
"no-useless-rename": "error", |
|
"no-useless-return": "error", |
|
"no-var": "error", |
|
"object-shorthand": ["error", "always"], |
|
"operator-assignment": ["error", "always"], |
|
"prefer-arrow-callback": "error", |
|
"prefer-exponentiation-operator": "error", |
|
"prefer-numeric-literals": "error", |
|
"prefer-object-has-own": "error", |
|
"prefer-object-spread": "error", |
|
"prefer-promise-reject-errors": "error", |
|
"prefer-regex-literals": "error", |
|
"prefer-rest-params": "error", |
|
"prefer-spread": "error", |
|
"radix": ["error", "as-needed"], |
|
|
|
|
|
|
|
"@stylistic/quotes": "off", |
|
"@stylistic/quote-props": "off", |
|
"@stylistic/function-call-spacing": "error", |
|
"@stylistic/arrow-parens": ["error", "as-needed"], |
|
"@stylistic/comma-dangle": ["error", { |
|
"arrays": "always-multiline", |
|
"objects": "always-multiline", |
|
"imports": "always-multiline", |
|
"exports": "always-multiline", |
|
"functions": "never", |
|
"importAttributes": "always-multiline", |
|
"dynamicImports": "always-multiline", |
|
"enums": "always-multiline", |
|
"generics": "always-multiline", |
|
"tuples": "always-multiline", |
|
}], |
|
"@stylistic/jsx-wrap-multilines": "off", |
|
"@stylistic/jsx-closing-bracket-location": ["error", "line-aligned"], |
|
|
|
"@stylistic/jsx-closing-tag-location": "off", |
|
"@stylistic/jsx-one-expression-per-line": "off", |
|
"@stylistic/jsx-max-props-per-line": "off", |
|
"@stylistic/jsx-function-call-newline": "off", |
|
"no-restricted-syntax": ["error", |
|
{ selector: "CallExpression[callee.name='Symbol']", message: "Annoying to serialize, just use a string" }, |
|
], |
|
|
|
|
|
|
|
"@stylistic/block-spacing": "error", |
|
"@stylistic/operator-linebreak": ["error", "after"], |
|
"@stylistic/max-statements-per-line": ["error", { max: 3, ignoredNodes: ['BreakStatement'] }], |
|
"@stylistic/lines-between-class-members": "off", |
|
"@stylistic/multiline-ternary": "off", |
|
"@stylistic/object-curly-spacing": ["error", "always"], |
|
"@stylistic/indent": ["error", "tab", { "flatTernaryExpressions": true }], |
|
}; |
|
|
|
|
|
export const defaultRulesTS = { |
|
...defaultRules, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"@typescript-eslint/consistent-indexed-object-style": "off", |
|
|
|
|
|
|
|
"no-unused-vars": "off", |
|
"@typescript-eslint/no-unused-vars": defaultRules["no-unused-vars"], |
|
"no-shadow": "off", |
|
"@typescript-eslint/no-shadow": defaultRules["no-shadow"], |
|
"no-dupe-class-members": "off", |
|
"@typescript-eslint/no-dupe-class-members": defaultRules["no-dupe-class-members"], |
|
"no-unused-expressions": "off", |
|
"@typescript-eslint/no-unused-expressions": defaultRules["no-unused-expressions"], |
|
|
|
|
|
|
|
"@typescript-eslint/no-empty-function": "off", |
|
"@typescript-eslint/no-explicit-any": "off", |
|
"@typescript-eslint/no-non-null-assertion": "off", |
|
|
|
|
|
|
|
"@typescript-eslint/no-empty-object-type": "error", |
|
"@typescript-eslint/no-extra-non-null-assertion": "error", |
|
"@typescript-eslint/no-misused-new": "error", |
|
|
|
|
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", |
|
|
|
|
|
|
|
"@typescript-eslint/naming-convention": ["error", { |
|
"selector": ["class", "interface", "typeAlias"], |
|
"format": ["PascalCase"], |
|
}], |
|
|
|
|
|
|
|
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }], |
|
"@typescript-eslint/prefer-namespace-keyword": "error", |
|
"@typescript-eslint/adjacent-overload-signatures": "error", |
|
"@typescript-eslint/array-type": "error", |
|
"@typescript-eslint/consistent-type-assertions": ["error", { "assertionStyle": "as" }], |
|
"@typescript-eslint/consistent-type-definitions": "off", |
|
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }], |
|
"@typescript-eslint/explicit-member-accessibility": ["error", { "accessibility": "no-public" }], |
|
"@typescript-eslint/parameter-properties": "error", |
|
|
|
|
|
"@typescript-eslint/no-this-alias": ["error", { "allowedNames": ["source", "target"] }], |
|
|
|
|
|
"@typescript-eslint/prefer-as-const": "error", |
|
"@typescript-eslint/prefer-for-of": "error", |
|
"@typescript-eslint/prefer-function-type": "error", |
|
"@typescript-eslint/prefer-return-this-type": "error", |
|
"@typescript-eslint/triple-slash-reference": "error", |
|
"@typescript-eslint/unified-signatures": "error", |
|
}; |
|
|
|
|
|
export const defaultRulesTSChecked = { |
|
...defaultRulesTS, |
|
|
|
|
|
|
|
"@typescript-eslint/no-unnecessary-type-arguments": "error", |
|
"@typescript-eslint/restrict-plus-operands": ["error", { |
|
allowBoolean: false, allowNullish: false, allowNumberAndString: false, allowRegExp: false, |
|
}], |
|
"@typescript-eslint/restrict-template-expressions": ["error", { |
|
allow: [{ name: ['Error', 'URL', 'URLSearchParams'], from: 'lib' }], |
|
allowBoolean: false, allowNever: false, allowNullish: false, allowRegExp: false, |
|
}], |
|
|
|
|
|
|
|
"@typescript-eslint/no-unsafe-assignment": "off", |
|
"@typescript-eslint/no-unsafe-call": "off", |
|
"@typescript-eslint/no-unsafe-member-access": "off", |
|
"@typescript-eslint/no-unsafe-return": "off", |
|
"@typescript-eslint/no-unsafe-argument": "off", |
|
|
|
|
|
|
|
"@typescript-eslint/prefer-includes": "error", |
|
"@typescript-eslint/prefer-nullish-coalescing": "off", |
|
"@typescript-eslint/dot-notation": "off", |
|
"@typescript-eslint/no-confusing-non-null-assertion": "off", |
|
}; |
|
|
|
|
|
export const defaultRulesES3 = { |
|
...defaultRules, |
|
|
|
|
|
"no-var": "off", |
|
"object-shorthand": ["error", "never"], |
|
"prefer-arrow-callback": "off", |
|
"prefer-exponentiation-operator": "off", |
|
"prefer-object-has-own": "off", |
|
"prefer-object-spread": "off", |
|
"prefer-rest-params": "off", |
|
"prefer-spread": "off", |
|
"radix": "off", |
|
"@stylistic/comma-dangle": "error", |
|
"no-unused-vars": ["warn", { |
|
args: "all", |
|
argsIgnorePattern: ".", |
|
caughtErrors: "all", |
|
caughtErrorsIgnorePattern: "^e(rr)?$", |
|
destructuredArrayIgnorePattern: ".", |
|
ignoreRestSiblings: true, |
|
}], |
|
"no-restricted-syntax": ["error", |
|
{ selector: "TaggedTemplateExpression", message: "Hard to compile down to ES3" }, |
|
{ selector: "CallExpression[callee.name='Symbol']", message: "Annoying to serialize, just use a string" }, |
|
], |
|
|
|
|
|
"no-redeclare": "off", |
|
|
|
|
|
|
|
|
|
"no-caller": "error", |
|
"no-invalid-this": "error", |
|
"no-new-wrappers": "error", |
|
|
|
"no-restricted-globals": ["error", "Proxy", "Reflect", "Symbol", "WeakSet", "WeakMap", "Set", "Map"], |
|
"unicode-bom": "error", |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const defaultRulesES3TSChecked = { |
|
...defaultRulesTSChecked, |
|
"radix": "off", |
|
"no-restricted-globals": ["error", "Proxy", "Reflect", "Symbol", "WeakSet", "WeakMap", "Set", "Map"], |
|
"no-restricted-syntax": ["error", "TaggedTemplateExpression", "YieldExpression", "AwaitExpression", "BigIntLiteral"], |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function extractPlugin(configs) { |
|
return configs.find(config => !config.rules) || |
|
(() => { throw new Error('No plugin found'); })(); |
|
} |
|
|
|
|
|
|
|
|
|
function extractRules(configs) { |
|
const rules = {}; |
|
for (const config of configs.filter(c => c.rules)) { |
|
Object.assign(rules, config.rules); |
|
} |
|
return rules; |
|
} |
|
const tseslintPlugin = extractPlugin(tseslint.configs.stylisticTypeChecked); |
|
|
|
|
|
export const configs = { |
|
js: [{ |
|
rules: { |
|
...eslint.configs.recommended.rules, |
|
...defaultRules, |
|
}, |
|
}], |
|
ts: [tseslintPlugin, { |
|
rules: { |
|
...eslint.configs.recommended.rules, |
|
...extractRules(tseslint.configs.recommendedTypeChecked), |
|
...extractRules(tseslint.configs.stylisticTypeChecked), |
|
...defaultRulesTSChecked, |
|
}, |
|
}], |
|
es3: [{ |
|
rules: { |
|
...eslint.configs.recommended.rules, |
|
...defaultRulesES3, |
|
}, |
|
}], |
|
es3ts: [tseslintPlugin, { |
|
rules: { |
|
...eslint.configs.recommended.rules, |
|
...extractRules(tseslint.configs.recommendedTypeChecked), |
|
...extractRules(tseslint.configs.stylisticTypeChecked), |
|
...defaultRulesES3TSChecked, |
|
}, |
|
}], |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|