Last active
May 30, 2024 04:44
-
-
Save BinToss/31b7be46edf9ccf63c9ce776dddfad25 to your computer and use it in GitHub Desktop.
Debugging ESLint FlatCompat pushing a function to a string[]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// derived from https://github.com/moonrepo/dev/blob/f3c51298bf732182108ee8790371be0a4e376ff6/packages/eslint-config/src/module.ts#L131-L137 | |
{ | |
rules: { | |
"import/no-default-export": "off", | |
}, | |
// files must be a string[]. Functions will cause minimatch to throw a TypeError. | |
files: [ | |
absoluteFilePath => eslintrcConfig.criteria.test(absoluteFilePath), | |
], | |
} |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* search for module.js#overrides[0] | |
* Approximate location is Line 45723 | |
* | |
* FlatConfig property `files` is a string[] of minimatch patterns. | |
* However, (typeof this[16].files[0]) === "function"; | |
* this function is `absoluteFilePath => eslintrcConfig.criteria.test(absoluteFilePath)` from @ c:\Repos\HaloSPV3\hce.shared-config\node_modules\@eslint\eslintrc\lib\flat-compat.js:121 | |
*/ | |
return [ | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\best-practices.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\best-practices.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"accessor-pairs": "off", | |
"array-callback-return": [ | |
"error", | |
{ | |
allowImplicit: true, | |
}, | |
], | |
"block-scoped-var": "error", | |
complexity: [ | |
"off", | |
20, | |
], | |
"class-methods-use-this": [ | |
"error", | |
{ | |
exceptMethods: [ | |
], | |
}, | |
], | |
"consistent-return": "error", | |
curly: [ | |
"error", | |
"multi-line", | |
], | |
"default-case": [ | |
"error", | |
{ | |
commentPattern: "^no default$", | |
}, | |
], | |
"default-case-last": "error", | |
"default-param-last": "error", | |
"dot-notation": [ | |
"error", | |
{ | |
allowKeywords: true, | |
}, | |
], | |
"dot-location": [ | |
"error", | |
"property", | |
], | |
eqeqeq: [ | |
"error", | |
"always", | |
{ | |
null: "ignore", | |
}, | |
], | |
"grouped-accessor-pairs": "error", | |
"guard-for-in": "error", | |
"max-classes-per-file": [ | |
"error", | |
1, | |
], | |
"no-alert": "warn", | |
"no-caller": "error", | |
"no-case-declarations": "error", | |
"no-constructor-return": "error", | |
"no-div-regex": "off", | |
"no-else-return": [ | |
"error", | |
{ | |
allowElseIf: false, | |
}, | |
], | |
"no-empty-function": [ | |
"error", | |
{ | |
allow: [ | |
"arrowFunctions", | |
"functions", | |
"methods", | |
], | |
}, | |
], | |
"no-empty-pattern": "error", | |
"no-eq-null": "off", | |
"no-eval": "error", | |
"no-extend-native": "error", | |
"no-extra-bind": "error", | |
"no-extra-label": "error", | |
"no-fallthrough": "error", | |
"no-floating-decimal": "error", | |
"no-global-assign": [ | |
"error", | |
{ | |
exceptions: [ | |
], | |
}, | |
], | |
"no-native-reassign": "off", | |
"no-implicit-coercion": [ | |
"off", | |
{ | |
boolean: false, | |
number: true, | |
string: true, | |
allow: [ | |
], | |
}, | |
], | |
"no-implicit-globals": "off", | |
"no-implied-eval": "error", | |
"no-invalid-this": "off", | |
"no-iterator": "error", | |
"no-labels": [ | |
"error", | |
{ | |
allowLoop: false, | |
allowSwitch: false, | |
}, | |
], | |
"no-lone-blocks": "error", | |
"no-loop-func": "error", | |
"no-magic-numbers": [ | |
"off", | |
{ | |
ignore: [ | |
], | |
ignoreArrayIndexes: true, | |
enforceConst: true, | |
detectObjects: false, | |
}, | |
], | |
"no-multi-spaces": [ | |
"error", | |
{ | |
ignoreEOLComments: false, | |
}, | |
], | |
"no-multi-str": "error", | |
"no-new": "error", | |
"no-new-func": "error", | |
"no-new-wrappers": "error", | |
"no-nonoctal-decimal-escape": "error", | |
"no-octal": "error", | |
"no-octal-escape": "error", | |
"no-param-reassign": [ | |
"error", | |
{ | |
props: true, | |
ignorePropertyModificationsFor: [ | |
"acc", | |
"accumulator", | |
"e", | |
"ctx", | |
"context", | |
"req", | |
"request", | |
"res", | |
"response", | |
"$scope", | |
"staticContext", | |
], | |
}, | |
], | |
"no-proto": "error", | |
"no-redeclare": "error", | |
"no-restricted-properties": [ | |
"error", | |
{ | |
object: "arguments", | |
property: "callee", | |
message: "arguments.callee is deprecated", | |
}, | |
{ | |
object: "global", | |
property: "isFinite", | |
message: "Please use Number.isFinite instead", | |
}, | |
{ | |
object: "self", | |
property: "isFinite", | |
message: "Please use Number.isFinite instead", | |
}, | |
{ | |
object: "window", | |
property: "isFinite", | |
message: "Please use Number.isFinite instead", | |
}, | |
{ | |
object: "global", | |
property: "isNaN", | |
message: "Please use Number.isNaN instead", | |
}, | |
{ | |
object: "self", | |
property: "isNaN", | |
message: "Please use Number.isNaN instead", | |
}, | |
{ | |
object: "window", | |
property: "isNaN", | |
message: "Please use Number.isNaN instead", | |
}, | |
{ | |
property: "__defineGetter__", | |
message: "Please use Object.defineProperty instead.", | |
}, | |
{ | |
property: "__defineSetter__", | |
message: "Please use Object.defineProperty instead.", | |
}, | |
{ | |
object: "Math", | |
property: "pow", | |
message: "Use the exponentiation operator (**) instead.", | |
}, | |
], | |
"no-return-assign": [ | |
"error", | |
"always", | |
], | |
"no-return-await": "error", | |
"no-script-url": "error", | |
"no-self-assign": [ | |
"error", | |
{ | |
props: true, | |
}, | |
], | |
"no-self-compare": "error", | |
"no-sequences": "error", | |
"no-throw-literal": "error", | |
"no-unmodified-loop-condition": "off", | |
"no-unused-expressions": [ | |
"error", | |
{ | |
allowShortCircuit: false, | |
allowTernary: false, | |
allowTaggedTemplates: false, | |
}, | |
], | |
"no-unused-labels": "error", | |
"no-useless-call": "off", | |
"no-useless-catch": "error", | |
"no-useless-concat": "error", | |
"no-useless-escape": "error", | |
"no-useless-return": "error", | |
"no-void": "error", | |
"no-warning-comments": [ | |
"off", | |
{ | |
terms: [ | |
"todo", | |
"fixme", | |
"xxx", | |
], | |
location: "start", | |
}, | |
], | |
"no-with": "error", | |
"prefer-promise-reject-errors": [ | |
"error", | |
{ | |
allowEmptyReject: true, | |
}, | |
], | |
"prefer-named-capture-group": "off", | |
"prefer-regex-literals": [ | |
"error", | |
{ | |
disallowRedundantWrapping: true, | |
}, | |
], | |
radix: "error", | |
"require-await": "off", | |
"require-unicode-regexp": "off", | |
"vars-on-top": "error", | |
"wrap-iife": [ | |
"error", | |
"outside", | |
{ | |
functionPrototypeMethods: false, | |
}, | |
], | |
yoda: "error", | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\errors.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\errors.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"for-direction": "error", | |
"getter-return": [ | |
"error", | |
{ | |
allowImplicit: true, | |
}, | |
], | |
"no-async-promise-executor": "error", | |
"no-await-in-loop": "error", | |
"no-compare-neg-zero": "error", | |
"no-cond-assign": [ | |
"error", | |
"always", | |
], | |
"no-console": "warn", | |
"no-constant-condition": "warn", | |
"no-control-regex": "error", | |
"no-debugger": "error", | |
"no-dupe-args": "error", | |
"no-dupe-else-if": "error", | |
"no-dupe-keys": "error", | |
"no-duplicate-case": "error", | |
"no-empty": "error", | |
"no-empty-character-class": "error", | |
"no-ex-assign": "error", | |
"no-extra-boolean-cast": "error", | |
"no-extra-parens": [ | |
"off", | |
"all", | |
{ | |
conditionalAssign: true, | |
nestedBinaryExpressions: false, | |
returnAssign: false, | |
ignoreJSX: "all", | |
enforceForArrowConditionals: false, | |
}, | |
], | |
"no-extra-semi": "error", | |
"no-func-assign": "error", | |
"no-import-assign": "error", | |
"no-inner-declarations": "error", | |
"no-invalid-regexp": "error", | |
"no-irregular-whitespace": "error", | |
"no-loss-of-precision": "error", | |
"no-misleading-character-class": "error", | |
"no-obj-calls": "error", | |
"no-promise-executor-return": "error", | |
"no-prototype-builtins": "error", | |
"no-regex-spaces": "error", | |
"no-setter-return": "error", | |
"no-sparse-arrays": "error", | |
"no-template-curly-in-string": "error", | |
"no-unexpected-multiline": "error", | |
"no-unreachable": "error", | |
"no-unreachable-loop": [ | |
"error", | |
{ | |
ignore: [ | |
], | |
}, | |
], | |
"no-unsafe-finally": "error", | |
"no-unsafe-negation": "error", | |
"no-unsafe-optional-chaining": [ | |
"error", | |
{ | |
disallowArithmeticOperators: true, | |
}, | |
], | |
"no-unused-private-class-members": "off", | |
"no-useless-backreference": "error", | |
"no-negated-in-lhs": "off", | |
"require-atomic-updates": "off", | |
"use-isnan": "error", | |
"valid-jsdoc": "off", | |
"valid-typeof": [ | |
"error", | |
{ | |
requireStringLiterals: true, | |
}, | |
], | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\node.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\node.js", | |
criteria: null, | |
env: { | |
node: true, | |
}, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"callback-return": "off", | |
"global-require": "error", | |
"handle-callback-err": "off", | |
"no-buffer-constructor": "error", | |
"no-mixed-requires": [ | |
"off", | |
false, | |
], | |
"no-new-require": "error", | |
"no-path-concat": "error", | |
"no-process-env": "off", | |
"no-process-exit": "off", | |
"no-restricted-modules": "off", | |
"no-sync": "off", | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\style.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\style.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"array-bracket-newline": [ | |
"off", | |
"consistent", | |
], | |
"array-element-newline": [ | |
"off", | |
{ | |
multiline: true, | |
minItems: 3, | |
}, | |
], | |
"array-bracket-spacing": [ | |
"error", | |
"never", | |
], | |
"block-spacing": [ | |
"error", | |
"always", | |
], | |
"brace-style": [ | |
"error", | |
"1tbs", | |
{ | |
allowSingleLine: true, | |
}, | |
], | |
camelcase: [ | |
"error", | |
{ | |
properties: "never", | |
ignoreDestructuring: false, | |
}, | |
], | |
"capitalized-comments": [ | |
"off", | |
"never", | |
{ | |
line: { | |
ignorePattern: ".*", | |
ignoreInlineComments: true, | |
ignoreConsecutiveComments: true, | |
}, | |
block: { | |
ignorePattern: ".*", | |
ignoreInlineComments: true, | |
ignoreConsecutiveComments: true, | |
}, | |
}, | |
], | |
"comma-dangle": [ | |
"error", | |
{ | |
arrays: "always-multiline", | |
objects: "always-multiline", | |
imports: "always-multiline", | |
exports: "always-multiline", | |
functions: "always-multiline", | |
}, | |
], | |
"comma-spacing": [ | |
"error", | |
{ | |
before: false, | |
after: true, | |
}, | |
], | |
"comma-style": [ | |
"error", | |
"last", | |
{ | |
exceptions: { | |
ArrayExpression: false, | |
ArrayPattern: false, | |
ArrowFunctionExpression: false, | |
CallExpression: false, | |
FunctionDeclaration: false, | |
FunctionExpression: false, | |
ImportDeclaration: false, | |
ObjectExpression: false, | |
ObjectPattern: false, | |
VariableDeclaration: false, | |
NewExpression: false, | |
}, | |
}, | |
], | |
"computed-property-spacing": [ | |
"error", | |
"never", | |
], | |
"consistent-this": "off", | |
"eol-last": [ | |
"error", | |
"always", | |
], | |
"function-call-argument-newline": [ | |
"error", | |
"consistent", | |
], | |
"func-call-spacing": [ | |
"error", | |
"never", | |
], | |
"func-name-matching": [ | |
"off", | |
"always", | |
{ | |
includeCommonJSModuleExports: false, | |
considerPropertyDescriptor: true, | |
}, | |
], | |
"func-names": "warn", | |
"func-style": [ | |
"off", | |
"expression", | |
], | |
"function-paren-newline": [ | |
"error", | |
"multiline-arguments", | |
], | |
"id-denylist": "off", | |
"id-length": "off", | |
"id-match": "off", | |
"implicit-arrow-linebreak": [ | |
"error", | |
"beside", | |
], | |
indent: [ | |
"error", | |
2, | |
{ | |
SwitchCase: 1, | |
VariableDeclarator: 1, | |
outerIIFEBody: 1, | |
FunctionDeclaration: { | |
parameters: 1, | |
body: 1, | |
}, | |
FunctionExpression: { | |
parameters: 1, | |
body: 1, | |
}, | |
CallExpression: { | |
arguments: 1, | |
}, | |
ArrayExpression: 1, | |
ObjectExpression: 1, | |
ImportDeclaration: 1, | |
flatTernaryExpressions: false, | |
ignoredNodes: [ | |
"JSXElement", | |
"JSXElement > *", | |
"JSXAttribute", | |
"JSXIdentifier", | |
"JSXNamespacedName", | |
"JSXMemberExpression", | |
"JSXSpreadAttribute", | |
"JSXExpressionContainer", | |
"JSXOpeningElement", | |
"JSXClosingElement", | |
"JSXFragment", | |
"JSXOpeningFragment", | |
"JSXClosingFragment", | |
"JSXText", | |
"JSXEmptyExpression", | |
"JSXSpreadChild", | |
], | |
ignoreComments: false, | |
}, | |
], | |
"jsx-quotes": [ | |
"off", | |
"prefer-double", | |
], | |
"key-spacing": [ | |
"error", | |
{ | |
beforeColon: false, | |
afterColon: true, | |
}, | |
], | |
"keyword-spacing": [ | |
"error", | |
{ | |
before: true, | |
after: true, | |
overrides: { | |
return: { | |
after: true, | |
}, | |
throw: { | |
after: true, | |
}, | |
case: { | |
after: true, | |
}, | |
}, | |
}, | |
], | |
"line-comment-position": [ | |
"off", | |
{ | |
position: "above", | |
ignorePattern: "", | |
applyDefaultPatterns: true, | |
}, | |
], | |
"linebreak-style": [ | |
"error", | |
"unix", | |
], | |
"lines-between-class-members": [ | |
"error", | |
"always", | |
{ | |
exceptAfterSingleLine: false, | |
}, | |
], | |
"lines-around-comment": "off", | |
"lines-around-directive": [ | |
"error", | |
{ | |
before: "always", | |
after: "always", | |
}, | |
], | |
"max-depth": [ | |
"off", | |
4, | |
], | |
"max-len": [ | |
"error", | |
100, | |
2, | |
{ | |
ignoreUrls: true, | |
ignoreComments: false, | |
ignoreRegExpLiterals: true, | |
ignoreStrings: true, | |
ignoreTemplateLiterals: true, | |
}, | |
], | |
"max-lines": [ | |
"off", | |
{ | |
max: 300, | |
skipBlankLines: true, | |
skipComments: true, | |
}, | |
], | |
"max-lines-per-function": [ | |
"off", | |
{ | |
max: 50, | |
skipBlankLines: true, | |
skipComments: true, | |
IIFEs: true, | |
}, | |
], | |
"max-nested-callbacks": "off", | |
"max-params": [ | |
"off", | |
3, | |
], | |
"max-statements": [ | |
"off", | |
10, | |
], | |
"max-statements-per-line": [ | |
"off", | |
{ | |
max: 1, | |
}, | |
], | |
"multiline-comment-style": [ | |
"off", | |
"starred-block", | |
], | |
"multiline-ternary": [ | |
"off", | |
"never", | |
], | |
"new-cap": [ | |
"error", | |
{ | |
newIsCap: true, | |
newIsCapExceptions: [ | |
], | |
capIsNew: false, | |
capIsNewExceptions: [ | |
"Immutable.Map", | |
"Immutable.Set", | |
"Immutable.List", | |
], | |
}, | |
], | |
"new-parens": "error", | |
"newline-after-var": "off", | |
"newline-before-return": "off", | |
"newline-per-chained-call": [ | |
"error", | |
{ | |
ignoreChainWithDepth: 4, | |
}, | |
], | |
"no-array-constructor": "error", | |
"no-bitwise": "error", | |
"no-continue": "error", | |
"no-inline-comments": "off", | |
"no-lonely-if": "error", | |
"no-mixed-operators": [ | |
"error", | |
{ | |
groups: [ | |
[ | |
"%", | |
"**", | |
], | |
[ | |
"%", | |
"+", | |
], | |
[ | |
"%", | |
"-", | |
], | |
[ | |
"%", | |
"*", | |
], | |
[ | |
"%", | |
"/", | |
], | |
[ | |
"/", | |
"*", | |
], | |
[ | |
"&", | |
"|", | |
"<<", | |
">>", | |
">>>", | |
], | |
[ | |
"==", | |
"!=", | |
"===", | |
"!==", | |
], | |
[ | |
"&&", | |
"||", | |
], | |
], | |
allowSamePrecedence: false, | |
}, | |
], | |
"no-mixed-spaces-and-tabs": "error", | |
"no-multi-assign": [ | |
"error", | |
], | |
"no-multiple-empty-lines": [ | |
"error", | |
{ | |
max: 1, | |
maxBOF: 0, | |
maxEOF: 0, | |
}, | |
], | |
"no-negated-condition": "off", | |
"no-nested-ternary": "error", | |
"no-new-object": "error", | |
"no-plusplus": "error", | |
"no-restricted-syntax": [ | |
"error", | |
{ | |
selector: "ForInStatement", | |
message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.", | |
}, | |
{ | |
selector: "ForOfStatement", | |
message: "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.", | |
}, | |
{ | |
selector: "LabeledStatement", | |
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.", | |
}, | |
{ | |
selector: "WithStatement", | |
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.", | |
}, | |
], | |
"no-spaced-func": "error", | |
"no-tabs": "error", | |
"no-ternary": "off", | |
"no-trailing-spaces": [ | |
"error", | |
{ | |
skipBlankLines: false, | |
ignoreComments: false, | |
}, | |
], | |
"no-underscore-dangle": [ | |
"error", | |
{ | |
allow: [ | |
], | |
allowAfterThis: false, | |
allowAfterSuper: false, | |
enforceInMethodNames: true, | |
}, | |
], | |
"no-unneeded-ternary": [ | |
"error", | |
{ | |
defaultAssignment: false, | |
}, | |
], | |
"no-whitespace-before-property": "error", | |
"nonblock-statement-body-position": [ | |
"error", | |
"beside", | |
{ | |
overrides: { | |
}, | |
}, | |
], | |
"object-curly-spacing": [ | |
"error", | |
"always", | |
], | |
"object-curly-newline": [ | |
"error", | |
{ | |
ObjectExpression: { | |
minProperties: 4, | |
multiline: true, | |
consistent: true, | |
}, | |
ObjectPattern: { | |
minProperties: 4, | |
multiline: true, | |
consistent: true, | |
}, | |
ImportDeclaration: { | |
minProperties: 4, | |
multiline: true, | |
consistent: true, | |
}, | |
ExportDeclaration: { | |
minProperties: 4, | |
multiline: true, | |
consistent: true, | |
}, | |
}, | |
], | |
"object-property-newline": [ | |
"error", | |
{ | |
allowAllPropertiesOnSameLine: true, | |
}, | |
], | |
"one-var": [ | |
"error", | |
"never", | |
], | |
"one-var-declaration-per-line": [ | |
"error", | |
"always", | |
], | |
"operator-assignment": [ | |
"error", | |
"always", | |
], | |
"operator-linebreak": [ | |
"error", | |
"before", | |
{ | |
overrides: { | |
"=": "none", | |
}, | |
}, | |
], | |
"padded-blocks": [ | |
"error", | |
{ | |
blocks: "never", | |
classes: "never", | |
switches: "never", | |
}, | |
{ | |
allowSingleLineBlocks: true, | |
}, | |
], | |
"padding-line-between-statements": "off", | |
"prefer-exponentiation-operator": "error", | |
"prefer-object-spread": "error", | |
"quote-props": [ | |
"error", | |
"as-needed", | |
{ | |
keywords: false, | |
unnecessary: true, | |
numbers: false, | |
}, | |
], | |
quotes: [ | |
"error", | |
"single", | |
{ | |
avoidEscape: true, | |
}, | |
], | |
"require-jsdoc": "off", | |
semi: [ | |
"error", | |
"always", | |
], | |
"semi-spacing": [ | |
"error", | |
{ | |
before: false, | |
after: true, | |
}, | |
], | |
"semi-style": [ | |
"error", | |
"last", | |
], | |
"sort-keys": [ | |
"off", | |
"asc", | |
{ | |
caseSensitive: false, | |
natural: true, | |
}, | |
], | |
"sort-vars": "off", | |
"space-before-blocks": "error", | |
"space-before-function-paren": [ | |
"error", | |
{ | |
anonymous: "always", | |
named: "never", | |
asyncArrow: "always", | |
}, | |
], | |
"space-in-parens": [ | |
"error", | |
"never", | |
], | |
"space-infix-ops": "error", | |
"space-unary-ops": [ | |
"error", | |
{ | |
words: true, | |
nonwords: false, | |
overrides: { | |
}, | |
}, | |
], | |
"spaced-comment": [ | |
"error", | |
"always", | |
{ | |
line: { | |
exceptions: [ | |
"-", | |
"+", | |
], | |
markers: [ | |
"=", | |
"!", | |
"/", | |
], | |
}, | |
block: { | |
exceptions: [ | |
"-", | |
"+", | |
], | |
markers: [ | |
"=", | |
"!", | |
":", | |
"::", | |
], | |
balanced: true, | |
}, | |
}, | |
], | |
"switch-colon-spacing": [ | |
"error", | |
{ | |
after: true, | |
before: false, | |
}, | |
], | |
"template-tag-spacing": [ | |
"error", | |
"never", | |
], | |
"unicode-bom": [ | |
"error", | |
"never", | |
], | |
"wrap-regex": "off", | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\variables.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\variables.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"init-declarations": "off", | |
"no-catch-shadow": "off", | |
"no-delete-var": "error", | |
"no-label-var": "error", | |
"no-restricted-globals": [ | |
"error", | |
{ | |
name: "isFinite", | |
message: "Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite", | |
}, | |
{ | |
name: "isNaN", | |
message: "Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan", | |
}, | |
"addEventListener", | |
"blur", | |
"close", | |
"closed", | |
"confirm", | |
"defaultStatus", | |
"defaultstatus", | |
"event", | |
"external", | |
"find", | |
"focus", | |
"frameElement", | |
"frames", | |
"history", | |
"innerHeight", | |
"innerWidth", | |
"length", | |
"location", | |
"locationbar", | |
"menubar", | |
"moveBy", | |
"moveTo", | |
"name", | |
"onblur", | |
"onerror", | |
"onfocus", | |
"onload", | |
"onresize", | |
"onunload", | |
"open", | |
"opener", | |
"opera", | |
"outerHeight", | |
"outerWidth", | |
"pageXOffset", | |
"pageYOffset", | |
"parent", | |
"print", | |
"removeEventListener", | |
"resizeBy", | |
"resizeTo", | |
"screen", | |
"screenLeft", | |
"screenTop", | |
"screenX", | |
"screenY", | |
"scroll", | |
"scrollbars", | |
"scrollBy", | |
"scrollTo", | |
"scrollX", | |
"scrollY", | |
"self", | |
"status", | |
"statusbar", | |
"stop", | |
"toolbar", | |
"top", | |
], | |
"no-shadow": "error", | |
"no-shadow-restricted-names": "error", | |
"no-undef": "error", | |
"no-undef-init": "error", | |
"no-undefined": "off", | |
"no-unused-vars": [ | |
"error", | |
{ | |
vars: "all", | |
args: "after-used", | |
ignoreRestSiblings: true, | |
}, | |
], | |
"no-use-before-define": [ | |
"error", | |
{ | |
functions: true, | |
classes: true, | |
variables: true, | |
}, | |
], | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\es6.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\es6.js", | |
criteria: null, | |
env: { | |
es6: true, | |
}, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: { | |
ecmaVersion: 6, | |
sourceType: "module", | |
ecmaFeatures: { | |
generators: false, | |
objectLiteralDuplicateProperties: false, | |
}, | |
}, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"arrow-body-style": [ | |
"error", | |
"as-needed", | |
{ | |
requireReturnForObjectLiteral: false, | |
}, | |
], | |
"arrow-parens": [ | |
"error", | |
"always", | |
], | |
"arrow-spacing": [ | |
"error", | |
{ | |
before: true, | |
after: true, | |
}, | |
], | |
"constructor-super": "error", | |
"generator-star-spacing": [ | |
"error", | |
{ | |
before: false, | |
after: true, | |
}, | |
], | |
"no-class-assign": "error", | |
"no-confusing-arrow": [ | |
"error", | |
{ | |
allowParens: true, | |
}, | |
], | |
"no-const-assign": "error", | |
"no-dupe-class-members": "error", | |
"no-duplicate-imports": "off", | |
"no-new-symbol": "error", | |
"no-restricted-exports": [ | |
"error", | |
{ | |
restrictedNamedExports: [ | |
"default", | |
"then", | |
], | |
}, | |
], | |
"no-restricted-imports": [ | |
"off", | |
{ | |
paths: [ | |
], | |
patterns: [ | |
], | |
}, | |
], | |
"no-this-before-super": "error", | |
"no-useless-computed-key": "error", | |
"no-useless-constructor": "error", | |
"no-useless-rename": [ | |
"error", | |
{ | |
ignoreDestructuring: false, | |
ignoreImport: false, | |
ignoreExport: false, | |
}, | |
], | |
"no-var": "error", | |
"object-shorthand": [ | |
"error", | |
"always", | |
{ | |
ignoreConstructors: false, | |
avoidQuotes: true, | |
}, | |
], | |
"prefer-arrow-callback": [ | |
"error", | |
{ | |
allowNamedFunctions: false, | |
allowUnboundThis: true, | |
}, | |
], | |
"prefer-const": [ | |
"error", | |
{ | |
destructuring: "any", | |
ignoreReadBeforeAssign: true, | |
}, | |
], | |
"prefer-destructuring": [ | |
"error", | |
{ | |
VariableDeclarator: { | |
array: false, | |
object: true, | |
}, | |
AssignmentExpression: { | |
array: true, | |
object: false, | |
}, | |
}, | |
{ | |
enforceForRenamedProperties: false, | |
}, | |
], | |
"prefer-numeric-literals": "error", | |
"prefer-reflect": "off", | |
"prefer-rest-params": "error", | |
"prefer-spread": "error", | |
"prefer-template": "error", | |
"require-yield": "error", | |
"rest-spread-spacing": [ | |
"error", | |
"never", | |
], | |
"sort-imports": [ | |
"off", | |
{ | |
ignoreCase: false, | |
ignoreDeclarationSort: false, | |
ignoreMemberSort: false, | |
memberSyntaxSortOrder: [ | |
"none", | |
"all", | |
"multiple", | |
"single", | |
], | |
}, | |
], | |
"symbol-description": "error", | |
"template-curly-spacing": "error", | |
"yield-star-spacing": [ | |
"error", | |
"after", | |
], | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\imports.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\imports.js", | |
criteria: null, | |
env: { | |
es6: true, | |
}, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: { | |
ecmaVersion: 6, | |
sourceType: "module", | |
}, | |
plugins: { | |
import: { | |
definition: { | |
configs: { | |
recommended: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-unresolved": "error", | |
"import/named": "error", | |
"import/namespace": "error", | |
"import/default": "error", | |
"import/export": "error", | |
"import/no-named-as-default": "warn", | |
"import/no-named-as-default-member": "warn", | |
"import/no-duplicates": "warn", | |
}, | |
parserOptions: { | |
sourceType: "module", | |
ecmaVersion: 2018, | |
}, | |
}, | |
errors: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-unresolved": 2, | |
"import/named": 2, | |
"import/namespace": 2, | |
"import/default": 2, | |
"import/export": 2, | |
}, | |
}, | |
warnings: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-named-as-default": 1, | |
"import/no-named-as-default-member": 1, | |
"import/no-duplicates": 1, | |
}, | |
}, | |
"stage-0": { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-deprecated": 1, | |
}, | |
}, | |
react: { | |
settings: { | |
"import/extensions": [ | |
".js", | |
".jsx", | |
], | |
}, | |
parserOptions: { | |
ecmaFeatures: { | |
jsx: true, | |
}, | |
}, | |
}, | |
"react-native": { | |
settings: { | |
"import/resolver": { | |
node: { | |
extensions: [ | |
".js", | |
".web.js", | |
".ios.js", | |
".android.js", | |
], | |
}, | |
}, | |
}, | |
}, | |
electron: { | |
settings: { | |
"import/core-modules": [ | |
"electron", | |
], | |
}, | |
}, | |
typescript: { | |
settings: { | |
"import/extensions": [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
".js", | |
".jsx", | |
], | |
"import/external-module-folders": [ | |
"node_modules", | |
"node_modules/@types", | |
], | |
"import/parsers": { | |
"@typescript-eslint/parser": [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
], | |
}, | |
"import/resolver": { | |
node: { | |
extensions: [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
".js", | |
".jsx", | |
], | |
}, | |
}, | |
}, | |
rules: { | |
"import/named": "off", | |
}, | |
}, | |
}, | |
environments: { | |
}, | |
processors: { | |
}, | |
rules: { | |
"no-unresolved": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure imports point to a file/module that can be resolved.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unresolved.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
caseSensitive: { | |
type: "boolean", | |
default: true, | |
}, | |
caseSensitiveStrict: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
function checkSourceValue(source, node) { | |
// ignore type-only imports and exports | |
if (node.importKind === 'type' || node.exportKind === 'type') { | |
return; | |
} | |
var caseSensitive = !_resolve.CASE_SENSITIVE_FS && options.caseSensitive !== false; | |
var caseSensitiveStrict = !_resolve.CASE_SENSITIVE_FS && options.caseSensitiveStrict; | |
var resolvedPath = (0, _resolve2['default'])(source.value, context); | |
if (resolvedPath === undefined) { | |
context.report( | |
source, 'Unable to resolve path to module \'' + String( | |
source.value) + '\'.'); | |
} else if (caseSensitive || caseSensitiveStrict) { | |
var cacheSettings = _ModuleCache2['default'].getSettings(context.settings); | |
if (!(0, _resolve.fileExistsWithCaseSync)(resolvedPath, cacheSettings, caseSensitiveStrict)) { | |
context.report( | |
source, 'Casing of ' + String( | |
source.value) + ' does not match the underlying filesystem.'); | |
} | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, options); | |
}, | |
}, | |
named: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure named imports correspond to a named export in the remote file.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/named.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
function checkSpecifiers(key, type, node) { | |
// ignore local exports and type imports/exports | |
if ( | |
node.source == null || | |
node.importKind === 'type' || | |
node.importKind === 'typeof' || | |
node.exportKind === 'type') | |
{ | |
return; | |
} | |
if (!node.specifiers.some(function (im) {return im.type === type;})) { | |
return; // no named imports/exports | |
} | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null || imports.parseGoal === 'ambiguous') { | |
return; | |
} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
return; | |
} | |
node.specifiers.forEach(function (im) { | |
if ( | |
im.type !== type | |
// ignore type imports | |
|| im.importKind === 'type' || im.importKind === 'typeof') | |
{ | |
return; | |
} | |
var name = im[key].name || im[key].value; | |
var deepLookup = imports.hasDeep(name); | |
if (!deepLookup.found) { | |
if (deepLookup.path.length > 1) { | |
var deepPath = deepLookup.path. | |
map(function (i) {return path.relative(path.dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()), i.path);}). | |
join(' -> '); | |
context.report(im[key], String(name) + ' not found via ' + String(deepPath)); | |
} else { | |
context.report(im[key], String(name) + ' not found in \'' + String(node.source.value) + '\''); | |
} | |
} | |
}); | |
} | |
function checkRequire(node) { | |
if ( | |
!options.commonjs || | |
node.type !== 'VariableDeclarator' | |
// return if it's not an object destructure or it's an empty object destructure | |
|| !node.id || node.id.type !== 'ObjectPattern' || node.id.properties.length === 0 | |
// return if there is no call expression on the right side | |
|| !node.init || node.init.type !== 'CallExpression') | |
{ | |
return; | |
} | |
var call = node.init;var _call$arguments = _slicedToArray( | |
call.arguments, 1),source = _call$arguments[0]; | |
var variableImports = node.id.properties; | |
var variableExports = _ExportMap2['default'].get(source.value, context); | |
if ( | |
// return if it's not a commonjs require statement | |
call.callee.type !== 'Identifier' || call.callee.name !== 'require' || call.arguments.length !== 1 | |
// return if it's not a string source | |
|| source.type !== 'Literal' || | |
variableExports == null || | |
variableExports.parseGoal === 'ambiguous') | |
{ | |
return; | |
} | |
if (variableExports.errors.length) { | |
variableExports.reportErrors(context, node); | |
return; | |
} | |
variableImports.forEach(function (im) { | |
if (im.type !== 'Property' || !im.key || im.key.type !== 'Identifier') { | |
return; | |
} | |
var deepLookup = variableExports.hasDeep(im.key.name); | |
if (!deepLookup.found) { | |
if (deepLookup.path.length > 1) { | |
var deepPath = deepLookup.path. | |
map(function (i) {return path.relative(path.dirname(context.getFilename()), i.path);}). | |
join(' -> '); | |
context.report(im.key, String(im.key.name) + ' not found via ' + String(deepPath)); | |
} else { | |
context.report(im.key, String(im.key.name) + ' not found in \'' + String(source.value) + '\''); | |
} | |
} | |
}); | |
} | |
return { | |
ImportDeclaration: checkSpecifiers.bind(null, 'imported', 'ImportSpecifier'), | |
ExportNamedDeclaration: checkSpecifiers.bind(null, 'local', 'ExportSpecifier'), | |
VariableDeclarator: checkRequire }; | |
}, | |
}, | |
default: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure a default export is present, given a default import.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDefault(specifierType, node) { | |
var defaultSpecifier = node.specifiers.find( | |
function (specifier) {return specifier.type === specifierType;}); | |
if (!defaultSpecifier) {return;} | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null) {return;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
} else if (imports.get('default') === undefined) { | |
context.report({ | |
node: defaultSpecifier, | |
message: 'No default export found in imported module "' + String(node.source.value) + '".' }); | |
} | |
} | |
return { | |
ImportDeclaration: checkDefault.bind(null, 'ImportDefaultSpecifier'), | |
ExportNamedDeclaration: checkDefault.bind(null, 'ExportDefaultSpecifier') }; | |
}, | |
}, | |
namespace: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure imported namespaces contain dereferenced properties as they are dereferenced.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/namespace.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowComputed: { | |
description: "If `false`, will report computed (and thus, un-lintable) references to namespace members.", | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function namespaceRule(context) { | |
// read options | |
var _ref = | |
context.options[0] || {},_ref$allowComputed = _ref.allowComputed,allowComputed = _ref$allowComputed === undefined ? false : _ref$allowComputed; | |
var namespaces = new Map(); | |
function makeMessage(last, namepath) { | |
return '\'' + String(last.name) + '\' not found in ' + (namepath.length > 1 ? 'deeply ' : '') + 'imported namespace \'' + String(namepath.join('.')) + '\'.'; | |
} | |
return { | |
// pick up all imports at body entry time, to properly respect hoisting | |
Program: function () {function Program(_ref2) {var body = _ref2.body; | |
body.forEach(function (x) {processBodyStatement(context, namespaces, x);}); | |
}return Program;}(), | |
// same as above, but does not add names to local map | |
ExportNamespaceSpecifier: function () {function ExportNamespaceSpecifier(namespace) { | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var imports = _ExportMap2['default'].get(declaration.source.value, context); | |
if (imports == null) {return null;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, declaration); | |
return; | |
} | |
if (!imports.size) { | |
context.report( | |
namespace, 'No exported names found in module \'' + String( | |
declaration.source.value) + '\'.'); | |
} | |
}return ExportNamespaceSpecifier;}(), | |
// todo: check for possible redefinition | |
MemberExpression: function () {function MemberExpression(dereference) { | |
if (dereference.object.type !== 'Identifier') {return;} | |
if (!namespaces.has(dereference.object.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') {return;} | |
if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) { | |
context.report( | |
dereference.parent, 'Assignment to member of namespace \'' + String( | |
dereference.object.name) + '\'.'); | |
} | |
// go deep | |
var namespace = namespaces.get(dereference.object.name); | |
var namepath = [dereference.object.name]; | |
// while property is namespace and parent is member expression, keep validating | |
while (namespace instanceof _ExportMap2['default'] && dereference.type === 'MemberExpression') { | |
if (dereference.computed) { | |
if (!allowComputed) { | |
context.report( | |
dereference.property, 'Unable to validate computed reference to imported namespace \'' + String( | |
dereference.object.name) + '\'.'); | |
} | |
return; | |
} | |
if (!namespace.has(dereference.property.name)) { | |
context.report( | |
dereference.property, | |
makeMessage(dereference.property, namepath)); | |
break; | |
} | |
var exported = namespace.get(dereference.property.name); | |
if (exported == null) {return;} | |
// stash and pop | |
namepath.push(dereference.property.name); | |
namespace = exported.namespace; | |
dereference = dereference.parent; | |
} | |
}return MemberExpression;}(), | |
VariableDeclarator: function () {function VariableDeclarator(_ref3) {var id = _ref3.id,init = _ref3.init; | |
if (init == null) {return;} | |
if (init.type !== 'Identifier') {return;} | |
if (!namespaces.has(init.name)) {return;} | |
// check for redefinition in intermediate scopes | |
if ((0, _declaredScope2['default'])(context, init.name) !== 'module') {return;} | |
// DFS traverse child namespaces | |
function testKey(pattern, namespace) {var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [init.name]; | |
if (!(namespace instanceof _ExportMap2['default'])) {return;} | |
if (pattern.type !== 'ObjectPattern') {return;}var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = pattern.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var property = _step.value; | |
if ( | |
property.type === 'ExperimentalRestProperty' || | |
property.type === 'RestElement' || | |
!property.key) | |
{ | |
continue; | |
} | |
if (property.key.type !== 'Identifier') { | |
context.report({ | |
node: property, | |
message: 'Only destructure top-level names.' }); | |
continue; | |
} | |
if (!namespace.has(property.key.name)) { | |
context.report({ | |
node: property, | |
message: makeMessage(property.key, path) }); | |
continue; | |
} | |
path.push(property.key.name); | |
var dependencyExportMap = namespace.get(property.key.name); | |
// could be null when ignored or ambiguous | |
if (dependencyExportMap !== null) { | |
testKey(property.value, dependencyExportMap.namespace, path); | |
} | |
path.pop(); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
testKey(id, namespaces.get(init.name)); | |
}return VariableDeclarator;}(), | |
JSXMemberExpression: function () {function JSXMemberExpression(_ref4) {var object = _ref4.object,property = _ref4.property; | |
if (!namespaces.has(object.name)) {return;} | |
var namespace = namespaces.get(object.name); | |
if (!namespace.has(property.name)) { | |
context.report({ | |
node: property, | |
message: makeMessage(property, [object.name]) }); | |
} | |
}return JSXMemberExpression;}() }; | |
}, | |
}, | |
"no-namespace": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid namespace (a.k.a. \"wildcard\" `*`) imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-namespace.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignore: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var firstOption = context.options[0] || {}; | |
var ignoreGlobs = firstOption.ignore; | |
return { | |
ImportNamespaceSpecifier: function () {function ImportNamespaceSpecifier(node) { | |
if (ignoreGlobs && ignoreGlobs.find(function (glob) {return (0, _minimatch2['default'])(node.parent.source.value, glob, { matchBase: true });})) { | |
return; | |
} | |
var scopeVariables = context.getScope().variables; | |
var namespaceVariable = scopeVariables.find(function (variable) {return variable.defs[0].node === node;}); | |
var namespaceReferences = namespaceVariable.references; | |
var namespaceIdentifiers = namespaceReferences.map(function (reference) {return reference.identifier;}); | |
var canFix = namespaceIdentifiers.length > 0 && !usesNamespaceAsObject(namespaceIdentifiers); | |
context.report({ | |
node: node, | |
message: 'Unexpected namespace import.', | |
fix: canFix && function (fixer) { | |
var scopeManager = context.getSourceCode().scopeManager; | |
var fixes = []; | |
// Pass 1: Collect variable names that are already in scope for each reference we want | |
// to transform, so that we can be sure that we choose non-conflicting import names | |
var importNameConflicts = {}; | |
namespaceIdentifiers.forEach(function (identifier) { | |
var parent = identifier.parent; | |
if (parent && parent.type === 'MemberExpression') { | |
var importName = getMemberPropertyName(parent); | |
var localConflicts = getVariableNamesInScope(scopeManager, parent); | |
if (!importNameConflicts[importName]) { | |
importNameConflicts[importName] = localConflicts; | |
} else { | |
localConflicts.forEach(function (c) {return importNameConflicts[importName].add(c);}); | |
} | |
} | |
}); | |
// Choose new names for each import | |
var importNames = Object.keys(importNameConflicts); | |
var importLocalNames = generateLocalNames( | |
importNames, | |
importNameConflicts, | |
namespaceVariable.name); | |
// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers | |
var namedImportSpecifiers = importNames.map(function (importName) {return importName === importLocalNames[importName] ? | |
importName : String( | |
importName) + ' as ' + String(importLocalNames[importName]);}); | |
fixes.push(fixer.replaceText(node, '{ ' + String(namedImportSpecifiers.join(', ')) + ' }')); | |
// Pass 2: Replace references to the namespace with references to the named imports | |
namespaceIdentifiers.forEach(function (identifier) { | |
var parent = identifier.parent; | |
if (parent && parent.type === 'MemberExpression') { | |
var importName = getMemberPropertyName(parent); | |
fixes.push(fixer.replaceText(parent, importLocalNames[importName])); | |
} | |
}); | |
return fixes; | |
} }); | |
}return ImportNamespaceSpecifier;}() }; | |
}, | |
}, | |
export: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid any invalid exports, i.e. re-export of the same name.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var namespace = new Map([[rootProgram, new Map()]]); | |
function addNamed(name, node, parent, isType) { | |
if (!namespace.has(parent)) { | |
namespace.set(parent, new Map()); | |
} | |
var named = namespace.get(parent); | |
var key = isType ? '' + tsTypePrefix + String(name) : name; | |
var nodes = named.get(key); | |
if (nodes == null) { | |
nodes = new Set(); | |
named.set(key, nodes); | |
} | |
nodes.add(node); | |
} | |
function getParent(node) { | |
if (node.parent && node.parent.type === 'TSModuleBlock') { | |
return node.parent.parent; | |
} | |
// just in case somehow a non-ts namespace export declaration isn't directly | |
// parented to the root Program node | |
return rootProgram; | |
} | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
addNamed('default', node, getParent(node)); | |
}return ExportDefaultDeclaration;}(), | |
ExportSpecifier: function () {function ExportSpecifier(node) { | |
addNamed( | |
node.exported.name || node.exported.value, | |
node.exported, | |
getParent(node.parent)); | |
}return ExportSpecifier;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
if (node.declaration == null) {return;} | |
var parent = getParent(node); | |
// support for old TypeScript versions | |
var isTypeVariableDecl = node.declaration.kind === 'type'; | |
if (node.declaration.id != null) { | |
if ((0, _arrayIncludes2['default'])([ | |
'TSTypeAliasDeclaration', | |
'TSInterfaceDeclaration'], | |
node.declaration.type)) { | |
addNamed(node.declaration.id.name, node.declaration.id, parent, true); | |
} else { | |
addNamed(node.declaration.id.name, node.declaration.id, parent, isTypeVariableDecl); | |
} | |
} | |
if (node.declaration.declarations != null) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = node.declaration.declarations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var declaration = _step.value; | |
(0, _ExportMap.recursivePatternCapture)(declaration.id, function (v) {addNamed(v.name, v, parent, isTypeVariableDecl);}); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
}return ExportNamedDeclaration;}(), | |
ExportAllDeclaration: function () {function ExportAllDeclaration(node) { | |
if (node.source == null) {return;} // not sure if this is ever true | |
// `export * as X from 'path'` does not conflict | |
if (node.exported && node.exported.name) {return;} | |
var remoteExports = _ExportMap2['default'].get(node.source.value, context); | |
if (remoteExports == null) {return;} | |
if (remoteExports.errors.length) { | |
remoteExports.reportErrors(context, node); | |
return; | |
} | |
var parent = getParent(node); | |
var any = false; | |
remoteExports.forEach(function (v, name) { | |
if (name !== 'default') { | |
any = true; // poor man's filter | |
addNamed(name, node, parent); | |
} | |
}); | |
if (!any) { | |
context.report( | |
node.source, 'No named exports found in module \'' + String( | |
node.source.value) + '\'.'); | |
} | |
}return ExportAllDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = namespace[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref = _step2.value;var _ref2 = _slicedToArray(_ref, 2);var named = _ref2[1];var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try { | |
for (var _iterator3 = named[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var _ref3 = _step3.value;var _ref4 = _slicedToArray(_ref3, 2);var name = _ref4[0];var nodes = _ref4[1]; | |
if (nodes.size <= 1) {continue;} | |
if (isTypescriptFunctionOverloads(nodes) || isTypescriptNamespaceMerging(nodes)) {continue;}var _iteratorNormalCompletion4 = true;var _didIteratorError4 = false;var _iteratorError4 = undefined;try { | |
for (var _iterator4 = nodes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {var node = _step4.value; | |
if (shouldSkipTypescriptNamespace(node, nodes)) {continue;} | |
if (name === 'default') { | |
context.report(node, 'Multiple default exports.'); | |
} else { | |
context.report( | |
node, 'Multiple exports of name \'' + String( | |
name.replace(tsTypePrefix, '')) + '\'.'); | |
} | |
}} catch (err) {_didIteratorError4 = true;_iteratorError4 = err;} finally {try {if (!_iteratorNormalCompletion4 && _iterator4['return']) {_iterator4['return']();}} finally {if (_didIteratorError4) {throw _iteratorError4;}}} | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-mutable-exports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid the use of mutable exports with `var` or `let`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-mutable-exports.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDeclaration(node) {var | |
kind = node.kind; | |
if (kind === 'var' || kind === 'let') { | |
context.report(node, 'Exporting mutable \'' + String(kind) + '\' binding, use \'const\' instead.'); | |
} | |
} | |
function checkDeclarationsInScope(_ref, name) {var variables = _ref.variables;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = variables[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (variable.name === name) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = variable.defs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var def = _step2.value; | |
if (def.type === 'Variable' && def.parent) { | |
checkDeclaration(def.parent); | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
function handleExportDefault(node) { | |
var scope = context.getScope(); | |
if (node.declaration.name) { | |
checkDeclarationsInScope(scope, node.declaration.name); | |
} | |
} | |
function handleExportNamed(node) { | |
var scope = context.getScope(); | |
if (node.declaration) { | |
checkDeclaration(node.declaration); | |
} else if (!node.source) {var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try { | |
for (var _iterator3 = node.specifiers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var specifier = _step3.value; | |
checkDeclarationsInScope(scope, specifier.local.name); | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
} | |
} | |
return { | |
ExportDefaultDeclaration: handleExportDefault, | |
ExportNamedDeclaration: handleExportNamed }; | |
}, | |
}, | |
extensions: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure consistent use of file extension within the import path.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/extensions.md", | |
}, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
pattern: { | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
ignorePackages: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
properties: { | |
pattern: { | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
ignorePackages: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
create: function create(context) { | |
var props = buildProperties(context); | |
function getModifier(extension) { | |
return props.pattern[extension] || props.defaultConfig; | |
} | |
function isUseOfExtensionRequired(extension, isPackage) { | |
return getModifier(extension) === 'always' && (!props.ignorePackages || !isPackage); | |
} | |
function isUseOfExtensionForbidden(extension) { | |
return getModifier(extension) === 'never'; | |
} | |
function isResolvableWithoutExtension(file) { | |
var extension = _path2['default'].extname(file); | |
var fileWithoutExtension = file.slice(0, -extension.length); | |
var resolvedFileWithoutExtension = (0, _resolve2['default'])(fileWithoutExtension, context); | |
return resolvedFileWithoutExtension === (0, _resolve2['default'])(file, context); | |
} | |
function isExternalRootModule(file) { | |
if (file === '.' || file === '..') {return false;} | |
var slashCount = file.split('/').length - 1; | |
if (slashCount === 0) {return true;} | |
if ((0, _importType.isScoped)(file) && slashCount <= 1) {return true;} | |
return false; | |
} | |
function checkFileExtension(source, node) { | |
// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor | |
if (!source || !source.value) {return;} | |
var importPathWithQueryString = source.value; | |
// don't enforce anything on builtins | |
if ((0, _importType.isBuiltIn)(importPathWithQueryString, context.settings)) {return;} | |
var importPath = importPathWithQueryString.replace(/\?(.*)$/, ''); | |
// don't enforce in root external packages as they may have names with `.js`. | |
// Like `import Decimal from decimal.js`) | |
if (isExternalRootModule(importPath)) {return;} | |
var resolvedPath = (0, _resolve2['default'])(importPath, context); | |
// get extension from resolved path, if possible. | |
// for unresolved, use source value. | |
var extension = _path2['default'].extname(resolvedPath || importPath).substring(1); | |
// determine if this is a module | |
var isPackage = (0, _importType.isExternalModule)( | |
importPath, | |
(0, _resolve2['default'])(importPath, context), | |
context) || | |
(0, _importType.isScoped)(importPath); | |
if (!extension || !importPath.endsWith('.' + String(extension))) { | |
// ignore type-only imports and exports | |
if (node.importKind === 'type' || node.exportKind === 'type') {return;} | |
var extensionRequired = isUseOfExtensionRequired(extension, isPackage); | |
var extensionForbidden = isUseOfExtensionForbidden(extension); | |
if (extensionRequired && !extensionForbidden) { | |
context.report({ | |
node: source, | |
message: 'Missing file extension ' + ( | |
extension ? '"' + String(extension) + '" ' : '') + 'for "' + String(importPathWithQueryString) + '"' }); | |
} | |
} else if (extension) { | |
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) { | |
context.report({ | |
node: source, | |
message: 'Unexpected use of file extension "' + String(extension) + '" for "' + String(importPathWithQueryString) + '"' }); | |
} | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkFileExtension, { commonjs: true }); | |
}, | |
}, | |
"no-restricted-paths": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Enforce which files can be imported in a given folder.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-restricted-paths.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
zones: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "object", | |
properties: { | |
target: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
minLength: 1, | |
}, | |
], | |
}, | |
from: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
minLength: 1, | |
}, | |
], | |
}, | |
except: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
message: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
basePath: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function noRestrictedPaths(context) { | |
var options = context.options[0] || {}; | |
var restrictedPaths = options.zones || []; | |
var basePath = options.basePath || process.cwd(); | |
var currentFilename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var matchingZones = restrictedPaths.filter( | |
function (zone) {return [].concat(zone.target). | |
map(function (target) {return _path2['default'].resolve(basePath, target);}). | |
some(function (targetPath) {return isMatchingTargetPath(currentFilename, targetPath);});}); | |
function isMatchingTargetPath(filename, targetPath) { | |
if ((0, _isGlob2['default'])(targetPath)) { | |
var mm = new _minimatch.Minimatch(targetPath); | |
return mm.match(filename); | |
} | |
return containsPath(filename, targetPath); | |
} | |
function isValidExceptionPath(absoluteFromPath, absoluteExceptionPath) { | |
var relativeExceptionPath = _path2['default'].relative(absoluteFromPath, absoluteExceptionPath); | |
return (0, _importType2['default'])(relativeExceptionPath, context) !== 'parent'; | |
} | |
function areBothGlobPatternAndAbsolutePath(areGlobPatterns) { | |
return areGlobPatterns.some(function (isGlob) {return isGlob;}) && areGlobPatterns.some(function (isGlob) {return !isGlob;}); | |
} | |
function reportInvalidExceptionPath(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path exceptions must be descendants of the configured `from` path for that zone.' }); | |
} | |
function reportInvalidExceptionMixedGlobAndNonGlob(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path `from` must contain either only glob patterns or none' }); | |
} | |
function reportInvalidExceptionGlob(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path exceptions must be glob patterns when `from` contains glob patterns' }); | |
} | |
function computeMixedGlobAndAbsolutePathValidator() { | |
return { | |
isPathRestricted: function () {function isPathRestricted() {return true;}return isPathRestricted;}(), | |
hasValidExceptions: false, | |
reportInvalidException: reportInvalidExceptionMixedGlobAndNonGlob }; | |
} | |
function computeGlobPatternPathValidator(absoluteFrom, zoneExcept) { | |
var isPathException = void 0; | |
var mm = new _minimatch.Minimatch(absoluteFrom); | |
var isPathRestricted = function () {function isPathRestricted(absoluteImportPath) {return mm.match(absoluteImportPath);}return isPathRestricted;}(); | |
var hasValidExceptions = zoneExcept.every(_isGlob2['default']); | |
if (hasValidExceptions) { | |
var exceptionsMm = zoneExcept.map(function (except) {return new _minimatch.Minimatch(except);}); | |
isPathException = function () {function isPathException(absoluteImportPath) {return exceptionsMm.some(function (mm) {return mm.match(absoluteImportPath);});}return isPathException;}(); | |
} | |
var reportInvalidException = reportInvalidExceptionGlob; | |
return { | |
isPathRestricted: isPathRestricted, | |
hasValidExceptions: hasValidExceptions, | |
isPathException: isPathException, | |
reportInvalidException: reportInvalidException }; | |
} | |
function computeAbsolutePathValidator(absoluteFrom, zoneExcept) { | |
var isPathException = void 0; | |
var isPathRestricted = function () {function isPathRestricted(absoluteImportPath) {return containsPath(absoluteImportPath, absoluteFrom);}return isPathRestricted;}(); | |
var absoluteExceptionPaths = zoneExcept. | |
map(function (exceptionPath) {return _path2['default'].resolve(absoluteFrom, exceptionPath);}); | |
var hasValidExceptions = absoluteExceptionPaths. | |
every(function (absoluteExceptionPath) {return isValidExceptionPath(absoluteFrom, absoluteExceptionPath);}); | |
if (hasValidExceptions) { | |
isPathException = function () {function isPathException(absoluteImportPath) {return absoluteExceptionPaths.some( | |
function (absoluteExceptionPath) {return containsPath(absoluteImportPath, absoluteExceptionPath);});}return isPathException;}(); | |
} | |
var reportInvalidException = reportInvalidExceptionPath; | |
return { | |
isPathRestricted: isPathRestricted, | |
hasValidExceptions: hasValidExceptions, | |
isPathException: isPathException, | |
reportInvalidException: reportInvalidException }; | |
} | |
function reportInvalidExceptions(validators, node) { | |
validators.forEach(function (validator) {return validator.reportInvalidException(node);}); | |
} | |
function reportImportsInRestrictedZone(validators, node, importPath, customMessage) { | |
validators.forEach(function () { | |
context.report({ | |
node: node, | |
message: 'Unexpected path "{{importPath}}" imported in restricted zone.' + (customMessage ? ' ' + String(customMessage) : ''), | |
data: { importPath: importPath } }); | |
}); | |
} | |
var makePathValidators = function () {function makePathValidators(zoneFrom) {var zoneExcept = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | |
var allZoneFrom = [].concat(zoneFrom); | |
var areGlobPatterns = allZoneFrom.map(_isGlob2['default']); | |
if (areBothGlobPatternAndAbsolutePath(areGlobPatterns)) { | |
return [computeMixedGlobAndAbsolutePathValidator()]; | |
} | |
var isGlobPattern = areGlobPatterns.every(function (isGlob) {return isGlob;}); | |
return allZoneFrom.map(function (singleZoneFrom) { | |
var absoluteFrom = _path2['default'].resolve(basePath, singleZoneFrom); | |
if (isGlobPattern) { | |
return computeGlobPatternPathValidator(absoluteFrom, zoneExcept); | |
} | |
return computeAbsolutePathValidator(absoluteFrom, zoneExcept); | |
}); | |
}return makePathValidators;}(); | |
var validators = []; | |
function checkForRestrictedImportPath(importPath, node) { | |
var absoluteImportPath = (0, _resolve2['default'])(importPath, context); | |
if (!absoluteImportPath) { | |
return; | |
} | |
matchingZones.forEach(function (zone, index) { | |
if (!validators[index]) { | |
validators[index] = makePathValidators(zone.from, zone.except); | |
} | |
var applicableValidatorsForImportPath = validators[index].filter(function (validator) {return validator.isPathRestricted(absoluteImportPath);}); | |
var validatorsWithInvalidExceptions = applicableValidatorsForImportPath.filter(function (validator) {return !validator.hasValidExceptions;}); | |
reportInvalidExceptions(validatorsWithInvalidExceptions, node); | |
var applicableValidatorsForImportPathExcludingExceptions = applicableValidatorsForImportPath. | |
filter(function (validator) {return validator.hasValidExceptions && !validator.isPathException(absoluteImportPath);}); | |
reportImportsInRestrictedZone(applicableValidatorsForImportPathExcludingExceptions, node, importPath, zone.message); | |
}); | |
} | |
return (0, _moduleVisitor2['default'])(function (source) { | |
checkForRestrictedImportPath(source.value, source); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-internal-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing the submodules of other modules.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-internal-modules.md", | |
}, | |
schema: [ | |
{ | |
anyOf: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
properties: { | |
forbid: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
}, | |
create: function noReachingInside(context) { | |
var options = context.options[0] || {}; | |
var allowRegexps = (options.allow || []).map(function (p) {return _minimatch2['default'].makeRe(p);}); | |
var forbidRegexps = (options.forbid || []).map(function (p) {return _minimatch2['default'].makeRe(p);}); | |
// minimatch patterns are expected to use / path separators, like import | |
// statements, so normalize paths to use the same | |
function normalizeSep(somePath) { | |
return somePath.split('\\').join('/'); | |
} | |
function toSteps(somePath) { | |
return normalizeSep(somePath). | |
split('/'). | |
filter(function (step) {return step && step !== '.';}). | |
reduce(function (acc, step) { | |
if (step === '..') { | |
return acc.slice(0, -1); | |
} | |
return acc.concat(step); | |
}, []); | |
} | |
// test if reaching to this destination is allowed | |
function reachingAllowed(importPath) { | |
return allowRegexps.some(function (re) {return re.test(importPath);}); | |
} | |
// test if reaching to this destination is forbidden | |
function reachingForbidden(importPath) { | |
return forbidRegexps.some(function (re) {return re.test(importPath);}); | |
} | |
function isAllowViolation(importPath) { | |
var steps = toSteps(importPath); | |
var nonScopeSteps = steps.filter(function (step) {return step.indexOf('@') !== 0;}); | |
if (nonScopeSteps.length <= 1) {return false;} | |
// before trying to resolve, see if the raw import (with relative | |
// segments resolved) matches an allowed pattern | |
var justSteps = steps.join('/'); | |
if (reachingAllowed(justSteps) || reachingAllowed('/' + String(justSteps))) {return false;} | |
// if the import statement doesn't match directly, try to match the | |
// resolved path if the import is resolvable | |
var resolved = (0, _resolve2['default'])(importPath, context); | |
if (!resolved || reachingAllowed(normalizeSep(resolved))) {return false;} | |
// this import was not allowed by the allowed paths, and reaches | |
// so it is a violation | |
return true; | |
} | |
function isForbidViolation(importPath) { | |
var steps = toSteps(importPath); | |
// before trying to resolve, see if the raw import (with relative | |
// segments resolved) matches a forbidden pattern | |
var justSteps = steps.join('/'); | |
if (reachingForbidden(justSteps) || reachingForbidden('/' + String(justSteps))) {return true;} | |
// if the import statement doesn't match directly, try to match the | |
// resolved path if the import is resolvable | |
var resolved = (0, _resolve2['default'])(importPath, context); | |
if (resolved && reachingForbidden(normalizeSep(resolved))) {return true;} | |
// this import was not forbidden by the forbidden paths so it is not a violation | |
return false; | |
} | |
// find a directory that is being reached into, but which shouldn't be | |
var isReachViolation = options.forbid ? isForbidViolation : isAllowViolation; | |
function checkImportForReaching(importPath, node) { | |
var potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal']; | |
if ( | |
potentialViolationTypes.indexOf((0, _importType2['default'])(importPath, context)) !== -1 && | |
isReachViolation(importPath)) | |
{ | |
context.report({ | |
node: node, | |
message: 'Reaching to "' + String(importPath) + '" is not allowed.' }); | |
} | |
} | |
return (0, _moduleVisitor2['default'])( | |
function (source) { | |
checkImportForReaching(source.value, source); | |
}, | |
{ commonjs: true }); | |
}, | |
}, | |
"group-exports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Prefer named exports to be grouped together in a single export declaration", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/group-exports.md", | |
}, | |
}, | |
create: function create(context) { | |
var nodes = { | |
modules: { | |
set: new Set(), | |
sources: {} }, | |
types: { | |
set: new Set(), | |
sources: {} }, | |
commonjs: { | |
set: new Set() } }; | |
return { | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
var target = node.exportKind === 'type' ? nodes.types : nodes.modules; | |
if (!node.source) { | |
target.set.add(node); | |
} else if (Array.isArray(target.sources[node.source.value])) { | |
target.sources[node.source.value].push(node); | |
} else { | |
target.sources[node.source.value] = [node]; | |
} | |
}return ExportNamedDeclaration;}(), | |
AssignmentExpression: function () {function AssignmentExpression(node) { | |
if (node.left.type !== 'MemberExpression') { | |
return; | |
} | |
var chain = accessorChain(node.left); | |
// Assignments to module.exports | |
// Deeper assignments are ignored since they just modify what's already being exported | |
// (ie. module.exports.exported.prop = true is ignored) | |
if (chain[0] === 'module' && chain[1] === 'exports' && chain.length <= 3) { | |
nodes.commonjs.set.add(node); | |
return; | |
} | |
// Assignments to exports (exports.* = *) | |
if (chain[0] === 'exports' && chain.length === 2) { | |
nodes.commonjs.set.add(node); | |
return; | |
} | |
}return AssignmentExpression;}(), | |
'Program:exit': function () {function onExit() { | |
// Report multiple `export` declarations (ES2015 modules) | |
if (nodes.modules.set.size > 1) { | |
nodes.modules.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
// Report multiple `aggregated exports` from the same module (ES2015 modules) | |
(0, _arrayPrototype2['default'])((0, _object2['default'])(nodes.modules.sources). | |
filter(function (nodesWithSource) {return Array.isArray(nodesWithSource) && nodesWithSource.length > 1;})). | |
forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
// Report multiple `export type` declarations (FLOW ES2015 modules) | |
if (nodes.types.set.size > 1) { | |
nodes.types.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
// Report multiple `aggregated type exports` from the same module (FLOW ES2015 modules) | |
(0, _arrayPrototype2['default'])((0, _object2['default'])(nodes.types.sources). | |
filter(function (nodesWithSource) {return Array.isArray(nodesWithSource) && nodesWithSource.length > 1;})). | |
forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
// Report multiple `module.exports` assignments (CommonJS) | |
if (nodes.commonjs.set.size > 1) { | |
nodes.commonjs.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
}return onExit;}() }; | |
}, | |
}, | |
"no-relative-packages": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing packages through relative paths.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-relative-packages.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source) {return checkImportForRelativePackage(context, source.value, source);}, context.options[0]); | |
}, | |
}, | |
"no-relative-parent-imports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing modules from parent directories.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-relative-parent-imports.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function noRelativePackages(context) { | |
var myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
if (myPath === '<text>') {return {};} // can't check a non-file | |
function checkSourceValue(sourceNode) { | |
var depPath = sourceNode.value; | |
if ((0, _importType2['default'])(depPath, context) === 'external') {// ignore packages | |
return; | |
} | |
var absDepPath = (0, _resolve2['default'])(depPath, context); | |
if (!absDepPath) {// unable to resolve path | |
return; | |
} | |
var relDepPath = (0, _path.relative)((0, _path.dirname)(myPath), absDepPath); | |
if ((0, _importType2['default'])(relDepPath, context) === 'parent') { | |
context.report({ | |
node: sourceNode, | |
message: 'Relative imports from parent directories are not allowed. Please either pass what you\'re importing through at runtime (dependency injection), move `' + String((0, _path.basename)(myPath)) + '` to same directory as `' + String(depPath) + '` or consider making `' + String(depPath) + '` a package.' }); | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, context.options[0]); | |
}, | |
}, | |
"consistent-type-specifier-style": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce or ban the use of inline type-only markers for named imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/consistent-type-specifier-style.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"prefer-inline", | |
"prefer-top-level", | |
], | |
default: "prefer-inline", | |
}, | |
], | |
}, | |
create: function create(context) { | |
var sourceCode = context.getSourceCode(); | |
if (context.options[0] === 'prefer-inline') { | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (node.importKind === 'value' || node.importKind == null) { | |
// top-level value / unknown is valid | |
return; | |
} | |
if ( | |
// no specifiers (import type {} from '') have no specifiers to mark as inline | |
node.specifiers.length === 0 || | |
node.specifiers.length === 1 | |
// default imports are both "inline" and "top-level" | |
&& ( | |
node.specifiers[0].type === 'ImportDefaultSpecifier' | |
// namespace imports are both "inline" and "top-level" | |
|| node.specifiers[0].type === 'ImportNamespaceSpecifier')) | |
{ | |
return; | |
} | |
context.report({ | |
node: node, | |
message: 'Prefer using inline {{kind}} specifiers instead of a top-level {{kind}}-only import.', | |
data: { | |
kind: node.importKind }, | |
fix: function () {function fix(fixer) { | |
var kindToken = sourceCode.getFirstToken(node, { skip: 1 }); | |
return [].concat( | |
kindToken ? fixer.remove(kindToken) : [], | |
node.specifiers.map(function (specifier) {return fixer.insertTextBefore(specifier, String(node.importKind) + ' ');})); | |
}return fix;}() }); | |
}return ImportDeclaration;}() }; | |
} | |
// prefer-top-level | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if ( | |
// already top-level is valid | |
node.importKind === 'type' || | |
node.importKind === 'typeof' | |
// no specifiers (import {} from '') cannot have inline - so is valid | |
|| node.specifiers.length === 0 || | |
node.specifiers.length === 1 | |
// default imports are both "inline" and "top-level" | |
&& ( | |
node.specifiers[0].type === 'ImportDefaultSpecifier' | |
// namespace imports are both "inline" and "top-level" | |
|| node.specifiers[0].type === 'ImportNamespaceSpecifier')) | |
{ | |
return; | |
} | |
var typeSpecifiers = []; | |
var typeofSpecifiers = []; | |
var valueSpecifiers = []; | |
var defaultSpecifier = null;var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = node.specifiers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var specifier = _step2.value; | |
if (specifier.type === 'ImportDefaultSpecifier') { | |
defaultSpecifier = specifier; | |
continue; | |
} | |
if (specifier.importKind === 'type') { | |
typeSpecifiers.push(specifier); | |
} else if (specifier.importKind === 'typeof') { | |
typeofSpecifiers.push(specifier); | |
} else if (specifier.importKind === 'value' || specifier.importKind == null) { | |
valueSpecifiers.push(specifier); | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
var typeImport = getImportText(node, sourceCode, typeSpecifiers, 'type'); | |
var typeofImport = getImportText(node, sourceCode, typeofSpecifiers, 'typeof'); | |
var newImports = (String(typeImport) + '\n' + String(typeofImport)).trim(); | |
if (typeSpecifiers.length + typeofSpecifiers.length === node.specifiers.length) { | |
// all specifiers have inline specifiers - so we replace the entire import | |
var kind = [].concat( | |
typeSpecifiers.length > 0 ? 'type' : [], | |
typeofSpecifiers.length > 0 ? 'typeof' : []); | |
context.report({ | |
node: node, | |
message: 'Prefer using a top-level {{kind}}-only import instead of inline {{kind}} specifiers.', | |
data: { | |
kind: kind.join('/') }, | |
fix: function () {function fix(fixer) { | |
return fixer.replaceText(node, newImports); | |
}return fix;}() }); | |
} else { | |
// remove specific specifiers and insert new imports for them | |
var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {for (var _iterator3 = typeSpecifiers.concat(typeofSpecifiers)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var _specifier = _step3.value; | |
context.report({ | |
node: _specifier, | |
message: 'Prefer using a top-level {{kind}}-only import instead of inline {{kind}} specifiers.', | |
data: { | |
kind: _specifier.importKind }, | |
fix: function () {function fix(fixer) { | |
var fixes = []; | |
// if there are no value specifiers, then the other report fixer will be called, not this one | |
if (valueSpecifiers.length > 0) { | |
// import { Value, type Type } from 'mod'; | |
// we can just remove the type specifiers | |
removeSpecifiers(fixes, fixer, sourceCode, typeSpecifiers); | |
removeSpecifiers(fixes, fixer, sourceCode, typeofSpecifiers); | |
// make the import nicely formatted by also removing the trailing comma after the last value import | |
// eg | |
// import { Value, type Type } from 'mod'; | |
// to | |
// import { Value } from 'mod'; | |
// not | |
// import { Value, } from 'mod'; | |
var maybeComma = sourceCode.getTokenAfter(valueSpecifiers[valueSpecifiers.length - 1]); | |
if (isComma(maybeComma)) { | |
fixes.push(fixer.remove(maybeComma)); | |
} | |
} else if (defaultSpecifier) { | |
// import Default, { type Type } from 'mod'; | |
// remove the entire curly block so we don't leave an empty one behind | |
// NOTE - the default specifier *must* be the first specifier always! | |
// so a comma exists that we also have to clean up or else it's bad syntax | |
var comma = sourceCode.getTokenAfter(defaultSpecifier, isComma); | |
var closingBrace = sourceCode.getTokenAfter( | |
node.specifiers[node.specifiers.length - 1], | |
function (token) {return token.type === 'Punctuator' && token.value === '}';}); | |
fixes.push(fixer.removeRange([ | |
comma.range[0], | |
closingBrace.range[1]])); | |
} | |
return fixes.concat( | |
// insert the new imports after the old declaration | |
fixer.insertTextAfter(node, '\n' + String(newImports))); | |
}return fix;}() }); | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
} | |
}return ImportDeclaration;}() }; | |
}, | |
}, | |
"no-self-import": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid a module from importing itself.", | |
recommended: true, | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-self-import.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
isImportingSelf(context, node, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-cycle": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid a module from importing a module with a dependency path back to itself.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-cycle.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
maxDepth: { | |
anyOf: [ | |
{ | |
description: "maximum dependency depth to traverse", | |
type: "integer", | |
minimum: 1, | |
}, | |
{ | |
enum: [ | |
"∞", | |
], | |
type: "string", | |
}, | |
], | |
}, | |
ignoreExternal: { | |
description: "ignore external modules", | |
type: "boolean", | |
default: false, | |
}, | |
allowUnsafeDynamicCyclicDependency: { | |
description: "Allow cyclic dependency if there is at least one dynamic import in the chain", | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
if (myPath === '<text>') {return {};} // can't cycle-check a non-file | |
var options = context.options[0] || {}; | |
var maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity; | |
var ignoreModule = function () {function ignoreModule(name) {return options.ignoreExternal && (0, _importType.isExternalModule)( | |
name, | |
(0, _resolve2['default'])(name, context), | |
context);}return ignoreModule;}(); | |
function checkSourceValue(sourceNode, importer) { | |
if (ignoreModule(sourceNode.value)) { | |
return; // ignore external modules | |
} | |
if ( | |
options.allowUnsafeDynamicCyclicDependency && ( | |
// Ignore `import()` | |
importer.type === 'ImportExpression' | |
// `require()` calls are always checked (if possible) | |
|| importer.type === 'CallExpression' && importer.callee.name !== 'require')) | |
{ | |
return; // cycle via dynamic import allowed by config | |
} | |
if ( | |
importer.type === 'ImportDeclaration' && ( | |
// import type { Foo } (TS and Flow) | |
importer.importKind === 'type' | |
// import { type Foo } (Flow) | |
|| importer.specifiers.every(function (_ref) {var importKind = _ref.importKind;return importKind === 'type';}))) | |
{ | |
return; // ignore type imports | |
} | |
var imported = _ExportMap2['default'].get(sourceNode.value, context); | |
if (imported == null) { | |
return; // no-unresolved territory | |
} | |
if (imported.path === myPath) { | |
return; // no-self-import territory | |
} | |
var untraversed = [{ mget: function () {function mget() {return imported;}return mget;}(), route: [] }]; | |
function detectCycle(_ref2) {var mget = _ref2.mget,route = _ref2.route; | |
var m = mget(); | |
if (m == null) {return;} | |
if (traversed.has(m.path)) {return;} | |
traversed.add(m.path);var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = m.imports[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref3 = _step.value;var _ref4 = _slicedToArray(_ref3, 2);var path = _ref4[0];var _ref4$ = _ref4[1];var getter = _ref4$.getter;var declarations = _ref4$.declarations; | |
if (traversed.has(path)) {continue;} | |
var toTraverse = [].concat(_toConsumableArray(declarations)).filter(function (_ref5) {var source = _ref5.source,isOnlyImportingTypes = _ref5.isOnlyImportingTypes;return !ignoreModule(source.value) | |
// Ignore only type imports | |
&& !isOnlyImportingTypes;}); | |
/* | |
If cyclic dependency is allowed via dynamic import, skip checking if any module is imported dynamically | |
*/ | |
if (options.allowUnsafeDynamicCyclicDependency && toTraverse.some(function (d) {return d.dynamic;})) {return;} | |
/* | |
Only report as a cycle if there are any import declarations that are considered by | |
the rule. For example: | |
a.ts: | |
import { foo } from './b' // should not be reported as a cycle | |
b.ts: | |
import type { Bar } from './a' | |
*/ | |
if (path === myPath && toTraverse.length > 0) {return true;} | |
if (route.length + 1 < maxDepth) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = toTraverse[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref6 = _step2.value;var source = _ref6.source; | |
untraversed.push({ mget: getter, route: route.concat(source) }); | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
while (untraversed.length > 0) { | |
var next = untraversed.shift(); // bfs! | |
if (detectCycle(next)) { | |
var message = next.route.length > 0 ? 'Dependency cycle via ' + String( | |
routeString(next.route)) : | |
'Dependency cycle detected.'; | |
context.report(importer, message); | |
return; | |
} | |
} | |
} | |
return Object.assign((0, _moduleVisitor2['default'])(checkSourceValue, context.options[0]), { | |
'Program:exit': function () {function ProgramExit() { | |
traversed.clear(); | |
}return ProgramExit;}() }); | |
}, | |
}, | |
"no-named-default": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid named default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
node.specifiers.forEach(function (im) { | |
if (im.importKind === 'type' || im.importKind === 'typeof') { | |
return; | |
} | |
if (im.type === 'ImportSpecifier' && (im.imported.name || im.imported.value) === 'default') { | |
context.report({ | |
node: im.local, | |
message: 'Use default import syntax to import \'' + String(im.local.name) + '\'.' }); | |
} | |
}); | |
}return ImportDeclaration;}() }; | |
}, | |
}, | |
"no-named-as-default": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid use of exported name as identifier of default export.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-as-default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDefault(nameKey, defaultSpecifier) { | |
// #566: default is a valid specifier | |
if (defaultSpecifier[nameKey].name === 'default') {return;} | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var imports = _ExportMap2['default'].get(declaration.source.value, context); | |
if (imports == null) {return;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, declaration); | |
return; | |
} | |
if (imports.has('default') && imports.has(defaultSpecifier[nameKey].name)) { | |
context.report( | |
defaultSpecifier, 'Using exported name \'' + String( | |
defaultSpecifier[nameKey].name) + '\' as identifier for default export.'); | |
} | |
} | |
return { | |
ImportDefaultSpecifier: checkDefault.bind(null, 'local'), | |
ExportDefaultSpecifier: checkDefault.bind(null, 'exported') }; | |
}, | |
}, | |
"no-named-as-default-member": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid use of exported name as property of default export.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-as-default-member.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var fileImports = new Map(); | |
var allPropertyLookups = new Map(); | |
function storePropertyLookup(objectName, propName, node) { | |
var lookups = allPropertyLookups.get(objectName) || []; | |
lookups.push({ node: node, propName: propName }); | |
allPropertyLookups.set(objectName, lookups); | |
} | |
return { | |
ImportDefaultSpecifier: function () {function ImportDefaultSpecifier(node) { | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var exportMap = _ExportMap2['default'].get(declaration.source.value, context); | |
if (exportMap == null) {return;} | |
if (exportMap.errors.length) { | |
exportMap.reportErrors(context, declaration); | |
return; | |
} | |
fileImports.set(node.local.name, { | |
exportMap: exportMap, | |
sourcePath: declaration.source.value }); | |
}return ImportDefaultSpecifier;}(), | |
MemberExpression: function () {function MemberExpression(node) { | |
var objectName = node.object.name; | |
var propName = node.property.name; | |
storePropertyLookup(objectName, propName, node); | |
}return MemberExpression;}(), | |
VariableDeclarator: function () {function VariableDeclarator(node) { | |
var isDestructure = node.id.type === 'ObjectPattern' && | |
node.init != null && | |
node.init.type === 'Identifier'; | |
if (!isDestructure) {return;} | |
var objectName = node.init.name;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = node.id.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref = _step.value;var key = _ref.key; | |
if (key == null) {continue;} // true for rest properties | |
storePropertyLookup(objectName, key.name, key); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
}return VariableDeclarator;}(), | |
'Program:exit': function () {function ProgramExit() { | |
allPropertyLookups.forEach(function (lookups, objectName) { | |
var fileImport = fileImports.get(objectName); | |
if (fileImport == null) {return;}var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = lookups[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref2 = _step2.value;var propName = _ref2.propName,node = _ref2.node; | |
// the default import can have a "default" property | |
if (propName === 'default') {continue;} | |
if (!fileImport.exportMap.namespace.has(propName)) {continue;} | |
context.report({ | |
node: node, | |
message: 'Caution: `' + String(objectName) + '` also has a named export `' + String(propName) + '`. Check if you meant to write `import {' + String(propName) + '} from \'' + String(fileImport.sourcePath) + '\'` instead.' }); | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
}); | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-anonymous-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid anonymous values as default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-anonymous-default-export.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowArray: { | |
description: "If `false`, will report default export of an array", | |
type: "boolean", | |
}, | |
allowArrowFunction: { | |
description: "If `false`, will report default export of an arrow function", | |
type: "boolean", | |
}, | |
allowCallExpression: { | |
description: "If `false`, will report default export of a function call", | |
type: "boolean", | |
}, | |
allowAnonymousClass: { | |
description: "If `false`, will report default export of an anonymous class", | |
type: "boolean", | |
}, | |
allowAnonymousFunction: { | |
description: "If `false`, will report default export of an anonymous function", | |
type: "boolean", | |
}, | |
allowLiteral: { | |
description: "If `false`, will report default export of a literal", | |
type: "boolean", | |
}, | |
allowObject: { | |
description: "If `false`, will report default export of an object expression", | |
type: "boolean", | |
}, | |
allowNew: { | |
description: "If `false`, will report default export of a class instantiation", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = Object.assign({}, defaults, context.options[0]); | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
var def = defs[node.declaration.type]; | |
// Recognized node type and allowed by configuration, | |
// and has no forbid check, or forbid check return value is truthy | |
if (def && !options[def.option] && (!def.forbid || def.forbid(node))) { | |
context.report({ node: node, message: def.message }); | |
} | |
}return ExportDefaultDeclaration;}() }; | |
}, | |
}, | |
"no-unused-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid modules without exports, or exports without matching import in another module.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unused-modules.md", | |
}, | |
schema: [ | |
{ | |
properties: { | |
src: { | |
description: "files/paths to be analyzed (only for unused exports)", | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
minLength: 1, | |
}, | |
}, | |
ignoreExports: { | |
description: "files/paths for which unused exports will not be reported (e.g module entry points)", | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
minLength: 1, | |
}, | |
}, | |
missingExports: { | |
description: "report modules without any exports", | |
type: "boolean", | |
}, | |
unusedExports: { | |
description: "report exports without any usage", | |
type: "boolean", | |
}, | |
}, | |
anyOf: [ | |
{ | |
properties: { | |
unusedExports: { | |
enum: [ | |
true, | |
], | |
}, | |
src: { | |
minItems: 1, | |
}, | |
}, | |
required: [ | |
"unusedExports", | |
], | |
}, | |
{ | |
properties: { | |
missingExports: { | |
enum: [ | |
true, | |
], | |
}, | |
}, | |
required: [ | |
"missingExports", | |
], | |
}, | |
], | |
}, | |
], | |
}, | |
create: function create(context) {var _ref9 = | |
context.options[0] || {},src = _ref9.src,_ref9$ignoreExports = _ref9.ignoreExports,ignoreExports = _ref9$ignoreExports === undefined ? [] : _ref9$ignoreExports,missingExports = _ref9.missingExports,unusedExports = _ref9.unusedExports; | |
if (unusedExports) { | |
doPreparation(src, ignoreExports, context); | |
} | |
var file = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var checkExportPresence = function () {function checkExportPresence(node) { | |
if (!missingExports) { | |
return; | |
} | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
var exportCount = exportList.get(file); | |
var exportAll = exportCount.get(EXPORT_ALL_DECLARATION); | |
var namespaceImports = exportCount.get(IMPORT_NAMESPACE_SPECIFIER); | |
exportCount['delete'](EXPORT_ALL_DECLARATION); | |
exportCount['delete'](IMPORT_NAMESPACE_SPECIFIER); | |
if (exportCount.size < 1) { | |
// node.body[0] === 'undefined' only happens, if everything is commented out in the file | |
// being linted | |
context.report(node.body[0] ? node.body[0] : node, 'No exports found'); | |
} | |
exportCount.set(EXPORT_ALL_DECLARATION, exportAll); | |
exportCount.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports); | |
}return checkExportPresence;}(); | |
var checkUsage = function () {function checkUsage(node, exportedValue) { | |
if (!unusedExports) { | |
return; | |
} | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
if (fileIsInPkg(file)) { | |
return; | |
} | |
if (filesOutsideSrc.has(file)) { | |
return; | |
} | |
// make sure file to be linted is included in source files | |
if (!srcFiles.has(file)) { | |
srcFiles = resolveFiles(getSrc(src), ignoreExports, context); | |
if (!srcFiles.has(file)) { | |
filesOutsideSrc.add(file); | |
return; | |
} | |
} | |
exports = exportList.get(file); | |
// special case: export * from | |
var exportAll = exports.get(EXPORT_ALL_DECLARATION); | |
if (typeof exportAll !== 'undefined' && exportedValue !== IMPORT_DEFAULT_SPECIFIER) { | |
if (exportAll.whereUsed.size > 0) { | |
return; | |
} | |
} | |
// special case: namespace import | |
var namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof namespaceImports !== 'undefined') { | |
if (namespaceImports.whereUsed.size > 0) { | |
return; | |
} | |
} | |
// exportsList will always map any imported value of 'default' to 'ImportDefaultSpecifier' | |
var exportsKey = exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue; | |
var exportStatement = exports.get(exportsKey); | |
var value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey; | |
if (typeof exportStatement !== 'undefined') { | |
if (exportStatement.whereUsed.size < 1) { | |
context.report( | |
node, 'exported declaration \'' + | |
value + '\' not used within other modules'); | |
} | |
} else { | |
context.report( | |
node, 'exported declaration \'' + | |
value + '\' not used within other modules'); | |
} | |
}return checkUsage;}(); | |
/** | |
* only useful for tools like vscode-eslint | |
* | |
* update lists of existing exports during runtime | |
*/ | |
var updateExportUsage = function () {function updateExportUsage(node) { | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
var exports = exportList.get(file); | |
// new module has been created during runtime | |
// include it in further processing | |
if (typeof exports === 'undefined') { | |
exports = new Map(); | |
} | |
var newExports = new Map(); | |
var newExportIdentifiers = new Set(); | |
node.body.forEach(function (_ref10) {var type = _ref10.type,declaration = _ref10.declaration,specifiers = _ref10.specifiers; | |
if (type === EXPORT_DEFAULT_DECLARATION) { | |
newExportIdentifiers.add(IMPORT_DEFAULT_SPECIFIER); | |
} | |
if (type === EXPORT_NAMED_DECLARATION) { | |
if (specifiers.length > 0) { | |
specifiers.forEach(function (specifier) { | |
if (specifier.exported) { | |
newExportIdentifiers.add(specifier.exported.name || specifier.exported.value); | |
} | |
}); | |
} | |
forEachDeclarationIdentifier(declaration, function (name) { | |
newExportIdentifiers.add(name); | |
}); | |
} | |
}); | |
// old exports exist within list of new exports identifiers: add to map of new exports | |
exports.forEach(function (value, key) { | |
if (newExportIdentifiers.has(key)) { | |
newExports.set(key, value); | |
} | |
}); | |
// new export identifiers added: add to map of new exports | |
newExportIdentifiers.forEach(function (key) { | |
if (!exports.has(key)) { | |
newExports.set(key, { whereUsed: new Set() }); | |
} | |
}); | |
// preserve information about namespace imports | |
var exportAll = exports.get(EXPORT_ALL_DECLARATION); | |
var namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof namespaceImports === 'undefined') { | |
namespaceImports = { whereUsed: new Set() }; | |
} | |
newExports.set(EXPORT_ALL_DECLARATION, exportAll); | |
newExports.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports); | |
exportList.set(file, newExports); | |
}return updateExportUsage;}(); | |
/** | |
* only useful for tools like vscode-eslint | |
* | |
* update lists of existing imports during runtime | |
*/ | |
var updateImportUsage = function () {function updateImportUsage(node) { | |
if (!unusedExports) { | |
return; | |
} | |
var oldImportPaths = importList.get(file); | |
if (typeof oldImportPaths === 'undefined') { | |
oldImportPaths = new Map(); | |
} | |
var oldNamespaceImports = new Set(); | |
var newNamespaceImports = new Set(); | |
var oldExportAll = new Set(); | |
var newExportAll = new Set(); | |
var oldDefaultImports = new Set(); | |
var newDefaultImports = new Set(); | |
var oldImports = new Map(); | |
var newImports = new Map(); | |
oldImportPaths.forEach(function (value, key) { | |
if (value.has(EXPORT_ALL_DECLARATION)) { | |
oldExportAll.add(key); | |
} | |
if (value.has(IMPORT_NAMESPACE_SPECIFIER)) { | |
oldNamespaceImports.add(key); | |
} | |
if (value.has(IMPORT_DEFAULT_SPECIFIER)) { | |
oldDefaultImports.add(key); | |
} | |
value.forEach(function (val) { | |
if ( | |
val !== IMPORT_NAMESPACE_SPECIFIER && | |
val !== IMPORT_DEFAULT_SPECIFIER) | |
{ | |
oldImports.set(val, key); | |
} | |
}); | |
}); | |
function processDynamicImport(source) { | |
if (source.type !== 'Literal') { | |
return null; | |
} | |
var p = (0, _resolve2['default'])(source.value, context); | |
if (p == null) { | |
return null; | |
} | |
newNamespaceImports.add(p); | |
} | |
(0, _visit2['default'])(node, visitorKeyMap.get(file), { | |
ImportExpression: function () {function ImportExpression(child) { | |
processDynamicImport(child.source); | |
}return ImportExpression;}(), | |
CallExpression: function () {function CallExpression(child) { | |
if (child.callee.type === 'Import') { | |
processDynamicImport(child.arguments[0]); | |
} | |
}return CallExpression;}() }); | |
node.body.forEach(function (astNode) { | |
var resolvedPath = void 0; | |
// support for export { value } from 'module' | |
if (astNode.type === EXPORT_NAMED_DECLARATION) { | |
if (astNode.source) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
astNode.specifiers.forEach(function (specifier) { | |
var name = specifier.local.name || specifier.local.value; | |
if (name === DEFAULT) { | |
newDefaultImports.add(resolvedPath); | |
} else { | |
newImports.set(name, resolvedPath); | |
} | |
}); | |
} | |
} | |
if (astNode.type === EXPORT_ALL_DECLARATION) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
newExportAll.add(resolvedPath); | |
} | |
if (astNode.type === IMPORT_DECLARATION) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
if (!resolvedPath) { | |
return; | |
} | |
if (isNodeModule(resolvedPath)) { | |
return; | |
} | |
if (newNamespaceImportExists(astNode.specifiers)) { | |
newNamespaceImports.add(resolvedPath); | |
} | |
if (newDefaultImportExists(astNode.specifiers)) { | |
newDefaultImports.add(resolvedPath); | |
} | |
astNode.specifiers. | |
filter(function (specifier) {return specifier.type !== IMPORT_DEFAULT_SPECIFIER && specifier.type !== IMPORT_NAMESPACE_SPECIFIER;}). | |
forEach(function (specifier) { | |
newImports.set(specifier.imported.name || specifier.imported.value, resolvedPath); | |
}); | |
} | |
}); | |
newExportAll.forEach(function (value) { | |
if (!oldExportAll.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(EXPORT_ALL_DECLARATION); | |
oldImportPaths.set(value, imports); | |
var _exports = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports !== 'undefined') { | |
currentExport = _exports.get(EXPORT_ALL_DECLARATION); | |
} else { | |
_exports = new Map(); | |
exportList.set(value, _exports); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports.set(EXPORT_ALL_DECLARATION, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldExportAll.forEach(function (value) { | |
if (!newExportAll.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](EXPORT_ALL_DECLARATION); | |
var _exports2 = exportList.get(value); | |
if (typeof _exports2 !== 'undefined') { | |
var currentExport = _exports2.get(EXPORT_ALL_DECLARATION); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newDefaultImports.forEach(function (value) { | |
if (!oldDefaultImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(IMPORT_DEFAULT_SPECIFIER); | |
oldImportPaths.set(value, imports); | |
var _exports3 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports3 !== 'undefined') { | |
currentExport = _exports3.get(IMPORT_DEFAULT_SPECIFIER); | |
} else { | |
_exports3 = new Map(); | |
exportList.set(value, _exports3); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports3.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldDefaultImports.forEach(function (value) { | |
if (!newDefaultImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](IMPORT_DEFAULT_SPECIFIER); | |
var _exports4 = exportList.get(value); | |
if (typeof _exports4 !== 'undefined') { | |
var currentExport = _exports4.get(IMPORT_DEFAULT_SPECIFIER); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newNamespaceImports.forEach(function (value) { | |
if (!oldNamespaceImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(IMPORT_NAMESPACE_SPECIFIER); | |
oldImportPaths.set(value, imports); | |
var _exports5 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports5 !== 'undefined') { | |
currentExport = _exports5.get(IMPORT_NAMESPACE_SPECIFIER); | |
} else { | |
_exports5 = new Map(); | |
exportList.set(value, _exports5); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports5.set(IMPORT_NAMESPACE_SPECIFIER, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldNamespaceImports.forEach(function (value) { | |
if (!newNamespaceImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](IMPORT_NAMESPACE_SPECIFIER); | |
var _exports6 = exportList.get(value); | |
if (typeof _exports6 !== 'undefined') { | |
var currentExport = _exports6.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newImports.forEach(function (value, key) { | |
if (!oldImports.has(key)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(key); | |
oldImportPaths.set(value, imports); | |
var _exports7 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports7 !== 'undefined') { | |
currentExport = _exports7.get(key); | |
} else { | |
_exports7 = new Map(); | |
exportList.set(value, _exports7); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports7.set(key, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldImports.forEach(function (value, key) { | |
if (!newImports.has(key)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](key); | |
var _exports8 = exportList.get(value); | |
if (typeof _exports8 !== 'undefined') { | |
var currentExport = _exports8.get(key); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
}return updateImportUsage;}(); | |
return { | |
'Program:exit': function () {function ProgramExit(node) { | |
updateExportUsage(node); | |
updateImportUsage(node); | |
checkExportPresence(node); | |
}return ProgramExit;}(), | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
checkUsage(node, IMPORT_DEFAULT_SPECIFIER); | |
}return ExportDefaultDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
node.specifiers.forEach(function (specifier) { | |
checkUsage(specifier, specifier.exported.name || specifier.exported.value); | |
}); | |
forEachDeclarationIdentifier(node.declaration, function (name) { | |
checkUsage(node, name); | |
}); | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-commonjs": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid CommonJS `require` calls and `module.exports` or `exports.*`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-commonjs.md", | |
}, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"allow-primitive-modules", | |
], | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
properties: { | |
allowPrimitiveModules: { | |
type: "boolean", | |
}, | |
allowRequire: { | |
type: "boolean", | |
}, | |
allowConditionalRequire: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
create: function create(context) { | |
var options = normalizeLegacyOptions(context.options); | |
return { | |
MemberExpression: function () {function MemberExpression(node) { | |
// module.exports | |
if (node.object.name === 'module' && node.property.name === 'exports') { | |
if (allowPrimitive(node, options)) {return;} | |
context.report({ node: node, message: EXPORT_MESSAGE }); | |
} | |
// exports. | |
if (node.object.name === 'exports') { | |
var isInScope = context.getScope(). | |
variables. | |
some(function (variable) {return variable.name === 'exports';}); | |
if (!isInScope) { | |
context.report({ node: node, message: EXPORT_MESSAGE }); | |
} | |
} | |
}return MemberExpression;}(), | |
CallExpression: function () {function CallExpression(call) { | |
if (!validateScope(context.getScope())) {return;} | |
if (call.callee.type !== 'Identifier') {return;} | |
if (call.callee.name !== 'require') {return;} | |
if (call.arguments.length !== 1) {return;} | |
if (!isLiteralString(call.arguments[0])) {return;} | |
if (allowRequire(call, options)) {return;} | |
if (allowConditionalRequire(call, options) && isConditional(call.parent)) {return;} | |
// keeping it simple: all 1-string-arg `require` calls are reported | |
context.report({ | |
node: call.callee, | |
message: IMPORT_MESSAGE }); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-amd": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid AMD `require` and `define` calls.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-amd.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
CallExpression: function () {function CallExpression(node) { | |
if (context.getScope().type !== 'module') {return;} | |
if (node.callee.type !== 'Identifier') {return;} | |
if (node.callee.name !== 'require' && node.callee.name !== 'define') {return;} | |
// todo: capture define((require, module, exports) => {}) form? | |
if (node.arguments.length !== 2) {return;} | |
var modules = node.arguments[0]; | |
if (modules.type !== 'ArrayExpression') {return;} | |
// todo: check second arg type? (identifier or callback) | |
context.report(node, 'Expected imports instead of AMD ' + String(node.callee.name) + '().'); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-duplicates": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Style guide", | |
description: "Forbid repeated import of the same module in multiple places.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-duplicates.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
considerQueryString: { | |
type: "boolean", | |
}, | |
"prefer-inline": { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
// Prepare the resolver from options. | |
var considerQueryStringOption = context.options[0] && | |
context.options[0].considerQueryString; | |
var defaultResolver = function () {function defaultResolver(sourcePath) {return (0, _resolve2['default'])(sourcePath, context) || sourcePath;}return defaultResolver;}(); | |
var resolver = considerQueryStringOption ? function (sourcePath) { | |
var parts = sourcePath.match(/^([^?]*)\?(.*)$/); | |
if (!parts) { | |
return defaultResolver(sourcePath); | |
} | |
return String(defaultResolver(parts[1])) + '?' + String(parts[2]); | |
} : defaultResolver; | |
var moduleMaps = new Map(); | |
function getImportMap(n) { | |
if (!moduleMaps.has(n.parent)) { | |
moduleMaps.set(n.parent, { | |
imported: new Map(), | |
nsImported: new Map(), | |
defaultTypesImported: new Map(), | |
namedTypesImported: new Map() }); | |
} | |
var map = moduleMaps.get(n.parent); | |
var preferInline = context.options[0] && context.options[0]['prefer-inline']; | |
if (!preferInline && n.importKind === 'type') { | |
return n.specifiers.length > 0 && n.specifiers[0].type === 'ImportDefaultSpecifier' ? map.defaultTypesImported : map.namedTypesImported; | |
} | |
if (!preferInline && n.specifiers.some(function (spec) {return spec.importKind === 'type';})) { | |
return map.namedTypesImported; | |
} | |
return hasNamespace(n) ? map.nsImported : map.imported; | |
} | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(n) { | |
// resolved path will cover aliased duplicates | |
var resolvedPath = resolver(n.source.value); | |
var importMap = getImportMap(n); | |
if (importMap.has(resolvedPath)) { | |
importMap.get(resolvedPath).push(n); | |
} else { | |
importMap.set(resolvedPath, [n]); | |
} | |
}return ImportDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() {var _iteratorNormalCompletion5 = true;var _didIteratorError5 = false;var _iteratorError5 = undefined;try { | |
for (var _iterator5 = moduleMaps.values()[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {var map = _step5.value; | |
checkImports(map.imported, context); | |
checkImports(map.nsImported, context); | |
checkImports(map.defaultTypesImported, context); | |
checkImports(map.namedTypesImported, context); | |
}} catch (err) {_didIteratorError5 = true;_iteratorError5 = err;} finally {try {if (!_iteratorNormalCompletion5 && _iterator5['return']) {_iterator5['return']();}} finally {if (_didIteratorError5) {throw _iteratorError5;}}} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
first: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure all imports appear before other statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/first.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"absolute-first", | |
"disable-absolute-first", | |
], | |
}, | |
], | |
}, | |
create: function create(context) { | |
function isPossibleDirective(node) { | |
return node.type === 'ExpressionStatement' && | |
node.expression.type === 'Literal' && | |
typeof node.expression.value === 'string'; | |
} | |
return { | |
Program: function () {function Program(n) { | |
var body = n.body; | |
if (!body) { | |
return; | |
} | |
var absoluteFirst = context.options[0] === 'absolute-first'; | |
var message = 'Import in body of module; reorder to top.'; | |
var sourceCode = context.getSourceCode(); | |
var originSourceCode = sourceCode.getText(); | |
var nonImportCount = 0; | |
var anyExpressions = false; | |
var anyRelative = false; | |
var lastLegalImp = null; | |
var errorInfos = []; | |
var shouldSort = true; | |
var lastSortNodesIndex = 0; | |
body.forEach(function (node, index) { | |
if (!anyExpressions && isPossibleDirective(node)) { | |
return; | |
} | |
anyExpressions = true; | |
if (node.type === 'ImportDeclaration' || node.type === 'TSImportEqualsDeclaration') { | |
if (absoluteFirst) { | |
if (/^\./.test(getImportValue(node))) { | |
anyRelative = true; | |
} else if (anyRelative) { | |
context.report({ | |
node: node.type === 'ImportDeclaration' ? node.source : node.moduleReference, | |
message: 'Absolute imports should come before relative imports.' }); | |
} | |
} | |
if (nonImportCount > 0) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = context.getDeclaredVariables(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (!shouldSort) {break;} | |
var references = variable.references; | |
if (references.length) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = references[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var reference = _step2.value; | |
if (reference.identifier.range[0] < node.range[1]) { | |
shouldSort = false; | |
break; | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
shouldSort && (lastSortNodesIndex = errorInfos.length); | |
errorInfos.push({ | |
node: node, | |
range: [body[index - 1].range[1], node.range[1]] }); | |
} else { | |
lastLegalImp = node; | |
} | |
} else { | |
nonImportCount++; | |
} | |
}); | |
if (!errorInfos.length) {return;} | |
errorInfos.forEach(function (errorInfo, index) { | |
var node = errorInfo.node; | |
var infos = { | |
node: node, | |
message: message }; | |
if (index < lastSortNodesIndex) { | |
infos.fix = function (fixer) { | |
return fixer.insertTextAfter(node, ''); | |
}; | |
} else if (index === lastSortNodesIndex) { | |
var sortNodes = errorInfos.slice(0, lastSortNodesIndex + 1); | |
infos.fix = function (fixer) { | |
var removeFixers = sortNodes.map(function (_errorInfo) { | |
return fixer.removeRange(_errorInfo.range); | |
}); | |
var range = [0, removeFixers[removeFixers.length - 1].range[1]]; | |
var insertSourceCode = sortNodes.map(function (_errorInfo) { | |
var nodeSourceCode = String.prototype.slice.apply( | |
originSourceCode, _errorInfo.range); | |
if (/\S/.test(nodeSourceCode[0])) { | |
return '\n' + String(nodeSourceCode); | |
} | |
return nodeSourceCode; | |
}).join(''); | |
var insertFixer = null; | |
var replaceSourceCode = ''; | |
if (!lastLegalImp) { | |
insertSourceCode = insertSourceCode.trim() + insertSourceCode.match(/^(\s+)/)[0]; | |
} | |
insertFixer = lastLegalImp ? | |
fixer.insertTextAfter(lastLegalImp, insertSourceCode) : | |
fixer.insertTextBefore(body[0], insertSourceCode); | |
var fixers = [insertFixer].concat(removeFixers); | |
fixers.forEach(function (computedFixer, i) { | |
replaceSourceCode += originSourceCode.slice( | |
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]) + | |
computedFixer.text; | |
}); | |
return fixer.replaceTextRange(range, replaceSourceCode); | |
}; | |
} | |
context.report(infos); | |
}); | |
}return Program;}() }; | |
}, | |
}, | |
"max-dependencies": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce the maximum number of dependencies a module can have.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/max-dependencies.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
max: { | |
type: "number", | |
}, | |
ignoreTypeImports: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) {var _ref2 = | |
context.options[0] || {},_ref2$ignoreTypeImpor = _ref2.ignoreTypeImports,ignoreTypeImports = _ref2$ignoreTypeImpor === undefined ? DEFAULT_IGNORE_TYPE_IMPORTS : _ref2$ignoreTypeImpor; | |
var dependencies = new Set(); // keep track of dependencies | |
var lastNode = void 0; // keep track of the last node to report on | |
return Object.assign({ | |
'Program:exit': function () {function ProgramExit() { | |
countDependencies(dependencies, lastNode, context); | |
}return ProgramExit;}() }, | |
(0, _moduleVisitor2['default'])( | |
function (source, _ref3) {var importKind = _ref3.importKind; | |
if (importKind !== TYPE_IMPORT || !ignoreTypeImports) { | |
dependencies.add(source.value); | |
} | |
lastNode = source; | |
}, | |
{ commonjs: true })); | |
}, | |
}, | |
"no-extraneous-dependencies": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid the use of extraneous packages.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-extraneous-dependencies.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
devDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
optionalDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
peerDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
bundledDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
packageDir: { | |
type: [ | |
"string", | |
"array", | |
], | |
}, | |
includeInternal: { | |
type: [ | |
"boolean", | |
], | |
}, | |
includeTypes: { | |
type: [ | |
"boolean", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var deps = getDependencies(context, options.packageDir) || extractDepFields({}); | |
var depsOptions = { | |
allowDevDeps: testConfig(options.devDependencies, filename) !== false, | |
allowOptDeps: testConfig(options.optionalDependencies, filename) !== false, | |
allowPeerDeps: testConfig(options.peerDependencies, filename) !== false, | |
allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false, | |
verifyInternalDeps: !!options.includeInternal, | |
verifyTypeImports: !!options.includeTypes }; | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfMissing(context, deps, depsOptions, node, source.value); | |
}, { commonjs: true }); | |
}, | |
"Program:exit": function ProgramExit() { | |
depFieldCache.clear(); | |
}, | |
}, | |
"no-absolute-path": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid import of modules using absolute paths.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-absolute-path.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
function reportIfAbsolute(source) { | |
if ((0, _importType.isAbsolute)(source.value)) { | |
context.report({ | |
node: source, | |
message: 'Do not import modules using an absolute path', | |
fix: function () {function fix(fixer) { | |
var resolvedContext = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
// node.js and web imports work with posix style paths ("/") | |
var relativePath = _path2['default'].posix.relative(_path2['default'].dirname(resolvedContext), source.value); | |
if (!relativePath.startsWith('.')) { | |
relativePath = './' + String(relativePath); | |
} | |
return fixer.replaceText(source, JSON.stringify(relativePath)); | |
}return fix;}() }); | |
} | |
} | |
var options = Object.assign({ esmodule: true, commonjs: true }, context.options[0]); | |
return (0, _moduleVisitor2['default'])(reportIfAbsolute, options); | |
}, | |
}, | |
"no-nodejs-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid Node.js builtin modules.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-nodejs-modules.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var allowed = options.allow || []; | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfMissing(context, node, allowed, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-webpack-loader-syntax": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid webpack loader syntax in imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-webpack-loader-syntax.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfNonStandard(context, node, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
order: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a convention in module import order.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/order.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
groups: { | |
type: "array", | |
}, | |
pathGroupsExcludedImportTypes: { | |
type: "array", | |
}, | |
distinctGroup: { | |
type: "boolean", | |
default: true, | |
}, | |
pathGroups: { | |
type: "array", | |
items: { | |
type: "object", | |
properties: { | |
pattern: { | |
type: "string", | |
}, | |
patternOptions: { | |
type: "object", | |
}, | |
group: { | |
type: "string", | |
enum: [ | |
"builtin", | |
"external", | |
"internal", | |
"unknown", | |
"parent", | |
"sibling", | |
"index", | |
"object", | |
"type", | |
], | |
}, | |
position: { | |
type: "string", | |
enum: [ | |
"after", | |
"before", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"pattern", | |
"group", | |
], | |
}, | |
}, | |
"newlines-between": { | |
enum: [ | |
"ignore", | |
"always", | |
"always-and-inside-groups", | |
"never", | |
], | |
}, | |
alphabetize: { | |
type: "object", | |
properties: { | |
caseInsensitive: { | |
type: "boolean", | |
default: false, | |
}, | |
order: { | |
enum: [ | |
"ignore", | |
"asc", | |
"desc", | |
], | |
default: "ignore", | |
}, | |
orderImportKind: { | |
enum: [ | |
"ignore", | |
"asc", | |
"desc", | |
], | |
default: "ignore", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
warnOnUnassignedImports: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function importOrderRule(context) { | |
var options = context.options[0] || {}; | |
var newlinesBetweenImports = options['newlines-between'] || 'ignore'; | |
var pathGroupsExcludedImportTypes = new Set(options.pathGroupsExcludedImportTypes || ['builtin', 'external', 'object']); | |
var alphabetize = getAlphabetizeConfig(options); | |
var distinctGroup = options.distinctGroup == null ? defaultDistinctGroup : !!options.distinctGroup; | |
var ranks = void 0; | |
try {var _convertPathGroupsFor = | |
convertPathGroupsForRanks(options.pathGroups || []),pathGroups = _convertPathGroupsFor.pathGroups,maxPosition = _convertPathGroupsFor.maxPosition;var _convertGroupsToRanks = | |
convertGroupsToRanks(options.groups || defaultGroups),groups = _convertGroupsToRanks.groups,omittedTypes = _convertGroupsToRanks.omittedTypes; | |
ranks = { | |
groups: groups, | |
omittedTypes: omittedTypes, | |
pathGroups: pathGroups, | |
maxPosition: maxPosition }; | |
} catch (error) { | |
// Malformed configuration | |
return { | |
Program: function () {function Program(node) { | |
context.report(node, error.message); | |
}return Program;}() }; | |
} | |
var importMap = new Map(); | |
function getBlockImports(node) { | |
if (!importMap.has(node)) { | |
importMap.set(node, []); | |
} | |
return importMap.get(node); | |
} | |
return { | |
ImportDeclaration: function () {function handleImports(node) { | |
// Ignoring unassigned imports unless warnOnUnassignedImports is set | |
if (node.specifiers.length || options.warnOnUnassignedImports) { | |
var name = node.source.value; | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: name, | |
displayName: name, | |
type: 'import' }, | |
ranks, | |
getBlockImports(node.parent), | |
pathGroupsExcludedImportTypes); | |
} | |
}return handleImports;}(), | |
TSImportEqualsDeclaration: function () {function handleImports(node) { | |
var displayName = void 0; | |
var value = void 0; | |
var type = void 0; | |
// skip "export import"s | |
if (node.isExport) { | |
return; | |
} | |
if (node.moduleReference.type === 'TSExternalModuleReference') { | |
value = node.moduleReference.expression.value; | |
displayName = value; | |
type = 'import'; | |
} else { | |
value = ''; | |
displayName = context.getSourceCode().getText(node.moduleReference); | |
type = 'import:object'; | |
} | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: value, | |
displayName: displayName, | |
type: type }, | |
ranks, | |
getBlockImports(node.parent), | |
pathGroupsExcludedImportTypes); | |
}return handleImports;}(), | |
CallExpression: function () {function handleRequires(node) { | |
if (!(0, _staticRequire2['default'])(node)) { | |
return; | |
} | |
var block = getRequireBlock(node); | |
if (!block) { | |
return; | |
} | |
var name = node.arguments[0].value; | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: name, | |
displayName: name, | |
type: 'require' }, | |
ranks, | |
getBlockImports(block), | |
pathGroupsExcludedImportTypes); | |
}return handleRequires;}(), | |
'Program:exit': function () {function reportAndReset() { | |
importMap.forEach(function (imported) { | |
if (newlinesBetweenImports !== 'ignore') { | |
makeNewlinesBetweenReport(context, imported, newlinesBetweenImports, distinctGroup); | |
} | |
if (alphabetize.order !== 'ignore') { | |
mutateRanksToAlphabetize(imported, alphabetize); | |
} | |
makeOutOfOrderReport(context, imported); | |
}); | |
importMap.clear(); | |
}return reportAndReset;}() }; | |
}, | |
}, | |
"newline-after-import": { | |
meta: { | |
type: "layout", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a newline after import statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/newline-after-import.md", | |
}, | |
fixable: "whitespace", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
count: { | |
type: "integer", | |
minimum: 1, | |
}, | |
exactCount: { | |
type: "boolean", | |
}, | |
considerComments: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var level = 0; | |
var requireCalls = []; | |
var options = Object.assign({ | |
count: 1, | |
exactCount: false, | |
considerComments: false }, | |
context.options[0]); | |
function checkForNewLine(node, nextNode, type) { | |
if (isExportDefaultClass(nextNode) || isExportNameClass(nextNode)) { | |
var classNode = nextNode.declaration; | |
if (isClassWithDecorator(classNode)) { | |
nextNode = classNode.decorators[0]; | |
} | |
} else if (isClassWithDecorator(nextNode)) { | |
nextNode = nextNode.decorators[0]; | |
} | |
var lineDifference = getLineDifference(node, nextNode); | |
var EXPECTED_LINE_DIFFERENCE = options.count + 1; | |
if ( | |
lineDifference < EXPECTED_LINE_DIFFERENCE || | |
options.exactCount && lineDifference !== EXPECTED_LINE_DIFFERENCE) | |
{ | |
var column = node.loc.start.column; | |
if (node.loc.start.line !== node.loc.end.line) { | |
column = 0; | |
} | |
context.report({ | |
loc: { | |
line: node.loc.end.line, | |
column: column }, | |
message: 'Expected ' + String(options.count) + ' empty line' + (options.count > 1 ? 's' : '') + ' after ' + String(type) + ' statement not followed by another ' + String(type) + '.', | |
fix: options.exactCount && EXPECTED_LINE_DIFFERENCE < lineDifference ? undefined : function (fixer) {return fixer.insertTextAfter( | |
node, | |
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference));} }); | |
} | |
} | |
function commentAfterImport(node, nextComment) { | |
var lineDifference = getLineDifference(node, nextComment); | |
var EXPECTED_LINE_DIFFERENCE = options.count + 1; | |
if (lineDifference < EXPECTED_LINE_DIFFERENCE) { | |
var column = node.loc.start.column; | |
if (node.loc.start.line !== node.loc.end.line) { | |
column = 0; | |
} | |
context.report({ | |
loc: { | |
line: node.loc.end.line, | |
column: column }, | |
message: 'Expected ' + String(options.count) + ' empty line' + (options.count > 1 ? 's' : '') + ' after import statement not followed by another import.', | |
fix: options.exactCount && EXPECTED_LINE_DIFFERENCE < lineDifference ? undefined : function (fixer) {return fixer.insertTextAfter( | |
node, | |
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference));} }); | |
} | |
} | |
function incrementLevel() { | |
level++; | |
} | |
function decrementLevel() { | |
level--; | |
} | |
function checkImport(node) {var | |
parent = node.parent; | |
if (!parent || !parent.body) { | |
return; | |
} | |
var nodePosition = parent.body.indexOf(node); | |
var nextNode = parent.body[nodePosition + 1]; | |
var endLine = node.loc.end.line; | |
var nextComment = void 0; | |
if (typeof parent.comments !== 'undefined' && options.considerComments) { | |
nextComment = parent.comments.find(function (o) {return o.loc.start.line >= endLine && o.loc.start.line <= endLine + options.count + 1;}); | |
} | |
// skip "export import"s | |
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) { | |
return; | |
} | |
if (nextComment && typeof nextComment !== 'undefined') { | |
commentAfterImport(node, nextComment); | |
} else if (nextNode && nextNode.type !== 'ImportDeclaration' && (nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)) { | |
checkForNewLine(node, nextNode, 'import'); | |
} | |
} | |
return { | |
ImportDeclaration: checkImport, | |
TSImportEqualsDeclaration: checkImport, | |
CallExpression: function () {function CallExpression(node) { | |
if ((0, _staticRequire2['default'])(node) && level === 0) { | |
requireCalls.push(node); | |
} | |
}return CallExpression;}(), | |
'Program:exit': function () {function ProgramExit() { | |
log('exit processing for', context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()); | |
var scopeBody = getScopeBody(context.getScope()); | |
log('got scope:', scopeBody); | |
requireCalls.forEach(function (node, index) { | |
var nodePosition = findNodeIndexInScopeBody(scopeBody, node); | |
log('node position in scope:', nodePosition); | |
var statementWithRequireCall = scopeBody[nodePosition]; | |
var nextStatement = scopeBody[nodePosition + 1]; | |
var nextRequireCall = requireCalls[index + 1]; | |
if (nextRequireCall && containsNodeOrEqual(statementWithRequireCall, nextRequireCall)) { | |
return; | |
} | |
if ( | |
nextStatement && ( | |
!nextRequireCall || | |
!containsNodeOrEqual(nextStatement, nextRequireCall))) | |
{ | |
checkForNewLine(statementWithRequireCall, nextStatement, 'require'); | |
} | |
}); | |
}return ProgramExit;}(), | |
FunctionDeclaration: incrementLevel, | |
FunctionExpression: incrementLevel, | |
ArrowFunctionExpression: incrementLevel, | |
BlockStatement: incrementLevel, | |
ObjectExpression: incrementLevel, | |
Decorator: incrementLevel, | |
'FunctionDeclaration:exit': decrementLevel, | |
'FunctionExpression:exit': decrementLevel, | |
'ArrowFunctionExpression:exit': decrementLevel, | |
'BlockStatement:exit': decrementLevel, | |
'ObjectExpression:exit': decrementLevel, | |
'Decorator:exit': decrementLevel }; | |
}, | |
}, | |
"prefer-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Prefer a default export if module exports a single name or multiple names.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/prefer-default-export.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
target: { | |
type: "string", | |
enum: [ | |
"single", | |
"any", | |
], | |
default: "single", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var specifierExportCount = 0; | |
var hasDefaultExport = false; | |
var hasStarExport = false; | |
var hasTypeExport = false; | |
var namedExportNode = null; | |
// get options. by default we look into files with single export | |
var _ref = context.options[0] || {},_ref$target = _ref.target,target = _ref$target === undefined ? 'single' : _ref$target; | |
function captureDeclaration(identifierOrPattern) { | |
if (identifierOrPattern && identifierOrPattern.type === 'ObjectPattern') { | |
// recursively capture | |
identifierOrPattern.properties. | |
forEach(function (property) { | |
captureDeclaration(property.value); | |
}); | |
} else if (identifierOrPattern && identifierOrPattern.type === 'ArrayPattern') { | |
identifierOrPattern.elements. | |
forEach(captureDeclaration); | |
} else { | |
// assume it's a single standard identifier | |
specifierExportCount++; | |
} | |
} | |
return { | |
ExportDefaultSpecifier: function () {function ExportDefaultSpecifier() { | |
hasDefaultExport = true; | |
}return ExportDefaultSpecifier;}(), | |
ExportSpecifier: function () {function ExportSpecifier(node) { | |
if ((node.exported.name || node.exported.value) === 'default') { | |
hasDefaultExport = true; | |
} else { | |
specifierExportCount++; | |
namedExportNode = node; | |
} | |
}return ExportSpecifier;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
// if there are specifiers, node.declaration should be null | |
if (!node.declaration) {return;}var | |
type = node.declaration.type; | |
if ( | |
type === 'TSTypeAliasDeclaration' || | |
type === 'TypeAlias' || | |
type === 'TSInterfaceDeclaration' || | |
type === 'InterfaceDeclaration') | |
{ | |
specifierExportCount++; | |
hasTypeExport = true; | |
return; | |
} | |
if (node.declaration.declarations) { | |
node.declaration.declarations.forEach(function (declaration) { | |
captureDeclaration(declaration.id); | |
}); | |
} else { | |
// captures 'export function foo() {}' syntax | |
specifierExportCount++; | |
} | |
namedExportNode = node; | |
}return ExportNamedDeclaration;}(), | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration() { | |
hasDefaultExport = true; | |
}return ExportDefaultDeclaration;}(), | |
ExportAllDeclaration: function () {function ExportAllDeclaration() { | |
hasStarExport = true; | |
}return ExportAllDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() { | |
if (hasDefaultExport || hasStarExport || hasTypeExport) { | |
return; | |
} | |
if (target === 'single' && specifierExportCount === 1) { | |
context.report(namedExportNode, SINGLE_EXPORT_ERROR_MESSAGE); | |
} else if (target === 'any' && specifierExportCount > 0) { | |
context.report(namedExportNode, ANY_EXPORT_ERROR_MESSAGE); | |
} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-default-export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
var preferNamed = 'Prefer named exports.'; | |
var noAliasDefault = function () {function noAliasDefault(_ref) {var local = _ref.local;return 'Do not alias `' + String(local.name) + '` as `default`. Just export `' + String(local.name) + '` itself instead.';}return noAliasDefault;}(); | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) {var _ref2 = | |
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref2.loc; | |
context.report({ node: node, message: preferNamed, loc: loc }); | |
}return ExportDefaultDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
node.specifiers. | |
filter(function (specifier) {return (specifier.exported.name || specifier.exported.value) === 'default';}). | |
forEach(function (specifier) {var _ref3 = | |
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref3.loc; | |
if (specifier.type === 'ExportDefaultSpecifier') { | |
context.report({ node: node, message: preferNamed, loc: loc }); | |
} else if (specifier.type === 'ExportSpecifier') { | |
context.report({ node: node, message: noAliasDefault(specifier), loc: loc }); | |
} | |
}); | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-named-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid named exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
var message = 'Named exports are not allowed.'; | |
return { | |
ExportAllDeclaration: function () {function ExportAllDeclaration(node) { | |
context.report({ node: node, message: message }); | |
}return ExportAllDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
if (node.specifiers.length === 0) { | |
return context.report({ node: node, message: message }); | |
} | |
var someNamed = node.specifiers.some(function (specifier) {return (specifier.exported.name || specifier.exported.value) !== 'default';}); | |
if (someNamed) { | |
context.report({ node: node, message: message }); | |
} | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-dynamic-require": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid `require()` calls with expressions.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-dynamic-require.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
esmodule: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
return { | |
CallExpression: function () {function CallExpression(node) { | |
if (!node.arguments[0] || isStaticValue(node.arguments[0])) { | |
return; | |
} | |
if (isRequire(node)) { | |
return context.report({ | |
node: node, | |
message: 'Calls to require() should use string literals' }); | |
} | |
if (options.esmodule && isDynamicImport(node)) { | |
return context.report({ | |
node: node, | |
message: dynamicImportErrorMessage }); | |
} | |
}return CallExpression;}(), | |
ImportExpression: function () {function ImportExpression(node) { | |
if (!options.esmodule || isStaticValue(node.source)) { | |
return; | |
} | |
return context.report({ | |
node: node, | |
message: dynamicImportErrorMessage }); | |
}return ImportExpression;}() }; | |
}, | |
}, | |
unambiguous: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid potentially ambiguous parse goal (`script` vs. `module`).", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/unambiguous.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
return { | |
Program: function () {function Program(ast) { | |
if (!(0, _unambiguous.isModule)(ast)) { | |
context.report({ | |
node: ast, | |
message: 'This module could be parsed as a valid script.' }); | |
} | |
}return Program;}() }; | |
}, | |
}, | |
"no-unassigned-import": { | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var isAllow = function isAllow(source) {return testIsAllow(options.allow, filename, source);}; | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (node.specifiers.length === 0 && !isAllow(node.source.value)) { | |
report(context, node); | |
} | |
}return ImportDeclaration;}(), | |
ExpressionStatement: function () {function ExpressionStatement(node) { | |
if ( | |
node.expression.type === 'CallExpression' && | |
(0, _staticRequire2['default'])(node.expression) && | |
!isAllow(node.expression.arguments[0].value)) | |
{ | |
report(context, node.expression); | |
} | |
}return ExpressionStatement;}() }; | |
}, | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid unassigned imports", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unassigned-import.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
devDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
optionalDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
peerDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-useless-path-segments": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid unnecessary path segments in import and require statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-useless-path-segments.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
noUselessIndex: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var currentDir = _path2['default'].dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()); | |
var options = context.options[0]; | |
function checkSourceValue(source) {var | |
importPath = source.value; | |
function reportWithProposedPath(proposedPath) { | |
context.report({ | |
node: source, | |
// Note: Using messageIds is not possible due to the support for ESLint 2 and 3 | |
message: 'Useless path segments for "' + String(importPath) + '", should be "' + String(proposedPath) + '"', | |
fix: function () {function fix(fixer) {return proposedPath && fixer.replaceText(source, JSON.stringify(proposedPath));}return fix;}() }); | |
} | |
// Only relative imports are relevant for this rule --> Skip checking | |
if (!importPath.startsWith('.')) { | |
return; | |
} | |
// Report rule violation if path is not the shortest possible | |
var resolvedPath = (0, _resolve2['default'])(importPath, context); | |
var normedPath = normalize(importPath); | |
var resolvedNormedPath = (0, _resolve2['default'])(normedPath, context); | |
if (normedPath !== importPath && resolvedPath === resolvedNormedPath) { | |
return reportWithProposedPath(normedPath); | |
} | |
var fileExtensions = (0, _ignore.getFileExtensions)(context.settings); | |
var regexUnnecessaryIndex = new RegExp('.*\\/index(\\' + String( | |
Array.from(fileExtensions).join('|\\')) + ')?$'); | |
// Check if path contains unnecessary index (including a configured extension) | |
if (options && options.noUselessIndex && regexUnnecessaryIndex.test(importPath)) { | |
var parentDirectory = _path2['default'].dirname(importPath); | |
// Try to find ambiguous imports | |
if (parentDirectory !== '.' && parentDirectory !== '..') {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = fileExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var fileExtension = _step.value; | |
if ((0, _resolve2['default'])('' + String(parentDirectory) + String(fileExtension), context)) { | |
return reportWithProposedPath(String(parentDirectory) + '/'); | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
return reportWithProposedPath(parentDirectory); | |
} | |
// Path is shortest possible + starts from the current directory --> Return directly | |
if (importPath.startsWith('./')) { | |
return; | |
} | |
// Path is not existing --> Return directly (following code requires path to be defined) | |
if (resolvedPath === undefined) { | |
return; | |
} | |
var expected = _path2['default'].relative(currentDir, resolvedPath); // Expected import path | |
var expectedSplit = expected.split(_path2['default'].sep); // Split by / or \ (depending on OS) | |
var importPathSplit = importPath.replace(/^\.\//, '').split('/'); | |
var countImportPathRelativeParents = countRelativeParents(importPathSplit); | |
var countExpectedRelativeParents = countRelativeParents(expectedSplit); | |
var diff = countImportPathRelativeParents - countExpectedRelativeParents; | |
// Same number of relative parents --> Paths are the same --> Return directly | |
if (diff <= 0) { | |
return; | |
} | |
// Report and propose minimal number of required relative parents | |
return reportWithProposedPath( | |
toRelativePath( | |
importPathSplit. | |
slice(0, countExpectedRelativeParents). | |
concat(importPathSplit.slice(countImportPathRelativeParents + diff)). | |
join('/'))); | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, options); | |
}, | |
}, | |
"dynamic-import-chunkname": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a leading comment with the webpackChunkName for dynamic imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/dynamic-import-chunkname.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
importFunctions: { | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
webpackChunknameFormat: { | |
type: "string", | |
}, | |
}, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var config = context.options[0];var _ref = | |
config || {},_ref$importFunctions = _ref.importFunctions,importFunctions = _ref$importFunctions === undefined ? [] : _ref$importFunctions;var _ref2 = | |
config || {},_ref2$webpackChunknam = _ref2.webpackChunknameFormat,webpackChunknameFormat = _ref2$webpackChunknam === undefined ? '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' : _ref2$webpackChunknam; | |
var paddedCommentRegex = /^ (\S[\s\S]+\S) $/; | |
var commentStyleRegex = /^( ((webpackChunkName: .+)|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/; | |
var chunkSubstrFormat = ' webpackChunkName: ["\']' + String(webpackChunknameFormat) + '["\'],? '; | |
var chunkSubstrRegex = new RegExp(chunkSubstrFormat); | |
function run(node, arg) { | |
var sourceCode = context.getSourceCode(); | |
var leadingComments = sourceCode.getCommentsBefore ? | |
sourceCode.getCommentsBefore(arg) // This method is available in ESLint >= 4. | |
: sourceCode.getComments(arg).leading; // This method is deprecated in ESLint 7. | |
if (!leadingComments || leadingComments.length === 0) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a leading comment with the webpack chunkname' }); | |
return; | |
} | |
var isChunknamePresent = false;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = leadingComments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var comment = _step.value; | |
if (comment.type !== 'Block') { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a /* foo */ style comment, not a // foo comment' }); | |
return; | |
} | |
if (!paddedCommentRegex.test(comment.value)) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a block comment padded with spaces - /* foo */' }); | |
return; | |
} | |
try { | |
// just like webpack itself does | |
_vm2['default'].runInNewContext('(function() {return {' + String(comment.value) + '}})()'); | |
} catch (error) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a "webpack" comment with valid syntax' }); | |
return; | |
} | |
if (!commentStyleRegex.test(comment.value)) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a "webpack" comment with valid syntax' }); | |
return; | |
} | |
if (chunkSubstrRegex.test(comment.value)) { | |
isChunknamePresent = true; | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
if (!isChunknamePresent) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a leading comment in the form /*' + | |
chunkSubstrFormat + '*/' }); | |
} | |
} | |
return { | |
ImportExpression: function () {function ImportExpression(node) { | |
run(node, node.source); | |
}return ImportExpression;}(), | |
CallExpression: function () {function CallExpression(node) { | |
if (node.callee.type !== 'Import' && importFunctions.indexOf(node.callee.name) < 0) { | |
return; | |
} | |
run(node, node.arguments[0]); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-import-module-exports": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Module systems", | |
description: "Forbid import statements with CommonJS module.exports.", | |
recommended: true, | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
exceptions: { | |
type: "array", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var importDeclarations = []; | |
var entryPoint = getEntryPoint(context); | |
var options = context.options[0] || {}; | |
var alreadyReported = false; | |
function report(node) { | |
var fileName = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var isEntryPoint = entryPoint === fileName; | |
var isIdentifier = node.object.type === 'Identifier'; | |
var hasKeywords = /^(module|exports)$/.test(node.object.name); | |
var objectScope = hasKeywords && findScope(context, node.object.name); | |
var variableDefinition = objectScope && findDefinition(objectScope, node.object.name); | |
var isImportBinding = variableDefinition && variableDefinition.type === 'ImportBinding'; | |
var hasCJSExportReference = hasKeywords && (!objectScope || objectScope.type === 'module'); | |
var isException = !!options.exceptions && options.exceptions.some(function (glob) {return (0, _minimatch2['default'])(fileName, glob);}); | |
if (isIdentifier && hasCJSExportReference && !isEntryPoint && !isException && !isImportBinding) { | |
importDeclarations.forEach(function (importDeclaration) { | |
context.report({ | |
node: importDeclaration, | |
message: 'Cannot use import declarations in modules that export using CommonJS (module.exports = \'foo\' or exports.bar = \'hi\')' }); | |
}); | |
alreadyReported = true; | |
} | |
} | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
importDeclarations.push(node); | |
}return ImportDeclaration;}(), | |
MemberExpression: function () {function MemberExpression(node) { | |
if (!alreadyReported) { | |
report(node); | |
} | |
}return MemberExpression;}() }; | |
}, | |
}, | |
"no-empty-named-blocks": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid empty named import blocks.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-empty-named-blocks.md", | |
}, | |
fixable: "code", | |
schema: [ | |
], | |
hasSuggestions: true, | |
}, | |
create: function create(context) { | |
var importsWithoutNameds = []; | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (!node.specifiers.some(function (x) {return x.type === 'ImportSpecifier';})) { | |
importsWithoutNameds.push(node); | |
} | |
}return ImportDeclaration;}(), | |
'Program:exit': function () {function ProgramExit(program) { | |
var importsTokens = importsWithoutNameds.map(function (node) {return [node, program.tokens.filter(function (x) {return x.range[0] >= node.range[0] && x.range[1] <= node.range[1];})];}); | |
importsTokens.forEach(function (_ref) {var _ref2 = _slicedToArray(_ref, 2),node = _ref2[0],tokens = _ref2[1]; | |
tokens.forEach(function (token) { | |
var idx = program.tokens.indexOf(token); | |
var nextToken = program.tokens[idx + 1]; | |
if (nextToken && token.value === '{' && nextToken.value === '}') { | |
var hasOtherIdentifiers = tokens.some(function (token) {return token.type === 'Identifier' && | |
token.value !== 'from' && | |
token.value !== 'type' && | |
token.value !== 'typeof';}); | |
// If it has no other identifiers it's the only thing in the import, so we can either remove the import | |
// completely or transform it in a side-effects only import | |
if (!hasOtherIdentifiers) { | |
context.report({ | |
node: node, | |
message: 'Unexpected empty named import block', | |
suggest: [ | |
{ | |
desc: 'Remove unused import', | |
fix: function () {function fix(fixer) { | |
// Remove the whole import | |
return fixer.remove(node); | |
}return fix;}() }, | |
{ | |
desc: 'Remove empty import block', | |
fix: function () {function fix(fixer) { | |
// Remove the empty block and the 'from' token, leaving the import only for its side | |
// effects, e.g. `import 'mod'` | |
var sourceCode = context.getSourceCode(); | |
var fromToken = program.tokens.find(function (t) {return t.value === 'from';}); | |
var importToken = program.tokens.find(function (t) {return t.value === 'import';}); | |
var hasSpaceAfterFrom = sourceCode.isSpaceBetween(fromToken, sourceCode.getTokenAfter(fromToken)); | |
var hasSpaceAfterImport = sourceCode.isSpaceBetween(importToken, sourceCode.getTokenAfter(fromToken));var _getEmptyBlockRange = | |
getEmptyBlockRange(program.tokens, idx),_getEmptyBlockRange2 = _slicedToArray(_getEmptyBlockRange, 1),start = _getEmptyBlockRange2[0];var _fromToken$range = _slicedToArray( | |
fromToken.range, 2),end = _fromToken$range[1]; | |
var range = [start, hasSpaceAfterFrom ? end + 1 : end]; | |
return fixer.replaceTextRange(range, hasSpaceAfterImport ? '' : ' '); | |
}return fix;}() }] }); | |
} else { | |
context.report({ | |
node: node, | |
message: 'Unexpected empty named import block', | |
fix: function () {function fix(fixer) { | |
return fixer.removeRange(getEmptyBlockRange(program.tokens, idx)); | |
}return fix;}() }); | |
} | |
} | |
}); | |
}); | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"exports-last": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure all exports appear after other statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/exports-last.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
Program: function () {function Program(_ref2) {var body = _ref2.body; | |
var lastNonExportStatementIndex = (0, _arrayPrototype2['default'])(body, isNonExportStatement); | |
if (lastNonExportStatementIndex !== -1) { | |
body.slice(0, lastNonExportStatementIndex).forEach(function (node) { | |
if (!isNonExportStatement(node)) { | |
context.report({ | |
node: node, | |
message: 'Export statements should appear at the end of the file' }); | |
} | |
}); | |
} | |
}return Program;}() }; | |
}, | |
}, | |
"no-deprecated": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid imported names marked with `@deprecated` documentation tag.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-deprecated.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var deprecated = new Map(); | |
var namespaces = new Map(); | |
function checkSpecifiers(node) { | |
if (node.type !== 'ImportDeclaration') {return;} | |
if (node.source == null) {return;} // local export, ignore | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null) {return;} | |
var moduleDeprecation = imports.doc && imports.doc.tags.find(function (t) {return t.title === 'deprecated';}); | |
if (moduleDeprecation) { | |
context.report({ node: node, message: message(moduleDeprecation) }); | |
} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
return; | |
} | |
node.specifiers.forEach(function (im) { | |
var imported = void 0;var local = void 0; | |
switch (im.type) { | |
case 'ImportNamespaceSpecifier':{ | |
if (!imports.size) {return;} | |
namespaces.set(im.local.name, imports); | |
return; | |
} | |
case 'ImportDefaultSpecifier': | |
imported = 'default'; | |
local = im.local.name; | |
break; | |
case 'ImportSpecifier': | |
imported = im.imported.name; | |
local = im.local.name; | |
break; | |
default:return; // can't handle this one | |
} | |
// unknown thing can't be deprecated | |
var exported = imports.get(imported); | |
if (exported == null) {return;} | |
// capture import of deep namespace | |
if (exported.namespace) {namespaces.set(local, exported.namespace);} | |
var deprecation = getDeprecation(imports.get(imported)); | |
if (!deprecation) {return;} | |
context.report({ node: im, message: message(deprecation) }); | |
deprecated.set(local, deprecation); | |
}); | |
} | |
return { | |
Program: function () {function Program(_ref) {var body = _ref.body;return body.forEach(checkSpecifiers);}return Program;}(), | |
Identifier: function () {function Identifier(node) { | |
if (node.parent.type === 'MemberExpression' && node.parent.property === node) { | |
return; // handled by MemberExpression | |
} | |
// ignore specifier identifiers | |
if (node.parent.type.slice(0, 6) === 'Import') {return;} | |
if (!deprecated.has(node.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, node.name) !== 'module') {return;} | |
context.report({ | |
node: node, | |
message: message(deprecated.get(node.name)) }); | |
}return Identifier;}(), | |
MemberExpression: function () {function MemberExpression(dereference) { | |
if (dereference.object.type !== 'Identifier') {return;} | |
if (!namespaces.has(dereference.object.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') {return;} | |
// go deep | |
var namespace = namespaces.get(dereference.object.name); | |
var namepath = [dereference.object.name]; | |
// while property is namespace and parent is member expression, keep validating | |
while (namespace instanceof _ExportMap2['default'] && dereference.type === 'MemberExpression') { | |
// ignore computed parts for now | |
if (dereference.computed) {return;} | |
var metadata = namespace.get(dereference.property.name); | |
if (!metadata) {break;} | |
var deprecation = getDeprecation(metadata); | |
if (deprecation) { | |
context.report({ node: dereference.property, message: message(deprecation) }); | |
} | |
// stash and pop | |
namepath.push(dereference.property.name); | |
namespace = metadata.namespace; | |
dereference = dereference.parent; | |
} | |
}return MemberExpression;}() }; | |
}, | |
}, | |
"imports-first": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Replaced by `import/first`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/7b25c1cb95ee18acc1531002fd343e1e6031f9ed/docs/rules/imports-first.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"absolute-first", | |
"disable-absolute-first", | |
], | |
}, | |
], | |
deprecated: true, | |
}, | |
create: function create(context) { | |
function isPossibleDirective(node) { | |
return node.type === 'ExpressionStatement' && | |
node.expression.type === 'Literal' && | |
typeof node.expression.value === 'string'; | |
} | |
return { | |
Program: function () {function Program(n) { | |
var body = n.body; | |
if (!body) { | |
return; | |
} | |
var absoluteFirst = context.options[0] === 'absolute-first'; | |
var message = 'Import in body of module; reorder to top.'; | |
var sourceCode = context.getSourceCode(); | |
var originSourceCode = sourceCode.getText(); | |
var nonImportCount = 0; | |
var anyExpressions = false; | |
var anyRelative = false; | |
var lastLegalImp = null; | |
var errorInfos = []; | |
var shouldSort = true; | |
var lastSortNodesIndex = 0; | |
body.forEach(function (node, index) { | |
if (!anyExpressions && isPossibleDirective(node)) { | |
return; | |
} | |
anyExpressions = true; | |
if (node.type === 'ImportDeclaration' || node.type === 'TSImportEqualsDeclaration') { | |
if (absoluteFirst) { | |
if (/^\./.test(getImportValue(node))) { | |
anyRelative = true; | |
} else if (anyRelative) { | |
context.report({ | |
node: node.type === 'ImportDeclaration' ? node.source : node.moduleReference, | |
message: 'Absolute imports should come before relative imports.' }); | |
} | |
} | |
if (nonImportCount > 0) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = context.getDeclaredVariables(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (!shouldSort) {break;} | |
var references = variable.references; | |
if (references.length) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = references[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var reference = _step2.value; | |
if (reference.identifier.range[0] < node.range[1]) { | |
shouldSort = false; | |
break; | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
shouldSort && (lastSortNodesIndex = errorInfos.length); | |
errorInfos.push({ | |
node: node, | |
range: [body[index - 1].range[1], node.range[1]] }); | |
} else { | |
lastLegalImp = node; | |
} | |
} else { | |
nonImportCount++; | |
} | |
}); | |
if (!errorInfos.length) {return;} | |
errorInfos.forEach(function (errorInfo, index) { | |
var node = errorInfo.node; | |
var infos = { | |
node: node, | |
message: message }; | |
if (index < lastSortNodesIndex) { | |
infos.fix = function (fixer) { | |
return fixer.insertTextAfter(node, ''); | |
}; | |
} else if (index === lastSortNodesIndex) { | |
var sortNodes = errorInfos.slice(0, lastSortNodesIndex + 1); | |
infos.fix = function (fixer) { | |
var removeFixers = sortNodes.map(function (_errorInfo) { | |
return fixer.removeRange(_errorInfo.range); | |
}); | |
var range = [0, removeFixers[removeFixers.length - 1].range[1]]; | |
var insertSourceCode = sortNodes.map(function (_errorInfo) { | |
var nodeSourceCode = String.prototype.slice.apply( | |
originSourceCode, _errorInfo.range); | |
if (/\S/.test(nodeSourceCode[0])) { | |
return '\n' + String(nodeSourceCode); | |
} | |
return nodeSourceCode; | |
}).join(''); | |
var insertFixer = null; | |
var replaceSourceCode = ''; | |
if (!lastLegalImp) { | |
insertSourceCode = insertSourceCode.trim() + insertSourceCode.match(/^(\s+)/)[0]; | |
} | |
insertFixer = lastLegalImp ? | |
fixer.insertTextAfter(lastLegalImp, insertSourceCode) : | |
fixer.insertTextBefore(body[0], insertSourceCode); | |
var fixers = [insertFixer].concat(removeFixers); | |
fixers.forEach(function (computedFixer, i) { | |
replaceSourceCode += originSourceCode.slice( | |
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]) + | |
computedFixer.text; | |
}); | |
return fixer.replaceTextRange(range, replaceSourceCode); | |
}; | |
} | |
context.report(infos); | |
}); | |
}return Program;}() }; | |
}, | |
}, | |
}, | |
}, | |
original: { | |
rules: { | |
"no-unresolved": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure imports point to a file/module that can be resolved.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unresolved.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
caseSensitive: { | |
type: "boolean", | |
default: true, | |
}, | |
caseSensitiveStrict: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
function checkSourceValue(source, node) { | |
// ignore type-only imports and exports | |
if (node.importKind === 'type' || node.exportKind === 'type') { | |
return; | |
} | |
var caseSensitive = !_resolve.CASE_SENSITIVE_FS && options.caseSensitive !== false; | |
var caseSensitiveStrict = !_resolve.CASE_SENSITIVE_FS && options.caseSensitiveStrict; | |
var resolvedPath = (0, _resolve2['default'])(source.value, context); | |
if (resolvedPath === undefined) { | |
context.report( | |
source, 'Unable to resolve path to module \'' + String( | |
source.value) + '\'.'); | |
} else if (caseSensitive || caseSensitiveStrict) { | |
var cacheSettings = _ModuleCache2['default'].getSettings(context.settings); | |
if (!(0, _resolve.fileExistsWithCaseSync)(resolvedPath, cacheSettings, caseSensitiveStrict)) { | |
context.report( | |
source, 'Casing of ' + String( | |
source.value) + ' does not match the underlying filesystem.'); | |
} | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, options); | |
}, | |
}, | |
named: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure named imports correspond to a named export in the remote file.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/named.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
function checkSpecifiers(key, type, node) { | |
// ignore local exports and type imports/exports | |
if ( | |
node.source == null || | |
node.importKind === 'type' || | |
node.importKind === 'typeof' || | |
node.exportKind === 'type') | |
{ | |
return; | |
} | |
if (!node.specifiers.some(function (im) {return im.type === type;})) { | |
return; // no named imports/exports | |
} | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null || imports.parseGoal === 'ambiguous') { | |
return; | |
} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
return; | |
} | |
node.specifiers.forEach(function (im) { | |
if ( | |
im.type !== type | |
// ignore type imports | |
|| im.importKind === 'type' || im.importKind === 'typeof') | |
{ | |
return; | |
} | |
var name = im[key].name || im[key].value; | |
var deepLookup = imports.hasDeep(name); | |
if (!deepLookup.found) { | |
if (deepLookup.path.length > 1) { | |
var deepPath = deepLookup.path. | |
map(function (i) {return path.relative(path.dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()), i.path);}). | |
join(' -> '); | |
context.report(im[key], String(name) + ' not found via ' + String(deepPath)); | |
} else { | |
context.report(im[key], String(name) + ' not found in \'' + String(node.source.value) + '\''); | |
} | |
} | |
}); | |
} | |
function checkRequire(node) { | |
if ( | |
!options.commonjs || | |
node.type !== 'VariableDeclarator' | |
// return if it's not an object destructure or it's an empty object destructure | |
|| !node.id || node.id.type !== 'ObjectPattern' || node.id.properties.length === 0 | |
// return if there is no call expression on the right side | |
|| !node.init || node.init.type !== 'CallExpression') | |
{ | |
return; | |
} | |
var call = node.init;var _call$arguments = _slicedToArray( | |
call.arguments, 1),source = _call$arguments[0]; | |
var variableImports = node.id.properties; | |
var variableExports = _ExportMap2['default'].get(source.value, context); | |
if ( | |
// return if it's not a commonjs require statement | |
call.callee.type !== 'Identifier' || call.callee.name !== 'require' || call.arguments.length !== 1 | |
// return if it's not a string source | |
|| source.type !== 'Literal' || | |
variableExports == null || | |
variableExports.parseGoal === 'ambiguous') | |
{ | |
return; | |
} | |
if (variableExports.errors.length) { | |
variableExports.reportErrors(context, node); | |
return; | |
} | |
variableImports.forEach(function (im) { | |
if (im.type !== 'Property' || !im.key || im.key.type !== 'Identifier') { | |
return; | |
} | |
var deepLookup = variableExports.hasDeep(im.key.name); | |
if (!deepLookup.found) { | |
if (deepLookup.path.length > 1) { | |
var deepPath = deepLookup.path. | |
map(function (i) {return path.relative(path.dirname(context.getFilename()), i.path);}). | |
join(' -> '); | |
context.report(im.key, String(im.key.name) + ' not found via ' + String(deepPath)); | |
} else { | |
context.report(im.key, String(im.key.name) + ' not found in \'' + String(source.value) + '\''); | |
} | |
} | |
}); | |
} | |
return { | |
ImportDeclaration: checkSpecifiers.bind(null, 'imported', 'ImportSpecifier'), | |
ExportNamedDeclaration: checkSpecifiers.bind(null, 'local', 'ExportSpecifier'), | |
VariableDeclarator: checkRequire }; | |
}, | |
}, | |
default: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure a default export is present, given a default import.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDefault(specifierType, node) { | |
var defaultSpecifier = node.specifiers.find( | |
function (specifier) {return specifier.type === specifierType;}); | |
if (!defaultSpecifier) {return;} | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null) {return;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
} else if (imports.get('default') === undefined) { | |
context.report({ | |
node: defaultSpecifier, | |
message: 'No default export found in imported module "' + String(node.source.value) + '".' }); | |
} | |
} | |
return { | |
ImportDeclaration: checkDefault.bind(null, 'ImportDefaultSpecifier'), | |
ExportNamedDeclaration: checkDefault.bind(null, 'ExportDefaultSpecifier') }; | |
}, | |
}, | |
namespace: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Ensure imported namespaces contain dereferenced properties as they are dereferenced.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/namespace.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowComputed: { | |
description: "If `false`, will report computed (and thus, un-lintable) references to namespace members.", | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function namespaceRule(context) { | |
// read options | |
var _ref = | |
context.options[0] || {},_ref$allowComputed = _ref.allowComputed,allowComputed = _ref$allowComputed === undefined ? false : _ref$allowComputed; | |
var namespaces = new Map(); | |
function makeMessage(last, namepath) { | |
return '\'' + String(last.name) + '\' not found in ' + (namepath.length > 1 ? 'deeply ' : '') + 'imported namespace \'' + String(namepath.join('.')) + '\'.'; | |
} | |
return { | |
// pick up all imports at body entry time, to properly respect hoisting | |
Program: function () {function Program(_ref2) {var body = _ref2.body; | |
body.forEach(function (x) {processBodyStatement(context, namespaces, x);}); | |
}return Program;}(), | |
// same as above, but does not add names to local map | |
ExportNamespaceSpecifier: function () {function ExportNamespaceSpecifier(namespace) { | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var imports = _ExportMap2['default'].get(declaration.source.value, context); | |
if (imports == null) {return null;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, declaration); | |
return; | |
} | |
if (!imports.size) { | |
context.report( | |
namespace, 'No exported names found in module \'' + String( | |
declaration.source.value) + '\'.'); | |
} | |
}return ExportNamespaceSpecifier;}(), | |
// todo: check for possible redefinition | |
MemberExpression: function () {function MemberExpression(dereference) { | |
if (dereference.object.type !== 'Identifier') {return;} | |
if (!namespaces.has(dereference.object.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') {return;} | |
if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) { | |
context.report( | |
dereference.parent, 'Assignment to member of namespace \'' + String( | |
dereference.object.name) + '\'.'); | |
} | |
// go deep | |
var namespace = namespaces.get(dereference.object.name); | |
var namepath = [dereference.object.name]; | |
// while property is namespace and parent is member expression, keep validating | |
while (namespace instanceof _ExportMap2['default'] && dereference.type === 'MemberExpression') { | |
if (dereference.computed) { | |
if (!allowComputed) { | |
context.report( | |
dereference.property, 'Unable to validate computed reference to imported namespace \'' + String( | |
dereference.object.name) + '\'.'); | |
} | |
return; | |
} | |
if (!namespace.has(dereference.property.name)) { | |
context.report( | |
dereference.property, | |
makeMessage(dereference.property, namepath)); | |
break; | |
} | |
var exported = namespace.get(dereference.property.name); | |
if (exported == null) {return;} | |
// stash and pop | |
namepath.push(dereference.property.name); | |
namespace = exported.namespace; | |
dereference = dereference.parent; | |
} | |
}return MemberExpression;}(), | |
VariableDeclarator: function () {function VariableDeclarator(_ref3) {var id = _ref3.id,init = _ref3.init; | |
if (init == null) {return;} | |
if (init.type !== 'Identifier') {return;} | |
if (!namespaces.has(init.name)) {return;} | |
// check for redefinition in intermediate scopes | |
if ((0, _declaredScope2['default'])(context, init.name) !== 'module') {return;} | |
// DFS traverse child namespaces | |
function testKey(pattern, namespace) {var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [init.name]; | |
if (!(namespace instanceof _ExportMap2['default'])) {return;} | |
if (pattern.type !== 'ObjectPattern') {return;}var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = pattern.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var property = _step.value; | |
if ( | |
property.type === 'ExperimentalRestProperty' || | |
property.type === 'RestElement' || | |
!property.key) | |
{ | |
continue; | |
} | |
if (property.key.type !== 'Identifier') { | |
context.report({ | |
node: property, | |
message: 'Only destructure top-level names.' }); | |
continue; | |
} | |
if (!namespace.has(property.key.name)) { | |
context.report({ | |
node: property, | |
message: makeMessage(property.key, path) }); | |
continue; | |
} | |
path.push(property.key.name); | |
var dependencyExportMap = namespace.get(property.key.name); | |
// could be null when ignored or ambiguous | |
if (dependencyExportMap !== null) { | |
testKey(property.value, dependencyExportMap.namespace, path); | |
} | |
path.pop(); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
testKey(id, namespaces.get(init.name)); | |
}return VariableDeclarator;}(), | |
JSXMemberExpression: function () {function JSXMemberExpression(_ref4) {var object = _ref4.object,property = _ref4.property; | |
if (!namespaces.has(object.name)) {return;} | |
var namespace = namespaces.get(object.name); | |
if (!namespace.has(property.name)) { | |
context.report({ | |
node: property, | |
message: makeMessage(property, [object.name]) }); | |
} | |
}return JSXMemberExpression;}() }; | |
}, | |
}, | |
"no-namespace": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid namespace (a.k.a. \"wildcard\" `*`) imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-namespace.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignore: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var firstOption = context.options[0] || {}; | |
var ignoreGlobs = firstOption.ignore; | |
return { | |
ImportNamespaceSpecifier: function () {function ImportNamespaceSpecifier(node) { | |
if (ignoreGlobs && ignoreGlobs.find(function (glob) {return (0, _minimatch2['default'])(node.parent.source.value, glob, { matchBase: true });})) { | |
return; | |
} | |
var scopeVariables = context.getScope().variables; | |
var namespaceVariable = scopeVariables.find(function (variable) {return variable.defs[0].node === node;}); | |
var namespaceReferences = namespaceVariable.references; | |
var namespaceIdentifiers = namespaceReferences.map(function (reference) {return reference.identifier;}); | |
var canFix = namespaceIdentifiers.length > 0 && !usesNamespaceAsObject(namespaceIdentifiers); | |
context.report({ | |
node: node, | |
message: 'Unexpected namespace import.', | |
fix: canFix && function (fixer) { | |
var scopeManager = context.getSourceCode().scopeManager; | |
var fixes = []; | |
// Pass 1: Collect variable names that are already in scope for each reference we want | |
// to transform, so that we can be sure that we choose non-conflicting import names | |
var importNameConflicts = {}; | |
namespaceIdentifiers.forEach(function (identifier) { | |
var parent = identifier.parent; | |
if (parent && parent.type === 'MemberExpression') { | |
var importName = getMemberPropertyName(parent); | |
var localConflicts = getVariableNamesInScope(scopeManager, parent); | |
if (!importNameConflicts[importName]) { | |
importNameConflicts[importName] = localConflicts; | |
} else { | |
localConflicts.forEach(function (c) {return importNameConflicts[importName].add(c);}); | |
} | |
} | |
}); | |
// Choose new names for each import | |
var importNames = Object.keys(importNameConflicts); | |
var importLocalNames = generateLocalNames( | |
importNames, | |
importNameConflicts, | |
namespaceVariable.name); | |
// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers | |
var namedImportSpecifiers = importNames.map(function (importName) {return importName === importLocalNames[importName] ? | |
importName : String( | |
importName) + ' as ' + String(importLocalNames[importName]);}); | |
fixes.push(fixer.replaceText(node, '{ ' + String(namedImportSpecifiers.join(', ')) + ' }')); | |
// Pass 2: Replace references to the namespace with references to the named imports | |
namespaceIdentifiers.forEach(function (identifier) { | |
var parent = identifier.parent; | |
if (parent && parent.type === 'MemberExpression') { | |
var importName = getMemberPropertyName(parent); | |
fixes.push(fixer.replaceText(parent, importLocalNames[importName])); | |
} | |
}); | |
return fixes; | |
} }); | |
}return ImportNamespaceSpecifier;}() }; | |
}, | |
}, | |
export: { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid any invalid exports, i.e. re-export of the same name.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var namespace = new Map([[rootProgram, new Map()]]); | |
function addNamed(name, node, parent, isType) { | |
if (!namespace.has(parent)) { | |
namespace.set(parent, new Map()); | |
} | |
var named = namespace.get(parent); | |
var key = isType ? '' + tsTypePrefix + String(name) : name; | |
var nodes = named.get(key); | |
if (nodes == null) { | |
nodes = new Set(); | |
named.set(key, nodes); | |
} | |
nodes.add(node); | |
} | |
function getParent(node) { | |
if (node.parent && node.parent.type === 'TSModuleBlock') { | |
return node.parent.parent; | |
} | |
// just in case somehow a non-ts namespace export declaration isn't directly | |
// parented to the root Program node | |
return rootProgram; | |
} | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
addNamed('default', node, getParent(node)); | |
}return ExportDefaultDeclaration;}(), | |
ExportSpecifier: function () {function ExportSpecifier(node) { | |
addNamed( | |
node.exported.name || node.exported.value, | |
node.exported, | |
getParent(node.parent)); | |
}return ExportSpecifier;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
if (node.declaration == null) {return;} | |
var parent = getParent(node); | |
// support for old TypeScript versions | |
var isTypeVariableDecl = node.declaration.kind === 'type'; | |
if (node.declaration.id != null) { | |
if ((0, _arrayIncludes2['default'])([ | |
'TSTypeAliasDeclaration', | |
'TSInterfaceDeclaration'], | |
node.declaration.type)) { | |
addNamed(node.declaration.id.name, node.declaration.id, parent, true); | |
} else { | |
addNamed(node.declaration.id.name, node.declaration.id, parent, isTypeVariableDecl); | |
} | |
} | |
if (node.declaration.declarations != null) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = node.declaration.declarations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var declaration = _step.value; | |
(0, _ExportMap.recursivePatternCapture)(declaration.id, function (v) {addNamed(v.name, v, parent, isTypeVariableDecl);}); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
}return ExportNamedDeclaration;}(), | |
ExportAllDeclaration: function () {function ExportAllDeclaration(node) { | |
if (node.source == null) {return;} // not sure if this is ever true | |
// `export * as X from 'path'` does not conflict | |
if (node.exported && node.exported.name) {return;} | |
var remoteExports = _ExportMap2['default'].get(node.source.value, context); | |
if (remoteExports == null) {return;} | |
if (remoteExports.errors.length) { | |
remoteExports.reportErrors(context, node); | |
return; | |
} | |
var parent = getParent(node); | |
var any = false; | |
remoteExports.forEach(function (v, name) { | |
if (name !== 'default') { | |
any = true; // poor man's filter | |
addNamed(name, node, parent); | |
} | |
}); | |
if (!any) { | |
context.report( | |
node.source, 'No named exports found in module \'' + String( | |
node.source.value) + '\'.'); | |
} | |
}return ExportAllDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = namespace[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref = _step2.value;var _ref2 = _slicedToArray(_ref, 2);var named = _ref2[1];var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try { | |
for (var _iterator3 = named[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var _ref3 = _step3.value;var _ref4 = _slicedToArray(_ref3, 2);var name = _ref4[0];var nodes = _ref4[1]; | |
if (nodes.size <= 1) {continue;} | |
if (isTypescriptFunctionOverloads(nodes) || isTypescriptNamespaceMerging(nodes)) {continue;}var _iteratorNormalCompletion4 = true;var _didIteratorError4 = false;var _iteratorError4 = undefined;try { | |
for (var _iterator4 = nodes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {var node = _step4.value; | |
if (shouldSkipTypescriptNamespace(node, nodes)) {continue;} | |
if (name === 'default') { | |
context.report(node, 'Multiple default exports.'); | |
} else { | |
context.report( | |
node, 'Multiple exports of name \'' + String( | |
name.replace(tsTypePrefix, '')) + '\'.'); | |
} | |
}} catch (err) {_didIteratorError4 = true;_iteratorError4 = err;} finally {try {if (!_iteratorNormalCompletion4 && _iterator4['return']) {_iterator4['return']();}} finally {if (_didIteratorError4) {throw _iteratorError4;}}} | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-mutable-exports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid the use of mutable exports with `var` or `let`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-mutable-exports.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDeclaration(node) {var | |
kind = node.kind; | |
if (kind === 'var' || kind === 'let') { | |
context.report(node, 'Exporting mutable \'' + String(kind) + '\' binding, use \'const\' instead.'); | |
} | |
} | |
function checkDeclarationsInScope(_ref, name) {var variables = _ref.variables;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = variables[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (variable.name === name) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = variable.defs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var def = _step2.value; | |
if (def.type === 'Variable' && def.parent) { | |
checkDeclaration(def.parent); | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
function handleExportDefault(node) { | |
var scope = context.getScope(); | |
if (node.declaration.name) { | |
checkDeclarationsInScope(scope, node.declaration.name); | |
} | |
} | |
function handleExportNamed(node) { | |
var scope = context.getScope(); | |
if (node.declaration) { | |
checkDeclaration(node.declaration); | |
} else if (!node.source) {var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try { | |
for (var _iterator3 = node.specifiers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var specifier = _step3.value; | |
checkDeclarationsInScope(scope, specifier.local.name); | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
} | |
} | |
return { | |
ExportDefaultDeclaration: handleExportDefault, | |
ExportNamedDeclaration: handleExportNamed }; | |
}, | |
}, | |
extensions: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure consistent use of file extension within the import path.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/extensions.md", | |
}, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
pattern: { | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
ignorePackages: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
properties: { | |
pattern: { | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
ignorePackages: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
patternProperties: { | |
".*": { | |
enum: [ | |
"always", | |
"ignorePackages", | |
"never", | |
], | |
}, | |
}, | |
}, | |
], | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
create: function create(context) { | |
var props = buildProperties(context); | |
function getModifier(extension) { | |
return props.pattern[extension] || props.defaultConfig; | |
} | |
function isUseOfExtensionRequired(extension, isPackage) { | |
return getModifier(extension) === 'always' && (!props.ignorePackages || !isPackage); | |
} | |
function isUseOfExtensionForbidden(extension) { | |
return getModifier(extension) === 'never'; | |
} | |
function isResolvableWithoutExtension(file) { | |
var extension = _path2['default'].extname(file); | |
var fileWithoutExtension = file.slice(0, -extension.length); | |
var resolvedFileWithoutExtension = (0, _resolve2['default'])(fileWithoutExtension, context); | |
return resolvedFileWithoutExtension === (0, _resolve2['default'])(file, context); | |
} | |
function isExternalRootModule(file) { | |
if (file === '.' || file === '..') {return false;} | |
var slashCount = file.split('/').length - 1; | |
if (slashCount === 0) {return true;} | |
if ((0, _importType.isScoped)(file) && slashCount <= 1) {return true;} | |
return false; | |
} | |
function checkFileExtension(source, node) { | |
// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor | |
if (!source || !source.value) {return;} | |
var importPathWithQueryString = source.value; | |
// don't enforce anything on builtins | |
if ((0, _importType.isBuiltIn)(importPathWithQueryString, context.settings)) {return;} | |
var importPath = importPathWithQueryString.replace(/\?(.*)$/, ''); | |
// don't enforce in root external packages as they may have names with `.js`. | |
// Like `import Decimal from decimal.js`) | |
if (isExternalRootModule(importPath)) {return;} | |
var resolvedPath = (0, _resolve2['default'])(importPath, context); | |
// get extension from resolved path, if possible. | |
// for unresolved, use source value. | |
var extension = _path2['default'].extname(resolvedPath || importPath).substring(1); | |
// determine if this is a module | |
var isPackage = (0, _importType.isExternalModule)( | |
importPath, | |
(0, _resolve2['default'])(importPath, context), | |
context) || | |
(0, _importType.isScoped)(importPath); | |
if (!extension || !importPath.endsWith('.' + String(extension))) { | |
// ignore type-only imports and exports | |
if (node.importKind === 'type' || node.exportKind === 'type') {return;} | |
var extensionRequired = isUseOfExtensionRequired(extension, isPackage); | |
var extensionForbidden = isUseOfExtensionForbidden(extension); | |
if (extensionRequired && !extensionForbidden) { | |
context.report({ | |
node: source, | |
message: 'Missing file extension ' + ( | |
extension ? '"' + String(extension) + '" ' : '') + 'for "' + String(importPathWithQueryString) + '"' }); | |
} | |
} else if (extension) { | |
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) { | |
context.report({ | |
node: source, | |
message: 'Unexpected use of file extension "' + String(extension) + '" for "' + String(importPathWithQueryString) + '"' }); | |
} | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkFileExtension, { commonjs: true }); | |
}, | |
}, | |
"no-restricted-paths": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Enforce which files can be imported in a given folder.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-restricted-paths.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
zones: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "object", | |
properties: { | |
target: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
minLength: 1, | |
}, | |
], | |
}, | |
from: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
minLength: 1, | |
}, | |
], | |
}, | |
except: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
message: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
basePath: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function noRestrictedPaths(context) { | |
var options = context.options[0] || {}; | |
var restrictedPaths = options.zones || []; | |
var basePath = options.basePath || process.cwd(); | |
var currentFilename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var matchingZones = restrictedPaths.filter( | |
function (zone) {return [].concat(zone.target). | |
map(function (target) {return _path2['default'].resolve(basePath, target);}). | |
some(function (targetPath) {return isMatchingTargetPath(currentFilename, targetPath);});}); | |
function isMatchingTargetPath(filename, targetPath) { | |
if ((0, _isGlob2['default'])(targetPath)) { | |
var mm = new _minimatch.Minimatch(targetPath); | |
return mm.match(filename); | |
} | |
return containsPath(filename, targetPath); | |
} | |
function isValidExceptionPath(absoluteFromPath, absoluteExceptionPath) { | |
var relativeExceptionPath = _path2['default'].relative(absoluteFromPath, absoluteExceptionPath); | |
return (0, _importType2['default'])(relativeExceptionPath, context) !== 'parent'; | |
} | |
function areBothGlobPatternAndAbsolutePath(areGlobPatterns) { | |
return areGlobPatterns.some(function (isGlob) {return isGlob;}) && areGlobPatterns.some(function (isGlob) {return !isGlob;}); | |
} | |
function reportInvalidExceptionPath(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path exceptions must be descendants of the configured `from` path for that zone.' }); | |
} | |
function reportInvalidExceptionMixedGlobAndNonGlob(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path `from` must contain either only glob patterns or none' }); | |
} | |
function reportInvalidExceptionGlob(node) { | |
context.report({ | |
node: node, | |
message: 'Restricted path exceptions must be glob patterns when `from` contains glob patterns' }); | |
} | |
function computeMixedGlobAndAbsolutePathValidator() { | |
return { | |
isPathRestricted: function () {function isPathRestricted() {return true;}return isPathRestricted;}(), | |
hasValidExceptions: false, | |
reportInvalidException: reportInvalidExceptionMixedGlobAndNonGlob }; | |
} | |
function computeGlobPatternPathValidator(absoluteFrom, zoneExcept) { | |
var isPathException = void 0; | |
var mm = new _minimatch.Minimatch(absoluteFrom); | |
var isPathRestricted = function () {function isPathRestricted(absoluteImportPath) {return mm.match(absoluteImportPath);}return isPathRestricted;}(); | |
var hasValidExceptions = zoneExcept.every(_isGlob2['default']); | |
if (hasValidExceptions) { | |
var exceptionsMm = zoneExcept.map(function (except) {return new _minimatch.Minimatch(except);}); | |
isPathException = function () {function isPathException(absoluteImportPath) {return exceptionsMm.some(function (mm) {return mm.match(absoluteImportPath);});}return isPathException;}(); | |
} | |
var reportInvalidException = reportInvalidExceptionGlob; | |
return { | |
isPathRestricted: isPathRestricted, | |
hasValidExceptions: hasValidExceptions, | |
isPathException: isPathException, | |
reportInvalidException: reportInvalidException }; | |
} | |
function computeAbsolutePathValidator(absoluteFrom, zoneExcept) { | |
var isPathException = void 0; | |
var isPathRestricted = function () {function isPathRestricted(absoluteImportPath) {return containsPath(absoluteImportPath, absoluteFrom);}return isPathRestricted;}(); | |
var absoluteExceptionPaths = zoneExcept. | |
map(function (exceptionPath) {return _path2['default'].resolve(absoluteFrom, exceptionPath);}); | |
var hasValidExceptions = absoluteExceptionPaths. | |
every(function (absoluteExceptionPath) {return isValidExceptionPath(absoluteFrom, absoluteExceptionPath);}); | |
if (hasValidExceptions) { | |
isPathException = function () {function isPathException(absoluteImportPath) {return absoluteExceptionPaths.some( | |
function (absoluteExceptionPath) {return containsPath(absoluteImportPath, absoluteExceptionPath);});}return isPathException;}(); | |
} | |
var reportInvalidException = reportInvalidExceptionPath; | |
return { | |
isPathRestricted: isPathRestricted, | |
hasValidExceptions: hasValidExceptions, | |
isPathException: isPathException, | |
reportInvalidException: reportInvalidException }; | |
} | |
function reportInvalidExceptions(validators, node) { | |
validators.forEach(function (validator) {return validator.reportInvalidException(node);}); | |
} | |
function reportImportsInRestrictedZone(validators, node, importPath, customMessage) { | |
validators.forEach(function () { | |
context.report({ | |
node: node, | |
message: 'Unexpected path "{{importPath}}" imported in restricted zone.' + (customMessage ? ' ' + String(customMessage) : ''), | |
data: { importPath: importPath } }); | |
}); | |
} | |
var makePathValidators = function () {function makePathValidators(zoneFrom) {var zoneExcept = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | |
var allZoneFrom = [].concat(zoneFrom); | |
var areGlobPatterns = allZoneFrom.map(_isGlob2['default']); | |
if (areBothGlobPatternAndAbsolutePath(areGlobPatterns)) { | |
return [computeMixedGlobAndAbsolutePathValidator()]; | |
} | |
var isGlobPattern = areGlobPatterns.every(function (isGlob) {return isGlob;}); | |
return allZoneFrom.map(function (singleZoneFrom) { | |
var absoluteFrom = _path2['default'].resolve(basePath, singleZoneFrom); | |
if (isGlobPattern) { | |
return computeGlobPatternPathValidator(absoluteFrom, zoneExcept); | |
} | |
return computeAbsolutePathValidator(absoluteFrom, zoneExcept); | |
}); | |
}return makePathValidators;}(); | |
var validators = []; | |
function checkForRestrictedImportPath(importPath, node) { | |
var absoluteImportPath = (0, _resolve2['default'])(importPath, context); | |
if (!absoluteImportPath) { | |
return; | |
} | |
matchingZones.forEach(function (zone, index) { | |
if (!validators[index]) { | |
validators[index] = makePathValidators(zone.from, zone.except); | |
} | |
var applicableValidatorsForImportPath = validators[index].filter(function (validator) {return validator.isPathRestricted(absoluteImportPath);}); | |
var validatorsWithInvalidExceptions = applicableValidatorsForImportPath.filter(function (validator) {return !validator.hasValidExceptions;}); | |
reportInvalidExceptions(validatorsWithInvalidExceptions, node); | |
var applicableValidatorsForImportPathExcludingExceptions = applicableValidatorsForImportPath. | |
filter(function (validator) {return validator.hasValidExceptions && !validator.isPathException(absoluteImportPath);}); | |
reportImportsInRestrictedZone(applicableValidatorsForImportPathExcludingExceptions, node, importPath, zone.message); | |
}); | |
} | |
return (0, _moduleVisitor2['default'])(function (source) { | |
checkForRestrictedImportPath(source.value, source); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-internal-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing the submodules of other modules.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-internal-modules.md", | |
}, | |
schema: [ | |
{ | |
anyOf: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
properties: { | |
forbid: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
}, | |
create: function noReachingInside(context) { | |
var options = context.options[0] || {}; | |
var allowRegexps = (options.allow || []).map(function (p) {return _minimatch2['default'].makeRe(p);}); | |
var forbidRegexps = (options.forbid || []).map(function (p) {return _minimatch2['default'].makeRe(p);}); | |
// minimatch patterns are expected to use / path separators, like import | |
// statements, so normalize paths to use the same | |
function normalizeSep(somePath) { | |
return somePath.split('\\').join('/'); | |
} | |
function toSteps(somePath) { | |
return normalizeSep(somePath). | |
split('/'). | |
filter(function (step) {return step && step !== '.';}). | |
reduce(function (acc, step) { | |
if (step === '..') { | |
return acc.slice(0, -1); | |
} | |
return acc.concat(step); | |
}, []); | |
} | |
// test if reaching to this destination is allowed | |
function reachingAllowed(importPath) { | |
return allowRegexps.some(function (re) {return re.test(importPath);}); | |
} | |
// test if reaching to this destination is forbidden | |
function reachingForbidden(importPath) { | |
return forbidRegexps.some(function (re) {return re.test(importPath);}); | |
} | |
function isAllowViolation(importPath) { | |
var steps = toSteps(importPath); | |
var nonScopeSteps = steps.filter(function (step) {return step.indexOf('@') !== 0;}); | |
if (nonScopeSteps.length <= 1) {return false;} | |
// before trying to resolve, see if the raw import (with relative | |
// segments resolved) matches an allowed pattern | |
var justSteps = steps.join('/'); | |
if (reachingAllowed(justSteps) || reachingAllowed('/' + String(justSteps))) {return false;} | |
// if the import statement doesn't match directly, try to match the | |
// resolved path if the import is resolvable | |
var resolved = (0, _resolve2['default'])(importPath, context); | |
if (!resolved || reachingAllowed(normalizeSep(resolved))) {return false;} | |
// this import was not allowed by the allowed paths, and reaches | |
// so it is a violation | |
return true; | |
} | |
function isForbidViolation(importPath) { | |
var steps = toSteps(importPath); | |
// before trying to resolve, see if the raw import (with relative | |
// segments resolved) matches a forbidden pattern | |
var justSteps = steps.join('/'); | |
if (reachingForbidden(justSteps) || reachingForbidden('/' + String(justSteps))) {return true;} | |
// if the import statement doesn't match directly, try to match the | |
// resolved path if the import is resolvable | |
var resolved = (0, _resolve2['default'])(importPath, context); | |
if (resolved && reachingForbidden(normalizeSep(resolved))) {return true;} | |
// this import was not forbidden by the forbidden paths so it is not a violation | |
return false; | |
} | |
// find a directory that is being reached into, but which shouldn't be | |
var isReachViolation = options.forbid ? isForbidViolation : isAllowViolation; | |
function checkImportForReaching(importPath, node) { | |
var potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal']; | |
if ( | |
potentialViolationTypes.indexOf((0, _importType2['default'])(importPath, context)) !== -1 && | |
isReachViolation(importPath)) | |
{ | |
context.report({ | |
node: node, | |
message: 'Reaching to "' + String(importPath) + '" is not allowed.' }); | |
} | |
} | |
return (0, _moduleVisitor2['default'])( | |
function (source) { | |
checkImportForReaching(source.value, source); | |
}, | |
{ commonjs: true }); | |
}, | |
}, | |
"group-exports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Prefer named exports to be grouped together in a single export declaration", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/group-exports.md", | |
}, | |
}, | |
create: function create(context) { | |
var nodes = { | |
modules: { | |
set: new Set(), | |
sources: {} }, | |
types: { | |
set: new Set(), | |
sources: {} }, | |
commonjs: { | |
set: new Set() } }; | |
return { | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
var target = node.exportKind === 'type' ? nodes.types : nodes.modules; | |
if (!node.source) { | |
target.set.add(node); | |
} else if (Array.isArray(target.sources[node.source.value])) { | |
target.sources[node.source.value].push(node); | |
} else { | |
target.sources[node.source.value] = [node]; | |
} | |
}return ExportNamedDeclaration;}(), | |
AssignmentExpression: function () {function AssignmentExpression(node) { | |
if (node.left.type !== 'MemberExpression') { | |
return; | |
} | |
var chain = accessorChain(node.left); | |
// Assignments to module.exports | |
// Deeper assignments are ignored since they just modify what's already being exported | |
// (ie. module.exports.exported.prop = true is ignored) | |
if (chain[0] === 'module' && chain[1] === 'exports' && chain.length <= 3) { | |
nodes.commonjs.set.add(node); | |
return; | |
} | |
// Assignments to exports (exports.* = *) | |
if (chain[0] === 'exports' && chain.length === 2) { | |
nodes.commonjs.set.add(node); | |
return; | |
} | |
}return AssignmentExpression;}(), | |
'Program:exit': function () {function onExit() { | |
// Report multiple `export` declarations (ES2015 modules) | |
if (nodes.modules.set.size > 1) { | |
nodes.modules.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
// Report multiple `aggregated exports` from the same module (ES2015 modules) | |
(0, _arrayPrototype2['default'])((0, _object2['default'])(nodes.modules.sources). | |
filter(function (nodesWithSource) {return Array.isArray(nodesWithSource) && nodesWithSource.length > 1;})). | |
forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
// Report multiple `export type` declarations (FLOW ES2015 modules) | |
if (nodes.types.set.size > 1) { | |
nodes.types.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
// Report multiple `aggregated type exports` from the same module (FLOW ES2015 modules) | |
(0, _arrayPrototype2['default'])((0, _object2['default'])(nodes.types.sources). | |
filter(function (nodesWithSource) {return Array.isArray(nodesWithSource) && nodesWithSource.length > 1;})). | |
forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
// Report multiple `module.exports` assignments (CommonJS) | |
if (nodes.commonjs.set.size > 1) { | |
nodes.commonjs.set.forEach(function (node) { | |
context.report({ | |
node: node, | |
message: errors[node.type] }); | |
}); | |
} | |
}return onExit;}() }; | |
}, | |
}, | |
"no-relative-packages": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing packages through relative paths.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-relative-packages.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source) {return checkImportForRelativePackage(context, source.value, source);}, context.options[0]); | |
}, | |
}, | |
"no-relative-parent-imports": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid importing modules from parent directories.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-relative-parent-imports.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function noRelativePackages(context) { | |
var myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
if (myPath === '<text>') {return {};} // can't check a non-file | |
function checkSourceValue(sourceNode) { | |
var depPath = sourceNode.value; | |
if ((0, _importType2['default'])(depPath, context) === 'external') {// ignore packages | |
return; | |
} | |
var absDepPath = (0, _resolve2['default'])(depPath, context); | |
if (!absDepPath) {// unable to resolve path | |
return; | |
} | |
var relDepPath = (0, _path.relative)((0, _path.dirname)(myPath), absDepPath); | |
if ((0, _importType2['default'])(relDepPath, context) === 'parent') { | |
context.report({ | |
node: sourceNode, | |
message: 'Relative imports from parent directories are not allowed. Please either pass what you\'re importing through at runtime (dependency injection), move `' + String((0, _path.basename)(myPath)) + '` to same directory as `' + String(depPath) + '` or consider making `' + String(depPath) + '` a package.' }); | |
} | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, context.options[0]); | |
}, | |
}, | |
"consistent-type-specifier-style": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce or ban the use of inline type-only markers for named imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/consistent-type-specifier-style.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"prefer-inline", | |
"prefer-top-level", | |
], | |
default: "prefer-inline", | |
}, | |
], | |
}, | |
create: function create(context) { | |
var sourceCode = context.getSourceCode(); | |
if (context.options[0] === 'prefer-inline') { | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (node.importKind === 'value' || node.importKind == null) { | |
// top-level value / unknown is valid | |
return; | |
} | |
if ( | |
// no specifiers (import type {} from '') have no specifiers to mark as inline | |
node.specifiers.length === 0 || | |
node.specifiers.length === 1 | |
// default imports are both "inline" and "top-level" | |
&& ( | |
node.specifiers[0].type === 'ImportDefaultSpecifier' | |
// namespace imports are both "inline" and "top-level" | |
|| node.specifiers[0].type === 'ImportNamespaceSpecifier')) | |
{ | |
return; | |
} | |
context.report({ | |
node: node, | |
message: 'Prefer using inline {{kind}} specifiers instead of a top-level {{kind}}-only import.', | |
data: { | |
kind: node.importKind }, | |
fix: function () {function fix(fixer) { | |
var kindToken = sourceCode.getFirstToken(node, { skip: 1 }); | |
return [].concat( | |
kindToken ? fixer.remove(kindToken) : [], | |
node.specifiers.map(function (specifier) {return fixer.insertTextBefore(specifier, String(node.importKind) + ' ');})); | |
}return fix;}() }); | |
}return ImportDeclaration;}() }; | |
} | |
// prefer-top-level | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if ( | |
// already top-level is valid | |
node.importKind === 'type' || | |
node.importKind === 'typeof' | |
// no specifiers (import {} from '') cannot have inline - so is valid | |
|| node.specifiers.length === 0 || | |
node.specifiers.length === 1 | |
// default imports are both "inline" and "top-level" | |
&& ( | |
node.specifiers[0].type === 'ImportDefaultSpecifier' | |
// namespace imports are both "inline" and "top-level" | |
|| node.specifiers[0].type === 'ImportNamespaceSpecifier')) | |
{ | |
return; | |
} | |
var typeSpecifiers = []; | |
var typeofSpecifiers = []; | |
var valueSpecifiers = []; | |
var defaultSpecifier = null;var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = node.specifiers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var specifier = _step2.value; | |
if (specifier.type === 'ImportDefaultSpecifier') { | |
defaultSpecifier = specifier; | |
continue; | |
} | |
if (specifier.importKind === 'type') { | |
typeSpecifiers.push(specifier); | |
} else if (specifier.importKind === 'typeof') { | |
typeofSpecifiers.push(specifier); | |
} else if (specifier.importKind === 'value' || specifier.importKind == null) { | |
valueSpecifiers.push(specifier); | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
var typeImport = getImportText(node, sourceCode, typeSpecifiers, 'type'); | |
var typeofImport = getImportText(node, sourceCode, typeofSpecifiers, 'typeof'); | |
var newImports = (String(typeImport) + '\n' + String(typeofImport)).trim(); | |
if (typeSpecifiers.length + typeofSpecifiers.length === node.specifiers.length) { | |
// all specifiers have inline specifiers - so we replace the entire import | |
var kind = [].concat( | |
typeSpecifiers.length > 0 ? 'type' : [], | |
typeofSpecifiers.length > 0 ? 'typeof' : []); | |
context.report({ | |
node: node, | |
message: 'Prefer using a top-level {{kind}}-only import instead of inline {{kind}} specifiers.', | |
data: { | |
kind: kind.join('/') }, | |
fix: function () {function fix(fixer) { | |
return fixer.replaceText(node, newImports); | |
}return fix;}() }); | |
} else { | |
// remove specific specifiers and insert new imports for them | |
var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {for (var _iterator3 = typeSpecifiers.concat(typeofSpecifiers)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var _specifier = _step3.value; | |
context.report({ | |
node: _specifier, | |
message: 'Prefer using a top-level {{kind}}-only import instead of inline {{kind}} specifiers.', | |
data: { | |
kind: _specifier.importKind }, | |
fix: function () {function fix(fixer) { | |
var fixes = []; | |
// if there are no value specifiers, then the other report fixer will be called, not this one | |
if (valueSpecifiers.length > 0) { | |
// import { Value, type Type } from 'mod'; | |
// we can just remove the type specifiers | |
removeSpecifiers(fixes, fixer, sourceCode, typeSpecifiers); | |
removeSpecifiers(fixes, fixer, sourceCode, typeofSpecifiers); | |
// make the import nicely formatted by also removing the trailing comma after the last value import | |
// eg | |
// import { Value, type Type } from 'mod'; | |
// to | |
// import { Value } from 'mod'; | |
// not | |
// import { Value, } from 'mod'; | |
var maybeComma = sourceCode.getTokenAfter(valueSpecifiers[valueSpecifiers.length - 1]); | |
if (isComma(maybeComma)) { | |
fixes.push(fixer.remove(maybeComma)); | |
} | |
} else if (defaultSpecifier) { | |
// import Default, { type Type } from 'mod'; | |
// remove the entire curly block so we don't leave an empty one behind | |
// NOTE - the default specifier *must* be the first specifier always! | |
// so a comma exists that we also have to clean up or else it's bad syntax | |
var comma = sourceCode.getTokenAfter(defaultSpecifier, isComma); | |
var closingBrace = sourceCode.getTokenAfter( | |
node.specifiers[node.specifiers.length - 1], | |
function (token) {return token.type === 'Punctuator' && token.value === '}';}); | |
fixes.push(fixer.removeRange([ | |
comma.range[0], | |
closingBrace.range[1]])); | |
} | |
return fixes.concat( | |
// insert the new imports after the old declaration | |
fixer.insertTextAfter(node, '\n' + String(newImports))); | |
}return fix;}() }); | |
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}} | |
} | |
}return ImportDeclaration;}() }; | |
}, | |
}, | |
"no-self-import": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid a module from importing itself.", | |
recommended: true, | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-self-import.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
isImportingSelf(context, node, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-cycle": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid a module from importing a module with a dependency path back to itself.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-cycle.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
maxDepth: { | |
anyOf: [ | |
{ | |
description: "maximum dependency depth to traverse", | |
type: "integer", | |
minimum: 1, | |
}, | |
{ | |
enum: [ | |
"∞", | |
], | |
type: "string", | |
}, | |
], | |
}, | |
ignoreExternal: { | |
description: "ignore external modules", | |
type: "boolean", | |
default: false, | |
}, | |
allowUnsafeDynamicCyclicDependency: { | |
description: "Allow cyclic dependency if there is at least one dynamic import in the chain", | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
if (myPath === '<text>') {return {};} // can't cycle-check a non-file | |
var options = context.options[0] || {}; | |
var maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity; | |
var ignoreModule = function () {function ignoreModule(name) {return options.ignoreExternal && (0, _importType.isExternalModule)( | |
name, | |
(0, _resolve2['default'])(name, context), | |
context);}return ignoreModule;}(); | |
function checkSourceValue(sourceNode, importer) { | |
if (ignoreModule(sourceNode.value)) { | |
return; // ignore external modules | |
} | |
if ( | |
options.allowUnsafeDynamicCyclicDependency && ( | |
// Ignore `import()` | |
importer.type === 'ImportExpression' | |
// `require()` calls are always checked (if possible) | |
|| importer.type === 'CallExpression' && importer.callee.name !== 'require')) | |
{ | |
return; // cycle via dynamic import allowed by config | |
} | |
if ( | |
importer.type === 'ImportDeclaration' && ( | |
// import type { Foo } (TS and Flow) | |
importer.importKind === 'type' | |
// import { type Foo } (Flow) | |
|| importer.specifiers.every(function (_ref) {var importKind = _ref.importKind;return importKind === 'type';}))) | |
{ | |
return; // ignore type imports | |
} | |
var imported = _ExportMap2['default'].get(sourceNode.value, context); | |
if (imported == null) { | |
return; // no-unresolved territory | |
} | |
if (imported.path === myPath) { | |
return; // no-self-import territory | |
} | |
var untraversed = [{ mget: function () {function mget() {return imported;}return mget;}(), route: [] }]; | |
function detectCycle(_ref2) {var mget = _ref2.mget,route = _ref2.route; | |
var m = mget(); | |
if (m == null) {return;} | |
if (traversed.has(m.path)) {return;} | |
traversed.add(m.path);var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = m.imports[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref3 = _step.value;var _ref4 = _slicedToArray(_ref3, 2);var path = _ref4[0];var _ref4$ = _ref4[1];var getter = _ref4$.getter;var declarations = _ref4$.declarations; | |
if (traversed.has(path)) {continue;} | |
var toTraverse = [].concat(_toConsumableArray(declarations)).filter(function (_ref5) {var source = _ref5.source,isOnlyImportingTypes = _ref5.isOnlyImportingTypes;return !ignoreModule(source.value) | |
// Ignore only type imports | |
&& !isOnlyImportingTypes;}); | |
/* | |
If cyclic dependency is allowed via dynamic import, skip checking if any module is imported dynamically | |
*/ | |
if (options.allowUnsafeDynamicCyclicDependency && toTraverse.some(function (d) {return d.dynamic;})) {return;} | |
/* | |
Only report as a cycle if there are any import declarations that are considered by | |
the rule. For example: | |
a.ts: | |
import { foo } from './b' // should not be reported as a cycle | |
b.ts: | |
import type { Bar } from './a' | |
*/ | |
if (path === myPath && toTraverse.length > 0) {return true;} | |
if (route.length + 1 < maxDepth) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = toTraverse[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref6 = _step2.value;var source = _ref6.source; | |
untraversed.push({ mget: getter, route: route.concat(source) }); | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
while (untraversed.length > 0) { | |
var next = untraversed.shift(); // bfs! | |
if (detectCycle(next)) { | |
var message = next.route.length > 0 ? 'Dependency cycle via ' + String( | |
routeString(next.route)) : | |
'Dependency cycle detected.'; | |
context.report(importer, message); | |
return; | |
} | |
} | |
} | |
return Object.assign((0, _moduleVisitor2['default'])(checkSourceValue, context.options[0]), { | |
'Program:exit': function () {function ProgramExit() { | |
traversed.clear(); | |
}return ProgramExit;}() }); | |
}, | |
}, | |
"no-named-default": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid named default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
node.specifiers.forEach(function (im) { | |
if (im.importKind === 'type' || im.importKind === 'typeof') { | |
return; | |
} | |
if (im.type === 'ImportSpecifier' && (im.imported.name || im.imported.value) === 'default') { | |
context.report({ | |
node: im.local, | |
message: 'Use default import syntax to import \'' + String(im.local.name) + '\'.' }); | |
} | |
}); | |
}return ImportDeclaration;}() }; | |
}, | |
}, | |
"no-named-as-default": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid use of exported name as identifier of default export.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-as-default.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
function checkDefault(nameKey, defaultSpecifier) { | |
// #566: default is a valid specifier | |
if (defaultSpecifier[nameKey].name === 'default') {return;} | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var imports = _ExportMap2['default'].get(declaration.source.value, context); | |
if (imports == null) {return;} | |
if (imports.errors.length) { | |
imports.reportErrors(context, declaration); | |
return; | |
} | |
if (imports.has('default') && imports.has(defaultSpecifier[nameKey].name)) { | |
context.report( | |
defaultSpecifier, 'Using exported name \'' + String( | |
defaultSpecifier[nameKey].name) + '\' as identifier for default export.'); | |
} | |
} | |
return { | |
ImportDefaultSpecifier: checkDefault.bind(null, 'local'), | |
ExportDefaultSpecifier: checkDefault.bind(null, 'exported') }; | |
}, | |
}, | |
"no-named-as-default-member": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid use of exported name as property of default export.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-as-default-member.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var fileImports = new Map(); | |
var allPropertyLookups = new Map(); | |
function storePropertyLookup(objectName, propName, node) { | |
var lookups = allPropertyLookups.get(objectName) || []; | |
lookups.push({ node: node, propName: propName }); | |
allPropertyLookups.set(objectName, lookups); | |
} | |
return { | |
ImportDefaultSpecifier: function () {function ImportDefaultSpecifier(node) { | |
var declaration = (0, _importDeclaration2['default'])(context); | |
var exportMap = _ExportMap2['default'].get(declaration.source.value, context); | |
if (exportMap == null) {return;} | |
if (exportMap.errors.length) { | |
exportMap.reportErrors(context, declaration); | |
return; | |
} | |
fileImports.set(node.local.name, { | |
exportMap: exportMap, | |
sourcePath: declaration.source.value }); | |
}return ImportDefaultSpecifier;}(), | |
MemberExpression: function () {function MemberExpression(node) { | |
var objectName = node.object.name; | |
var propName = node.property.name; | |
storePropertyLookup(objectName, propName, node); | |
}return MemberExpression;}(), | |
VariableDeclarator: function () {function VariableDeclarator(node) { | |
var isDestructure = node.id.type === 'ObjectPattern' && | |
node.init != null && | |
node.init.type === 'Identifier'; | |
if (!isDestructure) {return;} | |
var objectName = node.init.name;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = node.id.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref = _step.value;var key = _ref.key; | |
if (key == null) {continue;} // true for rest properties | |
storePropertyLookup(objectName, key.name, key); | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
}return VariableDeclarator;}(), | |
'Program:exit': function () {function ProgramExit() { | |
allPropertyLookups.forEach(function (lookups, objectName) { | |
var fileImport = fileImports.get(objectName); | |
if (fileImport == null) {return;}var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = lookups[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref2 = _step2.value;var propName = _ref2.propName,node = _ref2.node; | |
// the default import can have a "default" property | |
if (propName === 'default') {continue;} | |
if (!fileImport.exportMap.namespace.has(propName)) {continue;} | |
context.report({ | |
node: node, | |
message: 'Caution: `' + String(objectName) + '` also has a named export `' + String(propName) + '`. Check if you meant to write `import {' + String(propName) + '} from \'' + String(fileImport.sourcePath) + '\'` instead.' }); | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
}); | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-anonymous-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid anonymous values as default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-anonymous-default-export.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowArray: { | |
description: "If `false`, will report default export of an array", | |
type: "boolean", | |
}, | |
allowArrowFunction: { | |
description: "If `false`, will report default export of an arrow function", | |
type: "boolean", | |
}, | |
allowCallExpression: { | |
description: "If `false`, will report default export of a function call", | |
type: "boolean", | |
}, | |
allowAnonymousClass: { | |
description: "If `false`, will report default export of an anonymous class", | |
type: "boolean", | |
}, | |
allowAnonymousFunction: { | |
description: "If `false`, will report default export of an anonymous function", | |
type: "boolean", | |
}, | |
allowLiteral: { | |
description: "If `false`, will report default export of a literal", | |
type: "boolean", | |
}, | |
allowObject: { | |
description: "If `false`, will report default export of an object expression", | |
type: "boolean", | |
}, | |
allowNew: { | |
description: "If `false`, will report default export of a class instantiation", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = Object.assign({}, defaults, context.options[0]); | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
var def = defs[node.declaration.type]; | |
// Recognized node type and allowed by configuration, | |
// and has no forbid check, or forbid check return value is truthy | |
if (def && !options[def.option] && (!def.forbid || def.forbid(node))) { | |
context.report({ node: node, message: def.message }); | |
} | |
}return ExportDefaultDeclaration;}() }; | |
}, | |
}, | |
"no-unused-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid modules without exports, or exports without matching import in another module.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unused-modules.md", | |
}, | |
schema: [ | |
{ | |
properties: { | |
src: { | |
description: "files/paths to be analyzed (only for unused exports)", | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
minLength: 1, | |
}, | |
}, | |
ignoreExports: { | |
description: "files/paths for which unused exports will not be reported (e.g module entry points)", | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
minLength: 1, | |
}, | |
}, | |
missingExports: { | |
description: "report modules without any exports", | |
type: "boolean", | |
}, | |
unusedExports: { | |
description: "report exports without any usage", | |
type: "boolean", | |
}, | |
}, | |
anyOf: [ | |
{ | |
properties: { | |
unusedExports: { | |
enum: [ | |
true, | |
], | |
}, | |
src: { | |
minItems: 1, | |
}, | |
}, | |
required: [ | |
"unusedExports", | |
], | |
}, | |
{ | |
properties: { | |
missingExports: { | |
enum: [ | |
true, | |
], | |
}, | |
}, | |
required: [ | |
"missingExports", | |
], | |
}, | |
], | |
}, | |
], | |
}, | |
create: function create(context) {var _ref9 = | |
context.options[0] || {},src = _ref9.src,_ref9$ignoreExports = _ref9.ignoreExports,ignoreExports = _ref9$ignoreExports === undefined ? [] : _ref9$ignoreExports,missingExports = _ref9.missingExports,unusedExports = _ref9.unusedExports; | |
if (unusedExports) { | |
doPreparation(src, ignoreExports, context); | |
} | |
var file = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var checkExportPresence = function () {function checkExportPresence(node) { | |
if (!missingExports) { | |
return; | |
} | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
var exportCount = exportList.get(file); | |
var exportAll = exportCount.get(EXPORT_ALL_DECLARATION); | |
var namespaceImports = exportCount.get(IMPORT_NAMESPACE_SPECIFIER); | |
exportCount['delete'](EXPORT_ALL_DECLARATION); | |
exportCount['delete'](IMPORT_NAMESPACE_SPECIFIER); | |
if (exportCount.size < 1) { | |
// node.body[0] === 'undefined' only happens, if everything is commented out in the file | |
// being linted | |
context.report(node.body[0] ? node.body[0] : node, 'No exports found'); | |
} | |
exportCount.set(EXPORT_ALL_DECLARATION, exportAll); | |
exportCount.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports); | |
}return checkExportPresence;}(); | |
var checkUsage = function () {function checkUsage(node, exportedValue) { | |
if (!unusedExports) { | |
return; | |
} | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
if (fileIsInPkg(file)) { | |
return; | |
} | |
if (filesOutsideSrc.has(file)) { | |
return; | |
} | |
// make sure file to be linted is included in source files | |
if (!srcFiles.has(file)) { | |
srcFiles = resolveFiles(getSrc(src), ignoreExports, context); | |
if (!srcFiles.has(file)) { | |
filesOutsideSrc.add(file); | |
return; | |
} | |
} | |
exports = exportList.get(file); | |
// special case: export * from | |
var exportAll = exports.get(EXPORT_ALL_DECLARATION); | |
if (typeof exportAll !== 'undefined' && exportedValue !== IMPORT_DEFAULT_SPECIFIER) { | |
if (exportAll.whereUsed.size > 0) { | |
return; | |
} | |
} | |
// special case: namespace import | |
var namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof namespaceImports !== 'undefined') { | |
if (namespaceImports.whereUsed.size > 0) { | |
return; | |
} | |
} | |
// exportsList will always map any imported value of 'default' to 'ImportDefaultSpecifier' | |
var exportsKey = exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue; | |
var exportStatement = exports.get(exportsKey); | |
var value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey; | |
if (typeof exportStatement !== 'undefined') { | |
if (exportStatement.whereUsed.size < 1) { | |
context.report( | |
node, 'exported declaration \'' + | |
value + '\' not used within other modules'); | |
} | |
} else { | |
context.report( | |
node, 'exported declaration \'' + | |
value + '\' not used within other modules'); | |
} | |
}return checkUsage;}(); | |
/** | |
* only useful for tools like vscode-eslint | |
* | |
* update lists of existing exports during runtime | |
*/ | |
var updateExportUsage = function () {function updateExportUsage(node) { | |
if (ignoredFiles.has(file)) { | |
return; | |
} | |
var exports = exportList.get(file); | |
// new module has been created during runtime | |
// include it in further processing | |
if (typeof exports === 'undefined') { | |
exports = new Map(); | |
} | |
var newExports = new Map(); | |
var newExportIdentifiers = new Set(); | |
node.body.forEach(function (_ref10) {var type = _ref10.type,declaration = _ref10.declaration,specifiers = _ref10.specifiers; | |
if (type === EXPORT_DEFAULT_DECLARATION) { | |
newExportIdentifiers.add(IMPORT_DEFAULT_SPECIFIER); | |
} | |
if (type === EXPORT_NAMED_DECLARATION) { | |
if (specifiers.length > 0) { | |
specifiers.forEach(function (specifier) { | |
if (specifier.exported) { | |
newExportIdentifiers.add(specifier.exported.name || specifier.exported.value); | |
} | |
}); | |
} | |
forEachDeclarationIdentifier(declaration, function (name) { | |
newExportIdentifiers.add(name); | |
}); | |
} | |
}); | |
// old exports exist within list of new exports identifiers: add to map of new exports | |
exports.forEach(function (value, key) { | |
if (newExportIdentifiers.has(key)) { | |
newExports.set(key, value); | |
} | |
}); | |
// new export identifiers added: add to map of new exports | |
newExportIdentifiers.forEach(function (key) { | |
if (!exports.has(key)) { | |
newExports.set(key, { whereUsed: new Set() }); | |
} | |
}); | |
// preserve information about namespace imports | |
var exportAll = exports.get(EXPORT_ALL_DECLARATION); | |
var namespaceImports = exports.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof namespaceImports === 'undefined') { | |
namespaceImports = { whereUsed: new Set() }; | |
} | |
newExports.set(EXPORT_ALL_DECLARATION, exportAll); | |
newExports.set(IMPORT_NAMESPACE_SPECIFIER, namespaceImports); | |
exportList.set(file, newExports); | |
}return updateExportUsage;}(); | |
/** | |
* only useful for tools like vscode-eslint | |
* | |
* update lists of existing imports during runtime | |
*/ | |
var updateImportUsage = function () {function updateImportUsage(node) { | |
if (!unusedExports) { | |
return; | |
} | |
var oldImportPaths = importList.get(file); | |
if (typeof oldImportPaths === 'undefined') { | |
oldImportPaths = new Map(); | |
} | |
var oldNamespaceImports = new Set(); | |
var newNamespaceImports = new Set(); | |
var oldExportAll = new Set(); | |
var newExportAll = new Set(); | |
var oldDefaultImports = new Set(); | |
var newDefaultImports = new Set(); | |
var oldImports = new Map(); | |
var newImports = new Map(); | |
oldImportPaths.forEach(function (value, key) { | |
if (value.has(EXPORT_ALL_DECLARATION)) { | |
oldExportAll.add(key); | |
} | |
if (value.has(IMPORT_NAMESPACE_SPECIFIER)) { | |
oldNamespaceImports.add(key); | |
} | |
if (value.has(IMPORT_DEFAULT_SPECIFIER)) { | |
oldDefaultImports.add(key); | |
} | |
value.forEach(function (val) { | |
if ( | |
val !== IMPORT_NAMESPACE_SPECIFIER && | |
val !== IMPORT_DEFAULT_SPECIFIER) | |
{ | |
oldImports.set(val, key); | |
} | |
}); | |
}); | |
function processDynamicImport(source) { | |
if (source.type !== 'Literal') { | |
return null; | |
} | |
var p = (0, _resolve2['default'])(source.value, context); | |
if (p == null) { | |
return null; | |
} | |
newNamespaceImports.add(p); | |
} | |
(0, _visit2['default'])(node, visitorKeyMap.get(file), { | |
ImportExpression: function () {function ImportExpression(child) { | |
processDynamicImport(child.source); | |
}return ImportExpression;}(), | |
CallExpression: function () {function CallExpression(child) { | |
if (child.callee.type === 'Import') { | |
processDynamicImport(child.arguments[0]); | |
} | |
}return CallExpression;}() }); | |
node.body.forEach(function (astNode) { | |
var resolvedPath = void 0; | |
// support for export { value } from 'module' | |
if (astNode.type === EXPORT_NAMED_DECLARATION) { | |
if (astNode.source) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
astNode.specifiers.forEach(function (specifier) { | |
var name = specifier.local.name || specifier.local.value; | |
if (name === DEFAULT) { | |
newDefaultImports.add(resolvedPath); | |
} else { | |
newImports.set(name, resolvedPath); | |
} | |
}); | |
} | |
} | |
if (astNode.type === EXPORT_ALL_DECLARATION) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
newExportAll.add(resolvedPath); | |
} | |
if (astNode.type === IMPORT_DECLARATION) { | |
resolvedPath = (0, _resolve2['default'])(astNode.source.raw.replace(/('|")/g, ''), context); | |
if (!resolvedPath) { | |
return; | |
} | |
if (isNodeModule(resolvedPath)) { | |
return; | |
} | |
if (newNamespaceImportExists(astNode.specifiers)) { | |
newNamespaceImports.add(resolvedPath); | |
} | |
if (newDefaultImportExists(astNode.specifiers)) { | |
newDefaultImports.add(resolvedPath); | |
} | |
astNode.specifiers. | |
filter(function (specifier) {return specifier.type !== IMPORT_DEFAULT_SPECIFIER && specifier.type !== IMPORT_NAMESPACE_SPECIFIER;}). | |
forEach(function (specifier) { | |
newImports.set(specifier.imported.name || specifier.imported.value, resolvedPath); | |
}); | |
} | |
}); | |
newExportAll.forEach(function (value) { | |
if (!oldExportAll.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(EXPORT_ALL_DECLARATION); | |
oldImportPaths.set(value, imports); | |
var _exports = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports !== 'undefined') { | |
currentExport = _exports.get(EXPORT_ALL_DECLARATION); | |
} else { | |
_exports = new Map(); | |
exportList.set(value, _exports); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports.set(EXPORT_ALL_DECLARATION, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldExportAll.forEach(function (value) { | |
if (!newExportAll.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](EXPORT_ALL_DECLARATION); | |
var _exports2 = exportList.get(value); | |
if (typeof _exports2 !== 'undefined') { | |
var currentExport = _exports2.get(EXPORT_ALL_DECLARATION); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newDefaultImports.forEach(function (value) { | |
if (!oldDefaultImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(IMPORT_DEFAULT_SPECIFIER); | |
oldImportPaths.set(value, imports); | |
var _exports3 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports3 !== 'undefined') { | |
currentExport = _exports3.get(IMPORT_DEFAULT_SPECIFIER); | |
} else { | |
_exports3 = new Map(); | |
exportList.set(value, _exports3); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports3.set(IMPORT_DEFAULT_SPECIFIER, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldDefaultImports.forEach(function (value) { | |
if (!newDefaultImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](IMPORT_DEFAULT_SPECIFIER); | |
var _exports4 = exportList.get(value); | |
if (typeof _exports4 !== 'undefined') { | |
var currentExport = _exports4.get(IMPORT_DEFAULT_SPECIFIER); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newNamespaceImports.forEach(function (value) { | |
if (!oldNamespaceImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(IMPORT_NAMESPACE_SPECIFIER); | |
oldImportPaths.set(value, imports); | |
var _exports5 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports5 !== 'undefined') { | |
currentExport = _exports5.get(IMPORT_NAMESPACE_SPECIFIER); | |
} else { | |
_exports5 = new Map(); | |
exportList.set(value, _exports5); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports5.set(IMPORT_NAMESPACE_SPECIFIER, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldNamespaceImports.forEach(function (value) { | |
if (!newNamespaceImports.has(value)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](IMPORT_NAMESPACE_SPECIFIER); | |
var _exports6 = exportList.get(value); | |
if (typeof _exports6 !== 'undefined') { | |
var currentExport = _exports6.get(IMPORT_NAMESPACE_SPECIFIER); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
newImports.forEach(function (value, key) { | |
if (!oldImports.has(key)) { | |
var imports = oldImportPaths.get(value); | |
if (typeof imports === 'undefined') { | |
imports = new Set(); | |
} | |
imports.add(key); | |
oldImportPaths.set(value, imports); | |
var _exports7 = exportList.get(value); | |
var currentExport = void 0; | |
if (typeof _exports7 !== 'undefined') { | |
currentExport = _exports7.get(key); | |
} else { | |
_exports7 = new Map(); | |
exportList.set(value, _exports7); | |
} | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed.add(file); | |
} else { | |
var whereUsed = new Set(); | |
whereUsed.add(file); | |
_exports7.set(key, { whereUsed: whereUsed }); | |
} | |
} | |
}); | |
oldImports.forEach(function (value, key) { | |
if (!newImports.has(key)) { | |
var imports = oldImportPaths.get(value); | |
imports['delete'](key); | |
var _exports8 = exportList.get(value); | |
if (typeof _exports8 !== 'undefined') { | |
var currentExport = _exports8.get(key); | |
if (typeof currentExport !== 'undefined') { | |
currentExport.whereUsed['delete'](file); | |
} | |
} | |
} | |
}); | |
}return updateImportUsage;}(); | |
return { | |
'Program:exit': function () {function ProgramExit(node) { | |
updateExportUsage(node); | |
updateImportUsage(node); | |
checkExportPresence(node); | |
}return ProgramExit;}(), | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) { | |
checkUsage(node, IMPORT_DEFAULT_SPECIFIER); | |
}return ExportDefaultDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
node.specifiers.forEach(function (specifier) { | |
checkUsage(specifier, specifier.exported.name || specifier.exported.value); | |
}); | |
forEachDeclarationIdentifier(node.declaration, function (name) { | |
checkUsage(node, name); | |
}); | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-commonjs": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid CommonJS `require` calls and `module.exports` or `exports.*`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-commonjs.md", | |
}, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"allow-primitive-modules", | |
], | |
}, | |
], | |
additionalItems: false, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
properties: { | |
allowPrimitiveModules: { | |
type: "boolean", | |
}, | |
allowRequire: { | |
type: "boolean", | |
}, | |
allowConditionalRequire: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
create: function create(context) { | |
var options = normalizeLegacyOptions(context.options); | |
return { | |
MemberExpression: function () {function MemberExpression(node) { | |
// module.exports | |
if (node.object.name === 'module' && node.property.name === 'exports') { | |
if (allowPrimitive(node, options)) {return;} | |
context.report({ node: node, message: EXPORT_MESSAGE }); | |
} | |
// exports. | |
if (node.object.name === 'exports') { | |
var isInScope = context.getScope(). | |
variables. | |
some(function (variable) {return variable.name === 'exports';}); | |
if (!isInScope) { | |
context.report({ node: node, message: EXPORT_MESSAGE }); | |
} | |
} | |
}return MemberExpression;}(), | |
CallExpression: function () {function CallExpression(call) { | |
if (!validateScope(context.getScope())) {return;} | |
if (call.callee.type !== 'Identifier') {return;} | |
if (call.callee.name !== 'require') {return;} | |
if (call.arguments.length !== 1) {return;} | |
if (!isLiteralString(call.arguments[0])) {return;} | |
if (allowRequire(call, options)) {return;} | |
if (allowConditionalRequire(call, options) && isConditional(call.parent)) {return;} | |
// keeping it simple: all 1-string-arg `require` calls are reported | |
context.report({ | |
node: call.callee, | |
message: IMPORT_MESSAGE }); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-amd": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid AMD `require` and `define` calls.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-amd.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
CallExpression: function () {function CallExpression(node) { | |
if (context.getScope().type !== 'module') {return;} | |
if (node.callee.type !== 'Identifier') {return;} | |
if (node.callee.name !== 'require' && node.callee.name !== 'define') {return;} | |
// todo: capture define((require, module, exports) => {}) form? | |
if (node.arguments.length !== 2) {return;} | |
var modules = node.arguments[0]; | |
if (modules.type !== 'ArrayExpression') {return;} | |
// todo: check second arg type? (identifier or callback) | |
context.report(node, 'Expected imports instead of AMD ' + String(node.callee.name) + '().'); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-duplicates": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Style guide", | |
description: "Forbid repeated import of the same module in multiple places.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-duplicates.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
considerQueryString: { | |
type: "boolean", | |
}, | |
"prefer-inline": { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
// Prepare the resolver from options. | |
var considerQueryStringOption = context.options[0] && | |
context.options[0].considerQueryString; | |
var defaultResolver = function () {function defaultResolver(sourcePath) {return (0, _resolve2['default'])(sourcePath, context) || sourcePath;}return defaultResolver;}(); | |
var resolver = considerQueryStringOption ? function (sourcePath) { | |
var parts = sourcePath.match(/^([^?]*)\?(.*)$/); | |
if (!parts) { | |
return defaultResolver(sourcePath); | |
} | |
return String(defaultResolver(parts[1])) + '?' + String(parts[2]); | |
} : defaultResolver; | |
var moduleMaps = new Map(); | |
function getImportMap(n) { | |
if (!moduleMaps.has(n.parent)) { | |
moduleMaps.set(n.parent, { | |
imported: new Map(), | |
nsImported: new Map(), | |
defaultTypesImported: new Map(), | |
namedTypesImported: new Map() }); | |
} | |
var map = moduleMaps.get(n.parent); | |
var preferInline = context.options[0] && context.options[0]['prefer-inline']; | |
if (!preferInline && n.importKind === 'type') { | |
return n.specifiers.length > 0 && n.specifiers[0].type === 'ImportDefaultSpecifier' ? map.defaultTypesImported : map.namedTypesImported; | |
} | |
if (!preferInline && n.specifiers.some(function (spec) {return spec.importKind === 'type';})) { | |
return map.namedTypesImported; | |
} | |
return hasNamespace(n) ? map.nsImported : map.imported; | |
} | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(n) { | |
// resolved path will cover aliased duplicates | |
var resolvedPath = resolver(n.source.value); | |
var importMap = getImportMap(n); | |
if (importMap.has(resolvedPath)) { | |
importMap.get(resolvedPath).push(n); | |
} else { | |
importMap.set(resolvedPath, [n]); | |
} | |
}return ImportDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() {var _iteratorNormalCompletion5 = true;var _didIteratorError5 = false;var _iteratorError5 = undefined;try { | |
for (var _iterator5 = moduleMaps.values()[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {var map = _step5.value; | |
checkImports(map.imported, context); | |
checkImports(map.nsImported, context); | |
checkImports(map.defaultTypesImported, context); | |
checkImports(map.namedTypesImported, context); | |
}} catch (err) {_didIteratorError5 = true;_iteratorError5 = err;} finally {try {if (!_iteratorNormalCompletion5 && _iterator5['return']) {_iterator5['return']();}} finally {if (_didIteratorError5) {throw _iteratorError5;}}} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
first: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure all imports appear before other statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/first.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"absolute-first", | |
"disable-absolute-first", | |
], | |
}, | |
], | |
}, | |
create: function create(context) { | |
function isPossibleDirective(node) { | |
return node.type === 'ExpressionStatement' && | |
node.expression.type === 'Literal' && | |
typeof node.expression.value === 'string'; | |
} | |
return { | |
Program: function () {function Program(n) { | |
var body = n.body; | |
if (!body) { | |
return; | |
} | |
var absoluteFirst = context.options[0] === 'absolute-first'; | |
var message = 'Import in body of module; reorder to top.'; | |
var sourceCode = context.getSourceCode(); | |
var originSourceCode = sourceCode.getText(); | |
var nonImportCount = 0; | |
var anyExpressions = false; | |
var anyRelative = false; | |
var lastLegalImp = null; | |
var errorInfos = []; | |
var shouldSort = true; | |
var lastSortNodesIndex = 0; | |
body.forEach(function (node, index) { | |
if (!anyExpressions && isPossibleDirective(node)) { | |
return; | |
} | |
anyExpressions = true; | |
if (node.type === 'ImportDeclaration' || node.type === 'TSImportEqualsDeclaration') { | |
if (absoluteFirst) { | |
if (/^\./.test(getImportValue(node))) { | |
anyRelative = true; | |
} else if (anyRelative) { | |
context.report({ | |
node: node.type === 'ImportDeclaration' ? node.source : node.moduleReference, | |
message: 'Absolute imports should come before relative imports.' }); | |
} | |
} | |
if (nonImportCount > 0) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = context.getDeclaredVariables(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (!shouldSort) {break;} | |
var references = variable.references; | |
if (references.length) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = references[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var reference = _step2.value; | |
if (reference.identifier.range[0] < node.range[1]) { | |
shouldSort = false; | |
break; | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
shouldSort && (lastSortNodesIndex = errorInfos.length); | |
errorInfos.push({ | |
node: node, | |
range: [body[index - 1].range[1], node.range[1]] }); | |
} else { | |
lastLegalImp = node; | |
} | |
} else { | |
nonImportCount++; | |
} | |
}); | |
if (!errorInfos.length) {return;} | |
errorInfos.forEach(function (errorInfo, index) { | |
var node = errorInfo.node; | |
var infos = { | |
node: node, | |
message: message }; | |
if (index < lastSortNodesIndex) { | |
infos.fix = function (fixer) { | |
return fixer.insertTextAfter(node, ''); | |
}; | |
} else if (index === lastSortNodesIndex) { | |
var sortNodes = errorInfos.slice(0, lastSortNodesIndex + 1); | |
infos.fix = function (fixer) { | |
var removeFixers = sortNodes.map(function (_errorInfo) { | |
return fixer.removeRange(_errorInfo.range); | |
}); | |
var range = [0, removeFixers[removeFixers.length - 1].range[1]]; | |
var insertSourceCode = sortNodes.map(function (_errorInfo) { | |
var nodeSourceCode = String.prototype.slice.apply( | |
originSourceCode, _errorInfo.range); | |
if (/\S/.test(nodeSourceCode[0])) { | |
return '\n' + String(nodeSourceCode); | |
} | |
return nodeSourceCode; | |
}).join(''); | |
var insertFixer = null; | |
var replaceSourceCode = ''; | |
if (!lastLegalImp) { | |
insertSourceCode = insertSourceCode.trim() + insertSourceCode.match(/^(\s+)/)[0]; | |
} | |
insertFixer = lastLegalImp ? | |
fixer.insertTextAfter(lastLegalImp, insertSourceCode) : | |
fixer.insertTextBefore(body[0], insertSourceCode); | |
var fixers = [insertFixer].concat(removeFixers); | |
fixers.forEach(function (computedFixer, i) { | |
replaceSourceCode += originSourceCode.slice( | |
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]) + | |
computedFixer.text; | |
}); | |
return fixer.replaceTextRange(range, replaceSourceCode); | |
}; | |
} | |
context.report(infos); | |
}); | |
}return Program;}() }; | |
}, | |
}, | |
"max-dependencies": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce the maximum number of dependencies a module can have.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/max-dependencies.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
max: { | |
type: "number", | |
}, | |
ignoreTypeImports: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) {var _ref2 = | |
context.options[0] || {},_ref2$ignoreTypeImpor = _ref2.ignoreTypeImports,ignoreTypeImports = _ref2$ignoreTypeImpor === undefined ? DEFAULT_IGNORE_TYPE_IMPORTS : _ref2$ignoreTypeImpor; | |
var dependencies = new Set(); // keep track of dependencies | |
var lastNode = void 0; // keep track of the last node to report on | |
return Object.assign({ | |
'Program:exit': function () {function ProgramExit() { | |
countDependencies(dependencies, lastNode, context); | |
}return ProgramExit;}() }, | |
(0, _moduleVisitor2['default'])( | |
function (source, _ref3) {var importKind = _ref3.importKind; | |
if (importKind !== TYPE_IMPORT || !ignoreTypeImports) { | |
dependencies.add(source.value); | |
} | |
lastNode = source; | |
}, | |
{ commonjs: true })); | |
}, | |
}, | |
"no-extraneous-dependencies": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid the use of extraneous packages.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-extraneous-dependencies.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
devDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
optionalDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
peerDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
bundledDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
packageDir: { | |
type: [ | |
"string", | |
"array", | |
], | |
}, | |
includeInternal: { | |
type: [ | |
"boolean", | |
], | |
}, | |
includeTypes: { | |
type: [ | |
"boolean", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var deps = getDependencies(context, options.packageDir) || extractDepFields({}); | |
var depsOptions = { | |
allowDevDeps: testConfig(options.devDependencies, filename) !== false, | |
allowOptDeps: testConfig(options.optionalDependencies, filename) !== false, | |
allowPeerDeps: testConfig(options.peerDependencies, filename) !== false, | |
allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false, | |
verifyInternalDeps: !!options.includeInternal, | |
verifyTypeImports: !!options.includeTypes }; | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfMissing(context, deps, depsOptions, node, source.value); | |
}, { commonjs: true }); | |
}, | |
"Program:exit": function ProgramExit() { | |
depFieldCache.clear(); | |
}, | |
}, | |
"no-absolute-path": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid import of modules using absolute paths.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-absolute-path.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
amd: { | |
type: "boolean", | |
}, | |
esmodule: { | |
type: "boolean", | |
}, | |
ignore: { | |
type: "array", | |
minItems: 1, | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
function reportIfAbsolute(source) { | |
if ((0, _importType.isAbsolute)(source.value)) { | |
context.report({ | |
node: source, | |
message: 'Do not import modules using an absolute path', | |
fix: function () {function fix(fixer) { | |
var resolvedContext = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
// node.js and web imports work with posix style paths ("/") | |
var relativePath = _path2['default'].posix.relative(_path2['default'].dirname(resolvedContext), source.value); | |
if (!relativePath.startsWith('.')) { | |
relativePath = './' + String(relativePath); | |
} | |
return fixer.replaceText(source, JSON.stringify(relativePath)); | |
}return fix;}() }); | |
} | |
} | |
var options = Object.assign({ esmodule: true, commonjs: true }, context.options[0]); | |
return (0, _moduleVisitor2['default'])(reportIfAbsolute, options); | |
}, | |
}, | |
"no-nodejs-modules": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid Node.js builtin modules.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-nodejs-modules.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var allowed = options.allow || []; | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfMissing(context, node, allowed, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
"no-webpack-loader-syntax": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid webpack loader syntax in imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-webpack-loader-syntax.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return (0, _moduleVisitor2['default'])(function (source, node) { | |
reportIfNonStandard(context, node, source.value); | |
}, { commonjs: true }); | |
}, | |
}, | |
order: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a convention in module import order.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/order.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
groups: { | |
type: "array", | |
}, | |
pathGroupsExcludedImportTypes: { | |
type: "array", | |
}, | |
distinctGroup: { | |
type: "boolean", | |
default: true, | |
}, | |
pathGroups: { | |
type: "array", | |
items: { | |
type: "object", | |
properties: { | |
pattern: { | |
type: "string", | |
}, | |
patternOptions: { | |
type: "object", | |
}, | |
group: { | |
type: "string", | |
enum: [ | |
"builtin", | |
"external", | |
"internal", | |
"unknown", | |
"parent", | |
"sibling", | |
"index", | |
"object", | |
"type", | |
], | |
}, | |
position: { | |
type: "string", | |
enum: [ | |
"after", | |
"before", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"pattern", | |
"group", | |
], | |
}, | |
}, | |
"newlines-between": { | |
enum: [ | |
"ignore", | |
"always", | |
"always-and-inside-groups", | |
"never", | |
], | |
}, | |
alphabetize: { | |
type: "object", | |
properties: { | |
caseInsensitive: { | |
type: "boolean", | |
default: false, | |
}, | |
order: { | |
enum: [ | |
"ignore", | |
"asc", | |
"desc", | |
], | |
default: "ignore", | |
}, | |
orderImportKind: { | |
enum: [ | |
"ignore", | |
"asc", | |
"desc", | |
], | |
default: "ignore", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
warnOnUnassignedImports: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function importOrderRule(context) { | |
var options = context.options[0] || {}; | |
var newlinesBetweenImports = options['newlines-between'] || 'ignore'; | |
var pathGroupsExcludedImportTypes = new Set(options.pathGroupsExcludedImportTypes || ['builtin', 'external', 'object']); | |
var alphabetize = getAlphabetizeConfig(options); | |
var distinctGroup = options.distinctGroup == null ? defaultDistinctGroup : !!options.distinctGroup; | |
var ranks = void 0; | |
try {var _convertPathGroupsFor = | |
convertPathGroupsForRanks(options.pathGroups || []),pathGroups = _convertPathGroupsFor.pathGroups,maxPosition = _convertPathGroupsFor.maxPosition;var _convertGroupsToRanks = | |
convertGroupsToRanks(options.groups || defaultGroups),groups = _convertGroupsToRanks.groups,omittedTypes = _convertGroupsToRanks.omittedTypes; | |
ranks = { | |
groups: groups, | |
omittedTypes: omittedTypes, | |
pathGroups: pathGroups, | |
maxPosition: maxPosition }; | |
} catch (error) { | |
// Malformed configuration | |
return { | |
Program: function () {function Program(node) { | |
context.report(node, error.message); | |
}return Program;}() }; | |
} | |
var importMap = new Map(); | |
function getBlockImports(node) { | |
if (!importMap.has(node)) { | |
importMap.set(node, []); | |
} | |
return importMap.get(node); | |
} | |
return { | |
ImportDeclaration: function () {function handleImports(node) { | |
// Ignoring unassigned imports unless warnOnUnassignedImports is set | |
if (node.specifiers.length || options.warnOnUnassignedImports) { | |
var name = node.source.value; | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: name, | |
displayName: name, | |
type: 'import' }, | |
ranks, | |
getBlockImports(node.parent), | |
pathGroupsExcludedImportTypes); | |
} | |
}return handleImports;}(), | |
TSImportEqualsDeclaration: function () {function handleImports(node) { | |
var displayName = void 0; | |
var value = void 0; | |
var type = void 0; | |
// skip "export import"s | |
if (node.isExport) { | |
return; | |
} | |
if (node.moduleReference.type === 'TSExternalModuleReference') { | |
value = node.moduleReference.expression.value; | |
displayName = value; | |
type = 'import'; | |
} else { | |
value = ''; | |
displayName = context.getSourceCode().getText(node.moduleReference); | |
type = 'import:object'; | |
} | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: value, | |
displayName: displayName, | |
type: type }, | |
ranks, | |
getBlockImports(node.parent), | |
pathGroupsExcludedImportTypes); | |
}return handleImports;}(), | |
CallExpression: function () {function handleRequires(node) { | |
if (!(0, _staticRequire2['default'])(node)) { | |
return; | |
} | |
var block = getRequireBlock(node); | |
if (!block) { | |
return; | |
} | |
var name = node.arguments[0].value; | |
registerNode( | |
context, | |
{ | |
node: node, | |
value: name, | |
displayName: name, | |
type: 'require' }, | |
ranks, | |
getBlockImports(block), | |
pathGroupsExcludedImportTypes); | |
}return handleRequires;}(), | |
'Program:exit': function () {function reportAndReset() { | |
importMap.forEach(function (imported) { | |
if (newlinesBetweenImports !== 'ignore') { | |
makeNewlinesBetweenReport(context, imported, newlinesBetweenImports, distinctGroup); | |
} | |
if (alphabetize.order !== 'ignore') { | |
mutateRanksToAlphabetize(imported, alphabetize); | |
} | |
makeOutOfOrderReport(context, imported); | |
}); | |
importMap.clear(); | |
}return reportAndReset;}() }; | |
}, | |
}, | |
"newline-after-import": { | |
meta: { | |
type: "layout", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a newline after import statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/newline-after-import.md", | |
}, | |
fixable: "whitespace", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
count: { | |
type: "integer", | |
minimum: 1, | |
}, | |
exactCount: { | |
type: "boolean", | |
}, | |
considerComments: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var level = 0; | |
var requireCalls = []; | |
var options = Object.assign({ | |
count: 1, | |
exactCount: false, | |
considerComments: false }, | |
context.options[0]); | |
function checkForNewLine(node, nextNode, type) { | |
if (isExportDefaultClass(nextNode) || isExportNameClass(nextNode)) { | |
var classNode = nextNode.declaration; | |
if (isClassWithDecorator(classNode)) { | |
nextNode = classNode.decorators[0]; | |
} | |
} else if (isClassWithDecorator(nextNode)) { | |
nextNode = nextNode.decorators[0]; | |
} | |
var lineDifference = getLineDifference(node, nextNode); | |
var EXPECTED_LINE_DIFFERENCE = options.count + 1; | |
if ( | |
lineDifference < EXPECTED_LINE_DIFFERENCE || | |
options.exactCount && lineDifference !== EXPECTED_LINE_DIFFERENCE) | |
{ | |
var column = node.loc.start.column; | |
if (node.loc.start.line !== node.loc.end.line) { | |
column = 0; | |
} | |
context.report({ | |
loc: { | |
line: node.loc.end.line, | |
column: column }, | |
message: 'Expected ' + String(options.count) + ' empty line' + (options.count > 1 ? 's' : '') + ' after ' + String(type) + ' statement not followed by another ' + String(type) + '.', | |
fix: options.exactCount && EXPECTED_LINE_DIFFERENCE < lineDifference ? undefined : function (fixer) {return fixer.insertTextAfter( | |
node, | |
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference));} }); | |
} | |
} | |
function commentAfterImport(node, nextComment) { | |
var lineDifference = getLineDifference(node, nextComment); | |
var EXPECTED_LINE_DIFFERENCE = options.count + 1; | |
if (lineDifference < EXPECTED_LINE_DIFFERENCE) { | |
var column = node.loc.start.column; | |
if (node.loc.start.line !== node.loc.end.line) { | |
column = 0; | |
} | |
context.report({ | |
loc: { | |
line: node.loc.end.line, | |
column: column }, | |
message: 'Expected ' + String(options.count) + ' empty line' + (options.count > 1 ? 's' : '') + ' after import statement not followed by another import.', | |
fix: options.exactCount && EXPECTED_LINE_DIFFERENCE < lineDifference ? undefined : function (fixer) {return fixer.insertTextAfter( | |
node, | |
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference));} }); | |
} | |
} | |
function incrementLevel() { | |
level++; | |
} | |
function decrementLevel() { | |
level--; | |
} | |
function checkImport(node) {var | |
parent = node.parent; | |
if (!parent || !parent.body) { | |
return; | |
} | |
var nodePosition = parent.body.indexOf(node); | |
var nextNode = parent.body[nodePosition + 1]; | |
var endLine = node.loc.end.line; | |
var nextComment = void 0; | |
if (typeof parent.comments !== 'undefined' && options.considerComments) { | |
nextComment = parent.comments.find(function (o) {return o.loc.start.line >= endLine && o.loc.start.line <= endLine + options.count + 1;}); | |
} | |
// skip "export import"s | |
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) { | |
return; | |
} | |
if (nextComment && typeof nextComment !== 'undefined') { | |
commentAfterImport(node, nextComment); | |
} else if (nextNode && nextNode.type !== 'ImportDeclaration' && (nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)) { | |
checkForNewLine(node, nextNode, 'import'); | |
} | |
} | |
return { | |
ImportDeclaration: checkImport, | |
TSImportEqualsDeclaration: checkImport, | |
CallExpression: function () {function CallExpression(node) { | |
if ((0, _staticRequire2['default'])(node) && level === 0) { | |
requireCalls.push(node); | |
} | |
}return CallExpression;}(), | |
'Program:exit': function () {function ProgramExit() { | |
log('exit processing for', context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()); | |
var scopeBody = getScopeBody(context.getScope()); | |
log('got scope:', scopeBody); | |
requireCalls.forEach(function (node, index) { | |
var nodePosition = findNodeIndexInScopeBody(scopeBody, node); | |
log('node position in scope:', nodePosition); | |
var statementWithRequireCall = scopeBody[nodePosition]; | |
var nextStatement = scopeBody[nodePosition + 1]; | |
var nextRequireCall = requireCalls[index + 1]; | |
if (nextRequireCall && containsNodeOrEqual(statementWithRequireCall, nextRequireCall)) { | |
return; | |
} | |
if ( | |
nextStatement && ( | |
!nextRequireCall || | |
!containsNodeOrEqual(nextStatement, nextRequireCall))) | |
{ | |
checkForNewLine(statementWithRequireCall, nextStatement, 'require'); | |
} | |
}); | |
}return ProgramExit;}(), | |
FunctionDeclaration: incrementLevel, | |
FunctionExpression: incrementLevel, | |
ArrowFunctionExpression: incrementLevel, | |
BlockStatement: incrementLevel, | |
ObjectExpression: incrementLevel, | |
Decorator: incrementLevel, | |
'FunctionDeclaration:exit': decrementLevel, | |
'FunctionExpression:exit': decrementLevel, | |
'ArrowFunctionExpression:exit': decrementLevel, | |
'BlockStatement:exit': decrementLevel, | |
'ObjectExpression:exit': decrementLevel, | |
'Decorator:exit': decrementLevel }; | |
}, | |
}, | |
"prefer-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Prefer a default export if module exports a single name or multiple names.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/prefer-default-export.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
target: { | |
type: "string", | |
enum: [ | |
"single", | |
"any", | |
], | |
default: "single", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var specifierExportCount = 0; | |
var hasDefaultExport = false; | |
var hasStarExport = false; | |
var hasTypeExport = false; | |
var namedExportNode = null; | |
// get options. by default we look into files with single export | |
var _ref = context.options[0] || {},_ref$target = _ref.target,target = _ref$target === undefined ? 'single' : _ref$target; | |
function captureDeclaration(identifierOrPattern) { | |
if (identifierOrPattern && identifierOrPattern.type === 'ObjectPattern') { | |
// recursively capture | |
identifierOrPattern.properties. | |
forEach(function (property) { | |
captureDeclaration(property.value); | |
}); | |
} else if (identifierOrPattern && identifierOrPattern.type === 'ArrayPattern') { | |
identifierOrPattern.elements. | |
forEach(captureDeclaration); | |
} else { | |
// assume it's a single standard identifier | |
specifierExportCount++; | |
} | |
} | |
return { | |
ExportDefaultSpecifier: function () {function ExportDefaultSpecifier() { | |
hasDefaultExport = true; | |
}return ExportDefaultSpecifier;}(), | |
ExportSpecifier: function () {function ExportSpecifier(node) { | |
if ((node.exported.name || node.exported.value) === 'default') { | |
hasDefaultExport = true; | |
} else { | |
specifierExportCount++; | |
namedExportNode = node; | |
} | |
}return ExportSpecifier;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
// if there are specifiers, node.declaration should be null | |
if (!node.declaration) {return;}var | |
type = node.declaration.type; | |
if ( | |
type === 'TSTypeAliasDeclaration' || | |
type === 'TypeAlias' || | |
type === 'TSInterfaceDeclaration' || | |
type === 'InterfaceDeclaration') | |
{ | |
specifierExportCount++; | |
hasTypeExport = true; | |
return; | |
} | |
if (node.declaration.declarations) { | |
node.declaration.declarations.forEach(function (declaration) { | |
captureDeclaration(declaration.id); | |
}); | |
} else { | |
// captures 'export function foo() {}' syntax | |
specifierExportCount++; | |
} | |
namedExportNode = node; | |
}return ExportNamedDeclaration;}(), | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration() { | |
hasDefaultExport = true; | |
}return ExportDefaultDeclaration;}(), | |
ExportAllDeclaration: function () {function ExportAllDeclaration() { | |
hasStarExport = true; | |
}return ExportAllDeclaration;}(), | |
'Program:exit': function () {function ProgramExit() { | |
if (hasDefaultExport || hasStarExport || hasTypeExport) { | |
return; | |
} | |
if (target === 'single' && specifierExportCount === 1) { | |
context.report(namedExportNode, SINGLE_EXPORT_ERROR_MESSAGE); | |
} else if (target === 'any' && specifierExportCount > 0) { | |
context.report(namedExportNode, ANY_EXPORT_ERROR_MESSAGE); | |
} | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"no-default-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid default exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-default-export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
var preferNamed = 'Prefer named exports.'; | |
var noAliasDefault = function () {function noAliasDefault(_ref) {var local = _ref.local;return 'Do not alias `' + String(local.name) + '` as `default`. Just export `' + String(local.name) + '` itself instead.';}return noAliasDefault;}(); | |
return { | |
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) {var _ref2 = | |
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref2.loc; | |
context.report({ node: node, message: preferNamed, loc: loc }); | |
}return ExportDefaultDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
node.specifiers. | |
filter(function (specifier) {return (specifier.exported.name || specifier.exported.value) === 'default';}). | |
forEach(function (specifier) {var _ref3 = | |
context.getSourceCode().getFirstTokens(node)[1] || {},loc = _ref3.loc; | |
if (specifier.type === 'ExportDefaultSpecifier') { | |
context.report({ node: node, message: preferNamed, loc: loc }); | |
} else if (specifier.type === 'ExportSpecifier') { | |
context.report({ node: node, message: noAliasDefault(specifier), loc: loc }); | |
} | |
}); | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-named-export": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid named exports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-named-export.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
var message = 'Named exports are not allowed.'; | |
return { | |
ExportAllDeclaration: function () {function ExportAllDeclaration(node) { | |
context.report({ node: node, message: message }); | |
}return ExportAllDeclaration;}(), | |
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) { | |
if (node.specifiers.length === 0) { | |
return context.report({ node: node, message: message }); | |
} | |
var someNamed = node.specifiers.some(function (specifier) {return (specifier.exported.name || specifier.exported.value) !== 'default';}); | |
if (someNamed) { | |
context.report({ node: node, message: message }); | |
} | |
}return ExportNamedDeclaration;}() }; | |
}, | |
}, | |
"no-dynamic-require": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid `require()` calls with expressions.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-dynamic-require.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
esmodule: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
return { | |
CallExpression: function () {function CallExpression(node) { | |
if (!node.arguments[0] || isStaticValue(node.arguments[0])) { | |
return; | |
} | |
if (isRequire(node)) { | |
return context.report({ | |
node: node, | |
message: 'Calls to require() should use string literals' }); | |
} | |
if (options.esmodule && isDynamicImport(node)) { | |
return context.report({ | |
node: node, | |
message: dynamicImportErrorMessage }); | |
} | |
}return CallExpression;}(), | |
ImportExpression: function () {function ImportExpression(node) { | |
if (!options.esmodule || isStaticValue(node.source)) { | |
return; | |
} | |
return context.report({ | |
node: node, | |
message: dynamicImportErrorMessage }); | |
}return ImportExpression;}() }; | |
}, | |
}, | |
unambiguous: { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Module systems", | |
description: "Forbid potentially ambiguous parse goal (`script` vs. `module`).", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/unambiguous.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
// ignore non-modules | |
if (context.parserOptions.sourceType !== 'module') { | |
return {}; | |
} | |
return { | |
Program: function () {function Program(ast) { | |
if (!(0, _unambiguous.isModule)(ast)) { | |
context.report({ | |
node: ast, | |
message: 'This module could be parsed as a valid script.' }); | |
} | |
}return Program;}() }; | |
}, | |
}, | |
"no-unassigned-import": { | |
create: function create(context) { | |
var options = context.options[0] || {}; | |
var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var isAllow = function isAllow(source) {return testIsAllow(options.allow, filename, source);}; | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (node.specifiers.length === 0 && !isAllow(node.source.value)) { | |
report(context, node); | |
} | |
}return ImportDeclaration;}(), | |
ExpressionStatement: function () {function ExpressionStatement(node) { | |
if ( | |
node.expression.type === 'CallExpression' && | |
(0, _staticRequire2['default'])(node.expression) && | |
!isAllow(node.expression.arguments[0].value)) | |
{ | |
report(context, node.expression); | |
} | |
}return ExpressionStatement;}() }; | |
}, | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Forbid unassigned imports", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-unassigned-import.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
devDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
optionalDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
peerDependencies: { | |
type: [ | |
"boolean", | |
"array", | |
], | |
}, | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-useless-path-segments": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Static analysis", | |
description: "Forbid unnecessary path segments in import and require statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-useless-path-segments.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
commonjs: { | |
type: "boolean", | |
}, | |
noUselessIndex: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var currentDir = _path2['default'].dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()); | |
var options = context.options[0]; | |
function checkSourceValue(source) {var | |
importPath = source.value; | |
function reportWithProposedPath(proposedPath) { | |
context.report({ | |
node: source, | |
// Note: Using messageIds is not possible due to the support for ESLint 2 and 3 | |
message: 'Useless path segments for "' + String(importPath) + '", should be "' + String(proposedPath) + '"', | |
fix: function () {function fix(fixer) {return proposedPath && fixer.replaceText(source, JSON.stringify(proposedPath));}return fix;}() }); | |
} | |
// Only relative imports are relevant for this rule --> Skip checking | |
if (!importPath.startsWith('.')) { | |
return; | |
} | |
// Report rule violation if path is not the shortest possible | |
var resolvedPath = (0, _resolve2['default'])(importPath, context); | |
var normedPath = normalize(importPath); | |
var resolvedNormedPath = (0, _resolve2['default'])(normedPath, context); | |
if (normedPath !== importPath && resolvedPath === resolvedNormedPath) { | |
return reportWithProposedPath(normedPath); | |
} | |
var fileExtensions = (0, _ignore.getFileExtensions)(context.settings); | |
var regexUnnecessaryIndex = new RegExp('.*\\/index(\\' + String( | |
Array.from(fileExtensions).join('|\\')) + ')?$'); | |
// Check if path contains unnecessary index (including a configured extension) | |
if (options && options.noUselessIndex && regexUnnecessaryIndex.test(importPath)) { | |
var parentDirectory = _path2['default'].dirname(importPath); | |
// Try to find ambiguous imports | |
if (parentDirectory !== '.' && parentDirectory !== '..') {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = fileExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var fileExtension = _step.value; | |
if ((0, _resolve2['default'])('' + String(parentDirectory) + String(fileExtension), context)) { | |
return reportWithProposedPath(String(parentDirectory) + '/'); | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
} | |
return reportWithProposedPath(parentDirectory); | |
} | |
// Path is shortest possible + starts from the current directory --> Return directly | |
if (importPath.startsWith('./')) { | |
return; | |
} | |
// Path is not existing --> Return directly (following code requires path to be defined) | |
if (resolvedPath === undefined) { | |
return; | |
} | |
var expected = _path2['default'].relative(currentDir, resolvedPath); // Expected import path | |
var expectedSplit = expected.split(_path2['default'].sep); // Split by / or \ (depending on OS) | |
var importPathSplit = importPath.replace(/^\.\//, '').split('/'); | |
var countImportPathRelativeParents = countRelativeParents(importPathSplit); | |
var countExpectedRelativeParents = countRelativeParents(expectedSplit); | |
var diff = countImportPathRelativeParents - countExpectedRelativeParents; | |
// Same number of relative parents --> Paths are the same --> Return directly | |
if (diff <= 0) { | |
return; | |
} | |
// Report and propose minimal number of required relative parents | |
return reportWithProposedPath( | |
toRelativePath( | |
importPathSplit. | |
slice(0, countExpectedRelativeParents). | |
concat(importPathSplit.slice(countImportPathRelativeParents + diff)). | |
join('/'))); | |
} | |
return (0, _moduleVisitor2['default'])(checkSourceValue, options); | |
}, | |
}, | |
"dynamic-import-chunkname": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Enforce a leading comment with the webpackChunkName for dynamic imports.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/dynamic-import-chunkname.md", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
importFunctions: { | |
type: "array", | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
webpackChunknameFormat: { | |
type: "string", | |
}, | |
}, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var config = context.options[0];var _ref = | |
config || {},_ref$importFunctions = _ref.importFunctions,importFunctions = _ref$importFunctions === undefined ? [] : _ref$importFunctions;var _ref2 = | |
config || {},_ref2$webpackChunknam = _ref2.webpackChunknameFormat,webpackChunknameFormat = _ref2$webpackChunknam === undefined ? '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' : _ref2$webpackChunknam; | |
var paddedCommentRegex = /^ (\S[\s\S]+\S) $/; | |
var commentStyleRegex = /^( ((webpackChunkName: .+)|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/; | |
var chunkSubstrFormat = ' webpackChunkName: ["\']' + String(webpackChunknameFormat) + '["\'],? '; | |
var chunkSubstrRegex = new RegExp(chunkSubstrFormat); | |
function run(node, arg) { | |
var sourceCode = context.getSourceCode(); | |
var leadingComments = sourceCode.getCommentsBefore ? | |
sourceCode.getCommentsBefore(arg) // This method is available in ESLint >= 4. | |
: sourceCode.getComments(arg).leading; // This method is deprecated in ESLint 7. | |
if (!leadingComments || leadingComments.length === 0) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a leading comment with the webpack chunkname' }); | |
return; | |
} | |
var isChunknamePresent = false;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = leadingComments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var comment = _step.value; | |
if (comment.type !== 'Block') { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a /* foo */ style comment, not a // foo comment' }); | |
return; | |
} | |
if (!paddedCommentRegex.test(comment.value)) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a block comment padded with spaces - /* foo */' }); | |
return; | |
} | |
try { | |
// just like webpack itself does | |
_vm2['default'].runInNewContext('(function() {return {' + String(comment.value) + '}})()'); | |
} catch (error) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a "webpack" comment with valid syntax' }); | |
return; | |
} | |
if (!commentStyleRegex.test(comment.value)) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a "webpack" comment with valid syntax' }); | |
return; | |
} | |
if (chunkSubstrRegex.test(comment.value)) { | |
isChunknamePresent = true; | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
if (!isChunknamePresent) { | |
context.report({ | |
node: node, | |
message: 'dynamic imports require a leading comment in the form /*' + | |
chunkSubstrFormat + '*/' }); | |
} | |
} | |
return { | |
ImportExpression: function () {function ImportExpression(node) { | |
run(node, node.source); | |
}return ImportExpression;}(), | |
CallExpression: function () {function CallExpression(node) { | |
if (node.callee.type !== 'Import' && importFunctions.indexOf(node.callee.name) < 0) { | |
return; | |
} | |
run(node, node.arguments[0]); | |
}return CallExpression;}() }; | |
}, | |
}, | |
"no-import-module-exports": { | |
meta: { | |
type: "problem", | |
docs: { | |
category: "Module systems", | |
description: "Forbid import statements with CommonJS module.exports.", | |
recommended: true, | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
exceptions: { | |
type: "array", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
create: function create(context) { | |
var importDeclarations = []; | |
var entryPoint = getEntryPoint(context); | |
var options = context.options[0] || {}; | |
var alreadyReported = false; | |
function report(node) { | |
var fileName = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); | |
var isEntryPoint = entryPoint === fileName; | |
var isIdentifier = node.object.type === 'Identifier'; | |
var hasKeywords = /^(module|exports)$/.test(node.object.name); | |
var objectScope = hasKeywords && findScope(context, node.object.name); | |
var variableDefinition = objectScope && findDefinition(objectScope, node.object.name); | |
var isImportBinding = variableDefinition && variableDefinition.type === 'ImportBinding'; | |
var hasCJSExportReference = hasKeywords && (!objectScope || objectScope.type === 'module'); | |
var isException = !!options.exceptions && options.exceptions.some(function (glob) {return (0, _minimatch2['default'])(fileName, glob);}); | |
if (isIdentifier && hasCJSExportReference && !isEntryPoint && !isException && !isImportBinding) { | |
importDeclarations.forEach(function (importDeclaration) { | |
context.report({ | |
node: importDeclaration, | |
message: 'Cannot use import declarations in modules that export using CommonJS (module.exports = \'foo\' or exports.bar = \'hi\')' }); | |
}); | |
alreadyReported = true; | |
} | |
} | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
importDeclarations.push(node); | |
}return ImportDeclaration;}(), | |
MemberExpression: function () {function MemberExpression(node) { | |
if (!alreadyReported) { | |
report(node); | |
} | |
}return MemberExpression;}() }; | |
}, | |
}, | |
"no-empty-named-blocks": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid empty named import blocks.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-empty-named-blocks.md", | |
}, | |
fixable: "code", | |
schema: [ | |
], | |
hasSuggestions: true, | |
}, | |
create: function create(context) { | |
var importsWithoutNameds = []; | |
return { | |
ImportDeclaration: function () {function ImportDeclaration(node) { | |
if (!node.specifiers.some(function (x) {return x.type === 'ImportSpecifier';})) { | |
importsWithoutNameds.push(node); | |
} | |
}return ImportDeclaration;}(), | |
'Program:exit': function () {function ProgramExit(program) { | |
var importsTokens = importsWithoutNameds.map(function (node) {return [node, program.tokens.filter(function (x) {return x.range[0] >= node.range[0] && x.range[1] <= node.range[1];})];}); | |
importsTokens.forEach(function (_ref) {var _ref2 = _slicedToArray(_ref, 2),node = _ref2[0],tokens = _ref2[1]; | |
tokens.forEach(function (token) { | |
var idx = program.tokens.indexOf(token); | |
var nextToken = program.tokens[idx + 1]; | |
if (nextToken && token.value === '{' && nextToken.value === '}') { | |
var hasOtherIdentifiers = tokens.some(function (token) {return token.type === 'Identifier' && | |
token.value !== 'from' && | |
token.value !== 'type' && | |
token.value !== 'typeof';}); | |
// If it has no other identifiers it's the only thing in the import, so we can either remove the import | |
// completely or transform it in a side-effects only import | |
if (!hasOtherIdentifiers) { | |
context.report({ | |
node: node, | |
message: 'Unexpected empty named import block', | |
suggest: [ | |
{ | |
desc: 'Remove unused import', | |
fix: function () {function fix(fixer) { | |
// Remove the whole import | |
return fixer.remove(node); | |
}return fix;}() }, | |
{ | |
desc: 'Remove empty import block', | |
fix: function () {function fix(fixer) { | |
// Remove the empty block and the 'from' token, leaving the import only for its side | |
// effects, e.g. `import 'mod'` | |
var sourceCode = context.getSourceCode(); | |
var fromToken = program.tokens.find(function (t) {return t.value === 'from';}); | |
var importToken = program.tokens.find(function (t) {return t.value === 'import';}); | |
var hasSpaceAfterFrom = sourceCode.isSpaceBetween(fromToken, sourceCode.getTokenAfter(fromToken)); | |
var hasSpaceAfterImport = sourceCode.isSpaceBetween(importToken, sourceCode.getTokenAfter(fromToken));var _getEmptyBlockRange = | |
getEmptyBlockRange(program.tokens, idx),_getEmptyBlockRange2 = _slicedToArray(_getEmptyBlockRange, 1),start = _getEmptyBlockRange2[0];var _fromToken$range = _slicedToArray( | |
fromToken.range, 2),end = _fromToken$range[1]; | |
var range = [start, hasSpaceAfterFrom ? end + 1 : end]; | |
return fixer.replaceTextRange(range, hasSpaceAfterImport ? '' : ' '); | |
}return fix;}() }] }); | |
} else { | |
context.report({ | |
node: node, | |
message: 'Unexpected empty named import block', | |
fix: function () {function fix(fixer) { | |
return fixer.removeRange(getEmptyBlockRange(program.tokens, idx)); | |
}return fix;}() }); | |
} | |
} | |
}); | |
}); | |
}return ProgramExit;}() }; | |
}, | |
}, | |
"exports-last": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Ensure all exports appear after other statements.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/exports-last.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
return { | |
Program: function () {function Program(_ref2) {var body = _ref2.body; | |
var lastNonExportStatementIndex = (0, _arrayPrototype2['default'])(body, isNonExportStatement); | |
if (lastNonExportStatementIndex !== -1) { | |
body.slice(0, lastNonExportStatementIndex).forEach(function (node) { | |
if (!isNonExportStatement(node)) { | |
context.report({ | |
node: node, | |
message: 'Export statements should appear at the end of the file' }); | |
} | |
}); | |
} | |
}return Program;}() }; | |
}, | |
}, | |
"no-deprecated": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Helpful warnings", | |
description: "Forbid imported names marked with `@deprecated` documentation tag.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/no-deprecated.md", | |
}, | |
schema: [ | |
], | |
}, | |
create: function create(context) { | |
var deprecated = new Map(); | |
var namespaces = new Map(); | |
function checkSpecifiers(node) { | |
if (node.type !== 'ImportDeclaration') {return;} | |
if (node.source == null) {return;} // local export, ignore | |
var imports = _ExportMap2['default'].get(node.source.value, context); | |
if (imports == null) {return;} | |
var moduleDeprecation = imports.doc && imports.doc.tags.find(function (t) {return t.title === 'deprecated';}); | |
if (moduleDeprecation) { | |
context.report({ node: node, message: message(moduleDeprecation) }); | |
} | |
if (imports.errors.length) { | |
imports.reportErrors(context, node); | |
return; | |
} | |
node.specifiers.forEach(function (im) { | |
var imported = void 0;var local = void 0; | |
switch (im.type) { | |
case 'ImportNamespaceSpecifier':{ | |
if (!imports.size) {return;} | |
namespaces.set(im.local.name, imports); | |
return; | |
} | |
case 'ImportDefaultSpecifier': | |
imported = 'default'; | |
local = im.local.name; | |
break; | |
case 'ImportSpecifier': | |
imported = im.imported.name; | |
local = im.local.name; | |
break; | |
default:return; // can't handle this one | |
} | |
// unknown thing can't be deprecated | |
var exported = imports.get(imported); | |
if (exported == null) {return;} | |
// capture import of deep namespace | |
if (exported.namespace) {namespaces.set(local, exported.namespace);} | |
var deprecation = getDeprecation(imports.get(imported)); | |
if (!deprecation) {return;} | |
context.report({ node: im, message: message(deprecation) }); | |
deprecated.set(local, deprecation); | |
}); | |
} | |
return { | |
Program: function () {function Program(_ref) {var body = _ref.body;return body.forEach(checkSpecifiers);}return Program;}(), | |
Identifier: function () {function Identifier(node) { | |
if (node.parent.type === 'MemberExpression' && node.parent.property === node) { | |
return; // handled by MemberExpression | |
} | |
// ignore specifier identifiers | |
if (node.parent.type.slice(0, 6) === 'Import') {return;} | |
if (!deprecated.has(node.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, node.name) !== 'module') {return;} | |
context.report({ | |
node: node, | |
message: message(deprecated.get(node.name)) }); | |
}return Identifier;}(), | |
MemberExpression: function () {function MemberExpression(dereference) { | |
if (dereference.object.type !== 'Identifier') {return;} | |
if (!namespaces.has(dereference.object.name)) {return;} | |
if ((0, _declaredScope2['default'])(context, dereference.object.name) !== 'module') {return;} | |
// go deep | |
var namespace = namespaces.get(dereference.object.name); | |
var namepath = [dereference.object.name]; | |
// while property is namespace and parent is member expression, keep validating | |
while (namespace instanceof _ExportMap2['default'] && dereference.type === 'MemberExpression') { | |
// ignore computed parts for now | |
if (dereference.computed) {return;} | |
var metadata = namespace.get(dereference.property.name); | |
if (!metadata) {break;} | |
var deprecation = getDeprecation(metadata); | |
if (deprecation) { | |
context.report({ node: dereference.property, message: message(deprecation) }); | |
} | |
// stash and pop | |
namepath.push(dereference.property.name); | |
namespace = metadata.namespace; | |
dereference = dereference.parent; | |
} | |
}return MemberExpression;}() }; | |
}, | |
}, | |
"imports-first": { | |
meta: { | |
type: "suggestion", | |
docs: { | |
category: "Style guide", | |
description: "Replaced by `import/first`.", | |
url: "https://github.com/import-js/eslint-plugin-import/blob/7b25c1cb95ee18acc1531002fd343e1e6031f9ed/docs/rules/imports-first.md", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"absolute-first", | |
"disable-absolute-first", | |
], | |
}, | |
], | |
deprecated: true, | |
}, | |
create: function create(context) { | |
function isPossibleDirective(node) { | |
return node.type === 'ExpressionStatement' && | |
node.expression.type === 'Literal' && | |
typeof node.expression.value === 'string'; | |
} | |
return { | |
Program: function () {function Program(n) { | |
var body = n.body; | |
if (!body) { | |
return; | |
} | |
var absoluteFirst = context.options[0] === 'absolute-first'; | |
var message = 'Import in body of module; reorder to top.'; | |
var sourceCode = context.getSourceCode(); | |
var originSourceCode = sourceCode.getText(); | |
var nonImportCount = 0; | |
var anyExpressions = false; | |
var anyRelative = false; | |
var lastLegalImp = null; | |
var errorInfos = []; | |
var shouldSort = true; | |
var lastSortNodesIndex = 0; | |
body.forEach(function (node, index) { | |
if (!anyExpressions && isPossibleDirective(node)) { | |
return; | |
} | |
anyExpressions = true; | |
if (node.type === 'ImportDeclaration' || node.type === 'TSImportEqualsDeclaration') { | |
if (absoluteFirst) { | |
if (/^\./.test(getImportValue(node))) { | |
anyRelative = true; | |
} else if (anyRelative) { | |
context.report({ | |
node: node.type === 'ImportDeclaration' ? node.source : node.moduleReference, | |
message: 'Absolute imports should come before relative imports.' }); | |
} | |
} | |
if (nonImportCount > 0) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try { | |
for (var _iterator = context.getDeclaredVariables(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value; | |
if (!shouldSort) {break;} | |
var references = variable.references; | |
if (references.length) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try { | |
for (var _iterator2 = references[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var reference = _step2.value; | |
if (reference.identifier.range[0] < node.range[1]) { | |
shouldSort = false; | |
break; | |
} | |
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}} | |
} | |
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}} | |
shouldSort && (lastSortNodesIndex = errorInfos.length); | |
errorInfos.push({ | |
node: node, | |
range: [body[index - 1].range[1], node.range[1]] }); | |
} else { | |
lastLegalImp = node; | |
} | |
} else { | |
nonImportCount++; | |
} | |
}); | |
if (!errorInfos.length) {return;} | |
errorInfos.forEach(function (errorInfo, index) { | |
var node = errorInfo.node; | |
var infos = { | |
node: node, | |
message: message }; | |
if (index < lastSortNodesIndex) { | |
infos.fix = function (fixer) { | |
return fixer.insertTextAfter(node, ''); | |
}; | |
} else if (index === lastSortNodesIndex) { | |
var sortNodes = errorInfos.slice(0, lastSortNodesIndex + 1); | |
infos.fix = function (fixer) { | |
var removeFixers = sortNodes.map(function (_errorInfo) { | |
return fixer.removeRange(_errorInfo.range); | |
}); | |
var range = [0, removeFixers[removeFixers.length - 1].range[1]]; | |
var insertSourceCode = sortNodes.map(function (_errorInfo) { | |
var nodeSourceCode = String.prototype.slice.apply( | |
originSourceCode, _errorInfo.range); | |
if (/\S/.test(nodeSourceCode[0])) { | |
return '\n' + String(nodeSourceCode); | |
} | |
return nodeSourceCode; | |
}).join(''); | |
var insertFixer = null; | |
var replaceSourceCode = ''; | |
if (!lastLegalImp) { | |
insertSourceCode = insertSourceCode.trim() + insertSourceCode.match(/^(\s+)/)[0]; | |
} | |
insertFixer = lastLegalImp ? | |
fixer.insertTextAfter(lastLegalImp, insertSourceCode) : | |
fixer.insertTextBefore(body[0], insertSourceCode); | |
var fixers = [insertFixer].concat(removeFixers); | |
fixers.forEach(function (computedFixer, i) { | |
replaceSourceCode += originSourceCode.slice( | |
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]) + | |
computedFixer.text; | |
}); | |
return fixer.replaceTextRange(range, replaceSourceCode); | |
}; | |
} | |
context.report(infos); | |
}); | |
}return Program;}() }; | |
}, | |
}, | |
}, | |
configs: { | |
recommended: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-unresolved": "error", | |
"import/named": "error", | |
"import/namespace": "error", | |
"import/default": "error", | |
"import/export": "error", | |
"import/no-named-as-default": "warn", | |
"import/no-named-as-default-member": "warn", | |
"import/no-duplicates": "warn", | |
}, | |
parserOptions: { | |
sourceType: "module", | |
ecmaVersion: 2018, | |
}, | |
}, | |
errors: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-unresolved": 2, | |
"import/named": 2, | |
"import/namespace": 2, | |
"import/default": 2, | |
"import/export": 2, | |
}, | |
}, | |
warnings: { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-named-as-default": 1, | |
"import/no-named-as-default-member": 1, | |
"import/no-duplicates": 1, | |
}, | |
}, | |
"stage-0": { | |
plugins: [ | |
"import", | |
], | |
rules: { | |
"import/no-deprecated": 1, | |
}, | |
}, | |
react: { | |
settings: { | |
"import/extensions": [ | |
".js", | |
".jsx", | |
], | |
}, | |
parserOptions: { | |
ecmaFeatures: { | |
jsx: true, | |
}, | |
}, | |
}, | |
"react-native": { | |
settings: { | |
"import/resolver": { | |
node: { | |
extensions: [ | |
".js", | |
".web.js", | |
".ios.js", | |
".android.js", | |
], | |
}, | |
}, | |
}, | |
}, | |
electron: { | |
settings: { | |
"import/core-modules": [ | |
"electron", | |
], | |
}, | |
}, | |
typescript: { | |
settings: { | |
"import/extensions": [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
".js", | |
".jsx", | |
], | |
"import/external-module-folders": [ | |
"node_modules", | |
"node_modules/@types", | |
], | |
"import/parsers": { | |
"@typescript-eslint/parser": [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
], | |
}, | |
"import/resolver": { | |
node: { | |
extensions: [ | |
".ts", | |
".cts", | |
".mts", | |
".tsx", | |
".js", | |
".jsx", | |
], | |
}, | |
}, | |
}, | |
rules: { | |
"import/named": "off", | |
}, | |
}, | |
}, | |
}, | |
error: null, | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-plugin-import\\lib\\index.js", | |
id: "import", | |
importerName: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\imports.js", | |
importerPath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\imports.js", | |
}, | |
}, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
"import/no-unresolved": [ | |
"error", | |
{ | |
commonjs: true, | |
caseSensitive: true, | |
}, | |
], | |
"import/named": "error", | |
"import/default": "off", | |
"import/namespace": "off", | |
"import/export": "error", | |
"import/no-named-as-default": "error", | |
"import/no-named-as-default-member": "error", | |
"import/no-deprecated": "off", | |
"import/no-extraneous-dependencies": [ | |
"error", | |
{ | |
devDependencies: [ | |
"test/**", | |
"tests/**", | |
"spec/**", | |
"**/__tests__/**", | |
"**/__mocks__/**", | |
"test.{js,jsx}", | |
"test-*.{js,jsx}", | |
"**/*{.,_}{test,spec}.{js,jsx}", | |
"**/jest.config.js", | |
"**/jest.setup.js", | |
"**/vue.config.js", | |
"**/webpack.config.js", | |
"**/webpack.config.*.js", | |
"**/rollup.config.js", | |
"**/rollup.config.*.js", | |
"**/gulpfile.js", | |
"**/gulpfile.*.js", | |
"**/Gruntfile{,.js}", | |
"**/protractor.conf.js", | |
"**/protractor.conf.*.js", | |
"**/karma.conf.js", | |
"**/.eslintrc.js", | |
], | |
optionalDependencies: false, | |
}, | |
], | |
"import/no-mutable-exports": "error", | |
"import/no-commonjs": "off", | |
"import/no-amd": "error", | |
"import/no-nodejs-modules": "off", | |
"import/first": "error", | |
"import/imports-first": "off", | |
"import/no-duplicates": "error", | |
"import/no-namespace": "off", | |
"import/extensions": [ | |
"error", | |
"ignorePackages", | |
{ | |
js: "never", | |
mjs: "never", | |
jsx: "never", | |
}, | |
], | |
"import/order": [ | |
"error", | |
{ | |
groups: [ | |
[ | |
"builtin", | |
"external", | |
"internal", | |
], | |
], | |
}, | |
], | |
"import/newline-after-import": "error", | |
"import/prefer-default-export": "error", | |
"import/no-restricted-paths": "off", | |
"import/max-dependencies": [ | |
"off", | |
{ | |
max: 10, | |
}, | |
], | |
"import/no-absolute-path": "error", | |
"import/no-dynamic-require": "error", | |
"import/no-internal-modules": [ | |
"off", | |
{ | |
allow: [ | |
], | |
}, | |
], | |
"import/unambiguous": "off", | |
"import/no-webpack-loader-syntax": "error", | |
"import/no-unassigned-import": "off", | |
"import/no-named-default": "error", | |
"import/no-anonymous-default-export": [ | |
"off", | |
{ | |
allowArray: false, | |
allowArrowFunction: false, | |
allowAnonymousClass: false, | |
allowAnonymousFunction: false, | |
allowLiteral: false, | |
allowObject: false, | |
}, | |
], | |
"import/exports-last": "off", | |
"import/group-exports": "off", | |
"import/no-default-export": "off", | |
"import/no-named-export": "off", | |
"import/no-self-import": "error", | |
"import/no-cycle": [ | |
"error", | |
{ | |
maxDepth: "∞", | |
}, | |
], | |
"import/no-useless-path-segments": [ | |
"error", | |
{ | |
commonjs: true, | |
}, | |
], | |
"import/dynamic-import-chunkname": [ | |
"off", | |
{ | |
importFunctions: [ | |
], | |
webpackChunknameFormat: "[0-9a-zA-Z-_/.]+", | |
}, | |
], | |
"import/no-relative-parent-imports": "off", | |
"import/no-unused-modules": [ | |
"off", | |
{ | |
ignoreExports: [ | |
], | |
missingExports: true, | |
unusedExports: true, | |
}, | |
], | |
"import/no-import-module-exports": [ | |
"error", | |
{ | |
exceptions: [ | |
], | |
}, | |
], | |
"import/no-relative-packages": "error", | |
}, | |
settings: { | |
"import/resolver": { | |
node: { | |
extensions: [ | |
".mjs", | |
".js", | |
".json", | |
], | |
}, | |
}, | |
"import/extensions": [ | |
".js", | |
".mjs", | |
".jsx", | |
], | |
"import/core-modules": [ | |
], | |
"import/ignore": [ | |
"node_modules", | |
"\\.(coffee|scss|css|less|hbs|svg|json)$", | |
], | |
}, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\strict.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\rules\\strict.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
strict: [ | |
"error", | |
"never", | |
], | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » eslint-config-airbnb-base", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-airbnb-base\\index.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: { | |
ecmaVersion: 2018, | |
sourceType: "module", | |
}, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-moon\\lib\\base.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-moon\\lib\\base.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: undefined, | |
plugins: undefined, | |
processor: undefined, | |
reportUnusedDisableDirectives: undefined, | |
root: undefined, | |
rules: { | |
indent: [ | |
"error", | |
"tab", | |
], | |
"no-tabs": "off", | |
"class-methods-use-this": "off", | |
complexity: [ | |
"error", | |
11, | |
], | |
"multiline-comment-style": "off", | |
"prefer-destructuring": [ | |
"error", | |
{ | |
object: true, | |
array: false, | |
}, | |
], | |
"sort-keys": [ | |
"error", | |
"asc", | |
{ | |
caseSensitive: false, | |
natural: true, | |
}, | |
], | |
"no-constant-binary-expression": "error", | |
"no-constant-condition": "error", | |
"no-constructor-return": "error", | |
"no-div-regex": "error", | |
"no-dupe-else-if": "error", | |
"no-empty-static-block": "error", | |
"no-import-assign": "error", | |
"no-native-reassign": "error", | |
"no-new-native-nonconstructor": "error", | |
"no-promise-executor-return": "error", | |
"no-setter-return": "error", | |
"no-unreachable-loop": "error", | |
"no-unsafe-optional-chaining": [ | |
"error", | |
{ | |
disallowArithmeticOperators: true, | |
}, | |
], | |
"no-unused-private-class-members": "error", | |
"no-useless-call": "error", | |
"require-atomic-updates": "error", | |
"logical-assignment-operators": "error", | |
"prefer-exponentiation-operator": "error", | |
"prefer-regex-literals": [ | |
"error", | |
{ | |
disallowRedundantWrapping: true, | |
}, | |
], | |
"no-implicit-coercion": "error", | |
"no-magic-numbers": [ | |
"error", | |
{ | |
ignore: [ | |
-3, | |
-2, | |
-1, | |
0, | |
1, | |
2, | |
3, | |
], | |
ignoreArrayIndexes: true, | |
ignoreClassFieldInitialValues: true, | |
enforceConst: true, | |
}, | |
], | |
"require-unicode-regexp": "off", | |
"no-invalid-this": "off", | |
"no-restricted-syntax": "off", | |
"prefer-object-has-own": "error", | |
}, | |
settings: undefined, | |
}, | |
{ | |
type: "config", | |
name: " » eslint-config-moon » C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-moon\\lib\\typescript.js", | |
filePath: "C:\\Repos\\HaloSPV3\\hce.shared-config\\node_modules\\eslint-config-moon\\lib\\typescript.js", | |
criteria: null, | |
env: undefined, | |
globals: undefined, | |
ignorePattern: undefined, | |
noInlineConfig: undefined, | |
parser: undefined, | |
parserOptions: { | |
project: [ | |
"C:\\Repos\\HaloSPV3\\hce.shared-config\\tsconfig.json", | |
"C:\\Repos\\HaloSPV3\\hce.shared-config\\tests\\tsconfig.json", | |
"C:\\Repos\\HaloSPV3\\hce.shared-config\\src\\tsconfig.json", | |
], | |
}, | |
plugins: { | |
"@typescript-eslint": { | |
definition: { | |
configs: { | |
all: { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/adjacent-overload-signatures": "error", | |
"@typescript-eslint/array-type": "error", | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/ban-ts-comment": "error", | |
"@typescript-eslint/ban-tslint-comment": "error", | |
"@typescript-eslint/ban-types": "error", | |
"@typescript-eslint/class-literal-property-style": "error", | |
"class-methods-use-this": "off", | |
"@typescript-eslint/class-methods-use-this": "error", | |
"@typescript-eslint/consistent-generic-constructors": "error", | |
"@typescript-eslint/consistent-indexed-object-style": "error", | |
"consistent-return": "off", | |
"@typescript-eslint/consistent-return": "error", | |
"@typescript-eslint/consistent-type-assertions": "error", | |
"@typescript-eslint/consistent-type-definitions": "error", | |
"@typescript-eslint/consistent-type-exports": "error", | |
"@typescript-eslint/consistent-type-imports": "error", | |
"default-param-last": "off", | |
"@typescript-eslint/default-param-last": "error", | |
"dot-notation": "off", | |
"@typescript-eslint/dot-notation": "error", | |
"@typescript-eslint/explicit-function-return-type": "error", | |
"@typescript-eslint/explicit-member-accessibility": "error", | |
"@typescript-eslint/explicit-module-boundary-types": "error", | |
"init-declarations": "off", | |
"@typescript-eslint/init-declarations": "error", | |
"max-params": "off", | |
"@typescript-eslint/max-params": "error", | |
"@typescript-eslint/member-ordering": "error", | |
"@typescript-eslint/method-signature-style": "error", | |
"@typescript-eslint/naming-convention": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-array-delete": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-confusing-non-null-assertion": "error", | |
"@typescript-eslint/no-confusing-void-expression": "error", | |
"no-dupe-class-members": "off", | |
"@typescript-eslint/no-dupe-class-members": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-dynamic-delete": "error", | |
"no-empty-function": "off", | |
"@typescript-eslint/no-empty-function": "error", | |
"@typescript-eslint/no-empty-interface": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"@typescript-eslint/no-extraneous-class": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"@typescript-eslint/no-import-type-side-effects": "error", | |
"@typescript-eslint/no-inferrable-types": "error", | |
"no-invalid-this": "off", | |
"@typescript-eslint/no-invalid-this": "error", | |
"@typescript-eslint/no-invalid-void-type": "error", | |
"no-loop-func": "off", | |
"@typescript-eslint/no-loop-func": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"no-magic-numbers": "off", | |
"@typescript-eslint/no-magic-numbers": "error", | |
"@typescript-eslint/no-meaningless-void-operator": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-mixed-enums": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-non-null-assertion": "error", | |
"no-redeclare": "off", | |
"@typescript-eslint/no-redeclare": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-require-imports": "error", | |
"no-restricted-imports": "off", | |
"@typescript-eslint/no-restricted-imports": "error", | |
"no-shadow": "off", | |
"@typescript-eslint/no-shadow": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", | |
"@typescript-eslint/no-unnecessary-condition": "error", | |
"@typescript-eslint/no-unnecessary-qualifier": "error", | |
"@typescript-eslint/no-unnecessary-type-arguments": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"@typescript-eslint/no-unsafe-unary-minus": "error", | |
"no-unused-expressions": "off", | |
"@typescript-eslint/no-unused-expressions": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"no-use-before-define": "off", | |
"@typescript-eslint/no-use-before-define": "error", | |
"no-useless-constructor": "off", | |
"@typescript-eslint/no-useless-constructor": "error", | |
"@typescript-eslint/no-useless-empty-export": "error", | |
"@typescript-eslint/no-useless-template-literals": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"@typescript-eslint/non-nullable-type-assertion-style": "error", | |
"no-throw-literal": "off", | |
"@typescript-eslint/only-throw-error": "error", | |
"@typescript-eslint/parameter-properties": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"prefer-destructuring": "off", | |
"@typescript-eslint/prefer-destructuring": "error", | |
"@typescript-eslint/prefer-enum-initializers": "error", | |
"@typescript-eslint/prefer-find": "error", | |
"@typescript-eslint/prefer-for-of": "error", | |
"@typescript-eslint/prefer-function-type": "error", | |
"@typescript-eslint/prefer-includes": "error", | |
"@typescript-eslint/prefer-literal-enum-member": "error", | |
"@typescript-eslint/prefer-namespace-keyword": "error", | |
"@typescript-eslint/prefer-nullish-coalescing": "error", | |
"@typescript-eslint/prefer-optional-chain": "error", | |
"prefer-promise-reject-errors": "off", | |
"@typescript-eslint/prefer-promise-reject-errors": "error", | |
"@typescript-eslint/prefer-readonly": "error", | |
"@typescript-eslint/prefer-readonly-parameter-types": "error", | |
"@typescript-eslint/prefer-reduce-type-parameter": "error", | |
"@typescript-eslint/prefer-regexp-exec": "error", | |
"@typescript-eslint/prefer-return-this-type": "error", | |
"@typescript-eslint/prefer-string-starts-ends-with": "error", | |
"@typescript-eslint/prefer-ts-expect-error": "error", | |
"@typescript-eslint/promise-function-async": "error", | |
"@typescript-eslint/require-array-sort-compare": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": "error", | |
"@typescript-eslint/restrict-template-expressions": "error", | |
"no-return-await": "off", | |
"@typescript-eslint/return-await": "error", | |
"@typescript-eslint/sort-type-constituents": "error", | |
"@typescript-eslint/strict-boolean-expressions": "error", | |
"@typescript-eslint/switch-exhaustiveness-check": "error", | |
"@typescript-eslint/triple-slash-reference": "error", | |
"@typescript-eslint/typedef": "error", | |
"@typescript-eslint/unbound-method": "error", | |
"@typescript-eslint/unified-signatures": "error", | |
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error", | |
}, | |
}, | |
base: { | |
parser: "@typescript-eslint/parser", | |
parserOptions: { | |
sourceType: "module", | |
}, | |
plugins: [ | |
"@typescript-eslint", | |
], | |
}, | |
"disable-type-checked": { | |
parserOptions: { | |
project: false, | |
program: null, | |
}, | |
rules: { | |
"@typescript-eslint/await-thenable": "off", | |
"@typescript-eslint/consistent-return": "off", | |
"@typescript-eslint/consistent-type-exports": "off", | |
"@typescript-eslint/dot-notation": "off", | |
"@typescript-eslint/naming-convention": "off", | |
"@typescript-eslint/no-array-delete": "off", | |
"@typescript-eslint/no-base-to-string": "off", | |
"@typescript-eslint/no-confusing-void-expression": "off", | |
"@typescript-eslint/no-duplicate-type-constituents": "off", | |
"@typescript-eslint/no-floating-promises": "off", | |
"@typescript-eslint/no-for-in-array": "off", | |
"@typescript-eslint/no-implied-eval": "off", | |
"@typescript-eslint/no-meaningless-void-operator": "off", | |
"@typescript-eslint/no-misused-promises": "off", | |
"@typescript-eslint/no-mixed-enums": "off", | |
"@typescript-eslint/no-redundant-type-constituents": "off", | |
"@typescript-eslint/no-throw-literal": "off", | |
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off", | |
"@typescript-eslint/no-unnecessary-condition": "off", | |
"@typescript-eslint/no-unnecessary-qualifier": "off", | |
"@typescript-eslint/no-unnecessary-type-arguments": "off", | |
"@typescript-eslint/no-unnecessary-type-assertion": "off", | |
"@typescript-eslint/no-unsafe-argument": "off", | |
"@typescript-eslint/no-unsafe-assignment": "off", | |
"@typescript-eslint/no-unsafe-call": "off", | |
"@typescript-eslint/no-unsafe-enum-comparison": "off", | |
"@typescript-eslint/no-unsafe-member-access": "off", | |
"@typescript-eslint/no-unsafe-return": "off", | |
"@typescript-eslint/no-unsafe-unary-minus": "off", | |
"@typescript-eslint/no-useless-template-literals": "off", | |
"@typescript-eslint/non-nullable-type-assertion-style": "off", | |
"@typescript-eslint/only-throw-error": "off", | |
"@typescript-eslint/prefer-destructuring": "off", | |
"@typescript-eslint/prefer-find": "off", | |
"@typescript-eslint/prefer-includes": "off", | |
"@typescript-eslint/prefer-nullish-coalescing": "off", | |
"@typescript-eslint/prefer-optional-chain": "off", | |
"@typescript-eslint/prefer-promise-reject-errors": "off", | |
"@typescript-eslint/prefer-readonly": "off", | |
"@typescript-eslint/prefer-readonly-parameter-types": "off", | |
"@typescript-eslint/prefer-reduce-type-parameter": "off", | |
"@typescript-eslint/prefer-regexp-exec": "off", | |
"@typescript-eslint/prefer-return-this-type": "off", | |
"@typescript-eslint/prefer-string-starts-ends-with": "off", | |
"@typescript-eslint/promise-function-async": "off", | |
"@typescript-eslint/require-array-sort-compare": "off", | |
"@typescript-eslint/require-await": "off", | |
"@typescript-eslint/restrict-plus-operands": "off", | |
"@typescript-eslint/restrict-template-expressions": "off", | |
"@typescript-eslint/return-await": "off", | |
"@typescript-eslint/strict-boolean-expressions": "off", | |
"@typescript-eslint/switch-exhaustiveness-check": "off", | |
"@typescript-eslint/unbound-method": "off", | |
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off", | |
}, | |
}, | |
"eslint-recommended": { | |
overrides: [ | |
{ | |
files: [ | |
"*.ts", | |
"*.tsx", | |
"*.mts", | |
"*.cts", | |
], | |
rules: { | |
"constructor-super": "off", | |
"getter-return": "off", | |
"no-const-assign": "off", | |
"no-dupe-args": "off", | |
"no-dupe-class-members": "off", | |
"no-dupe-keys": "off", | |
"no-func-assign": "off", | |
"no-import-assign": "off", | |
"no-new-symbol": "off", | |
"no-new-native-nonconstructor": "off", | |
"no-obj-calls": "off", | |
"no-redeclare": "off", | |
"no-setter-return": "off", | |
"no-this-before-super": "off", | |
"no-undef": "off", | |
"no-unreachable": "off", | |
"no-unsafe-negation": "off", | |
"no-var": "error", | |
"prefer-const": "error", | |
"prefer-rest-params": "error", | |
"prefer-spread": "error", | |
}, | |
}, | |
], | |
}, | |
recommended: { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/ban-ts-comment": "error", | |
"@typescript-eslint/ban-types": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"@typescript-eslint/triple-slash-reference": "error", | |
}, | |
}, | |
"recommended-requiring-type-checking": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/ban-ts-comment": "error", | |
"@typescript-eslint/ban-types": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": "error", | |
"@typescript-eslint/restrict-template-expressions": "error", | |
"@typescript-eslint/triple-slash-reference": "error", | |
"@typescript-eslint/unbound-method": "error", | |
}, | |
}, | |
"recommended-type-checked": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/ban-ts-comment": "error", | |
"@typescript-eslint/ban-types": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": "error", | |
"@typescript-eslint/restrict-template-expressions": "error", | |
"@typescript-eslint/triple-slash-reference": "error", | |
"@typescript-eslint/unbound-method": "error", | |
}, | |
}, | |
"recommended-type-checked-only": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": "error", | |
"@typescript-eslint/restrict-template-expressions": "error", | |
"@typescript-eslint/unbound-method": "error", | |
}, | |
}, | |
strict: { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/ban-ts-comment": [ | |
"error", | |
{ | |
minimumDescriptionLength: 10, | |
}, | |
], | |
"@typescript-eslint/ban-types": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-dynamic-delete": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"@typescript-eslint/no-extraneous-class": "error", | |
"@typescript-eslint/no-invalid-void-type": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-non-null-assertion": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"no-useless-constructor": "off", | |
"@typescript-eslint/no-useless-constructor": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"@typescript-eslint/prefer-literal-enum-member": "error", | |
"@typescript-eslint/prefer-ts-expect-error": "error", | |
"@typescript-eslint/triple-slash-reference": "error", | |
"@typescript-eslint/unified-signatures": "error", | |
}, | |
}, | |
"strict-type-checked": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/ban-ts-comment": [ | |
"error", | |
{ | |
minimumDescriptionLength: 10, | |
}, | |
], | |
"@typescript-eslint/ban-types": "error", | |
"no-array-constructor": "off", | |
"@typescript-eslint/no-array-constructor": "error", | |
"@typescript-eslint/no-array-delete": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-confusing-void-expression": "error", | |
"@typescript-eslint/no-duplicate-enum-values": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-dynamic-delete": "error", | |
"@typescript-eslint/no-explicit-any": "error", | |
"@typescript-eslint/no-extra-non-null-assertion": "error", | |
"@typescript-eslint/no-extraneous-class": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"@typescript-eslint/no-invalid-void-type": "error", | |
"no-loss-of-precision": "off", | |
"@typescript-eslint/no-loss-of-precision": "error", | |
"@typescript-eslint/no-meaningless-void-operator": "error", | |
"@typescript-eslint/no-misused-new": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-mixed-enums": "error", | |
"@typescript-eslint/no-namespace": "error", | |
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error", | |
"@typescript-eslint/no-non-null-asserted-optional-chain": "error", | |
"@typescript-eslint/no-non-null-assertion": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-this-alias": "error", | |
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", | |
"@typescript-eslint/no-unnecessary-condition": "error", | |
"@typescript-eslint/no-unnecessary-type-arguments": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unnecessary-type-constraint": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-declaration-merging": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"no-unused-vars": "off", | |
"@typescript-eslint/no-unused-vars": "error", | |
"no-useless-constructor": "off", | |
"@typescript-eslint/no-useless-constructor": "error", | |
"@typescript-eslint/no-useless-template-literals": "error", | |
"@typescript-eslint/no-var-requires": "error", | |
"no-throw-literal": "off", | |
"@typescript-eslint/only-throw-error": "error", | |
"@typescript-eslint/prefer-as-const": "error", | |
"@typescript-eslint/prefer-includes": "error", | |
"@typescript-eslint/prefer-literal-enum-member": "error", | |
"prefer-promise-reject-errors": "off", | |
"@typescript-eslint/prefer-promise-reject-errors": "error", | |
"@typescript-eslint/prefer-reduce-type-parameter": "error", | |
"@typescript-eslint/prefer-return-this-type": "error", | |
"@typescript-eslint/prefer-ts-expect-error": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": [ | |
"error", | |
{ | |
allowAny: false, | |
allowBoolean: false, | |
allowNullish: false, | |
allowNumberAndString: false, | |
allowRegExp: false, | |
}, | |
], | |
"@typescript-eslint/restrict-template-expressions": [ | |
"error", | |
{ | |
allowAny: false, | |
allowBoolean: false, | |
allowNullish: false, | |
allowNumber: false, | |
allowRegExp: false, | |
allowNever: false, | |
}, | |
], | |
"@typescript-eslint/triple-slash-reference": "error", | |
"@typescript-eslint/unbound-method": "error", | |
"@typescript-eslint/unified-signatures": "error", | |
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error", | |
}, | |
}, | |
"strict-type-checked-only": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/await-thenable": "error", | |
"@typescript-eslint/no-array-delete": "error", | |
"@typescript-eslint/no-base-to-string": "error", | |
"@typescript-eslint/no-confusing-void-expression": "error", | |
"@typescript-eslint/no-duplicate-type-constituents": "error", | |
"@typescript-eslint/no-floating-promises": "error", | |
"@typescript-eslint/no-for-in-array": "error", | |
"no-implied-eval": "off", | |
"@typescript-eslint/no-implied-eval": "error", | |
"@typescript-eslint/no-meaningless-void-operator": "error", | |
"@typescript-eslint/no-misused-promises": "error", | |
"@typescript-eslint/no-mixed-enums": "error", | |
"@typescript-eslint/no-redundant-type-constituents": "error", | |
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", | |
"@typescript-eslint/no-unnecessary-condition": "error", | |
"@typescript-eslint/no-unnecessary-type-arguments": "error", | |
"@typescript-eslint/no-unnecessary-type-assertion": "error", | |
"@typescript-eslint/no-unsafe-argument": "error", | |
"@typescript-eslint/no-unsafe-assignment": "error", | |
"@typescript-eslint/no-unsafe-call": "error", | |
"@typescript-eslint/no-unsafe-enum-comparison": "error", | |
"@typescript-eslint/no-unsafe-member-access": "error", | |
"@typescript-eslint/no-unsafe-return": "error", | |
"@typescript-eslint/no-useless-template-literals": "error", | |
"no-throw-literal": "off", | |
"@typescript-eslint/only-throw-error": "error", | |
"@typescript-eslint/prefer-includes": "error", | |
"prefer-promise-reject-errors": "off", | |
"@typescript-eslint/prefer-promise-reject-errors": "error", | |
"@typescript-eslint/prefer-reduce-type-parameter": "error", | |
"@typescript-eslint/prefer-return-this-type": "error", | |
"require-await": "off", | |
"@typescript-eslint/require-await": "error", | |
"@typescript-eslint/restrict-plus-operands": [ | |
"error", | |
{ | |
allowAny: false, | |
allowBoolean: false, | |
allowNullish: false, | |
allowNumberAndString: false, | |
allowRegExp: false, | |
}, | |
], | |
"@typescript-eslint/restrict-template-expressions": [ | |
"error", | |
{ | |
allowAny: false, | |
allowBoolean: false, | |
allowNullish: false, | |
allowNumber: false, | |
allowRegExp: false, | |
allowNever: false, | |
}, | |
], | |
"@typescript-eslint/unbound-method": "error", | |
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error", | |
}, | |
}, | |
stylistic: { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/adjacent-overload-signatures": "error", | |
"@typescript-eslint/array-type": "error", | |
"@typescript-eslint/ban-tslint-comment": "error", | |
"@typescript-eslint/class-literal-property-style": "error", | |
"@typescript-eslint/consistent-generic-constructors": "error", | |
"@typescript-eslint/consistent-indexed-object-style": "error", | |
"@typescript-eslint/consistent-type-assertions": "error", | |
"@typescript-eslint/consistent-type-definitions": "error", | |
"@typescript-eslint/no-confusing-non-null-assertion": "error", | |
"no-empty-function": "off", | |
"@typescript-eslint/no-empty-function": "error", | |
"@typescript-eslint/no-empty-interface": "error", | |
"@typescript-eslint/no-inferrable-types": "error", | |
"@typescript-eslint/prefer-for-of": "error", | |
"@typescript-eslint/prefer-function-type": "error", | |
"@typescript-eslint/prefer-namespace-keyword": "error", | |
}, | |
}, | |
"stylistic-type-checked": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"@typescript-eslint/adjacent-overload-signatures": "error", | |
"@typescript-eslint/array-type": "error", | |
"@typescript-eslint/ban-tslint-comment": "error", | |
"@typescript-eslint/class-literal-property-style": "error", | |
"@typescript-eslint/consistent-generic-constructors": "error", | |
"@typescript-eslint/consistent-indexed-object-style": "error", | |
"@typescript-eslint/consistent-type-assertions": "error", | |
"@typescript-eslint/consistent-type-definitions": "error", | |
"dot-notation": "off", | |
"@typescript-eslint/dot-notation": "error", | |
"@typescript-eslint/no-confusing-non-null-assertion": "error", | |
"no-empty-function": "off", | |
"@typescript-eslint/no-empty-function": "error", | |
"@typescript-eslint/no-empty-interface": "error", | |
"@typescript-eslint/no-inferrable-types": "error", | |
"@typescript-eslint/non-nullable-type-assertion-style": "error", | |
"@typescript-eslint/prefer-for-of": "error", | |
"@typescript-eslint/prefer-function-type": "error", | |
"@typescript-eslint/prefer-namespace-keyword": "error", | |
"@typescript-eslint/prefer-nullish-coalescing": "error", | |
"@typescript-eslint/prefer-optional-chain": "error", | |
"@typescript-eslint/prefer-string-starts-ends-with": "error", | |
}, | |
}, | |
"stylistic-type-checked-only": { | |
extends: [ | |
"./configs/base", | |
"./configs/eslint-recommended", | |
], | |
rules: { | |
"dot-notation": "off", | |
"@typescript-eslint/dot-notation": "error", | |
"@typescript-eslint/non-nullable-type-assertion-style": "error", | |
"@typescript-eslint/prefer-nullish-coalescing": "error", | |
"@typescript-eslint/prefer-optional-chain": "error", | |
"@typescript-eslint/prefer-string-starts-ends-with": "error", | |
}, | |
}, | |
}, | |
environments: { | |
}, | |
processors: { | |
}, | |
rules: { | |
"adjacent-overload-signatures": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require that function overload signatures be consecutive", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/adjacent-overload-signatures", | |
}, | |
schema: [ | |
], | |
messages: { | |
adjacentSignature: "All {{name}} signatures should be adjacent.", | |
}, | |
}, | |
}, | |
"array-type": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
default: "array", | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require consistently using either `T[]` or `Array<T>` for arrays", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/array-type", | |
}, | |
fixable: "code", | |
messages: { | |
errorStringGeneric: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden. Use '{{className}}<{{type}}>' instead.", | |
errorStringArray: "Array type using '{{className}}<{{type}}>' is forbidden. Use '{{readonlyPrefix}}{{type}}[]' instead.", | |
errorStringArraySimple: "Array type using '{{className}}<{{type}}>' is forbidden for simple types. Use '{{readonlyPrefix}}{{type}}[]' instead.", | |
errorStringGenericSimple: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
arrayOption: { | |
type: "string", | |
enum: [ | |
"array", | |
"generic", | |
"array-simple", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
properties: { | |
default: { | |
$ref: "#/items/0/$defs/arrayOption", | |
description: "The array type expected for mutable cases.", | |
}, | |
readonly: { | |
$ref: "#/items/0/$defs/arrayOption", | |
description: "The array type expected for readonly cases. If omitted, the value for `default` will be used.", | |
}, | |
}, | |
type: "object", | |
}, | |
], | |
}, | |
}, | |
"await-thenable": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow awaiting a value that is not a Thenable", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/await-thenable", | |
}, | |
hasSuggestions: true, | |
messages: { | |
await: "Unexpected `await` of a non-Promise (non-\"Thenable\") value.", | |
removeAwait: "Remove unnecessary `await`.", | |
}, | |
schema: [ | |
], | |
type: "problem", | |
}, | |
}, | |
"ban-ts-comment": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
"ts-expect-error": "allow-with-description", | |
"ts-ignore": true, | |
"ts-nocheck": true, | |
"ts-check": false, | |
minimumDescriptionLength: 3, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow `@ts-<directive>` comments or require descriptions after directives", | |
recommended: { | |
recommended: true, | |
strict: [ | |
{ | |
minimumDescriptionLength: 10, | |
}, | |
], | |
}, | |
url: "https://typescript-eslint.io/rules/ban-ts-comment", | |
}, | |
messages: { | |
tsDirectiveComment: "Do not use \"@ts-{{directive}}\" because it alters compilation errors.", | |
tsIgnoreInsteadOfExpectError: "Use \"@ts-expect-error\" instead of \"@ts-ignore\", as \"@ts-ignore\" will do nothing if the following line is error-free.", | |
tsDirectiveCommentRequiresDescription: "Include a description after the \"@ts-{{directive}}\" directive to explain why the @ts-{{directive}} is necessary. The description must be {{minimumDescriptionLength}} characters or longer.", | |
tsDirectiveCommentDescriptionNotMatchPattern: "The description for the \"@ts-{{directive}}\" directive must match the {{format}} format.", | |
replaceTsIgnoreWithTsExpectError: "Replace \"@ts-ignore\" with \"@ts-expect-error\".", | |
}, | |
hasSuggestions: true, | |
schema: [ | |
{ | |
$defs: { | |
directiveConfigSchema: { | |
oneOf: [ | |
{ | |
type: "boolean", | |
default: true, | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"allow-with-description", | |
], | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
descriptionFormat: { | |
type: "string", | |
}, | |
}, | |
}, | |
], | |
}, | |
}, | |
properties: { | |
"ts-expect-error": { | |
$ref: "#/items/0/$defs/directiveConfigSchema", | |
}, | |
"ts-ignore": { | |
$ref: "#/items/0/$defs/directiveConfigSchema", | |
}, | |
"ts-nocheck": { | |
$ref: "#/items/0/$defs/directiveConfigSchema", | |
}, | |
"ts-check": { | |
$ref: "#/items/0/$defs/directiveConfigSchema", | |
}, | |
minimumDescriptionLength: { | |
type: "number", | |
default: 3, | |
}, | |
}, | |
type: "object", | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"ban-tslint-comment": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow `// tslint:<rule-flag>` comments", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/ban-tslint-comment", | |
}, | |
messages: { | |
commentDetected: "tslint comment detected: \"{{ text }}\"", | |
}, | |
schema: [ | |
], | |
fixable: "code", | |
}, | |
}, | |
"ban-types": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow certain types", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/ban-types", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
bannedTypeMessage: "Don't use `{{name}}` as a type.{{customMessage}}", | |
bannedTypeReplacement: "Replace `{{name}}` with `{{replacement}}`.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
banConfig: { | |
oneOf: [ | |
{ | |
type: "null", | |
description: "Bans the type with the default message", | |
}, | |
{ | |
type: "boolean", | |
enum: [ | |
false, | |
], | |
description: "Un-bans the type (useful when paired with `extendDefaults`)", | |
}, | |
{ | |
type: "boolean", | |
enum: [ | |
true, | |
], | |
description: "Bans the type with the default message", | |
}, | |
{ | |
type: "string", | |
description: "Bans the type with a custom message", | |
}, | |
{ | |
type: "object", | |
description: "Bans a type", | |
properties: { | |
message: { | |
type: "string", | |
description: "Custom error message", | |
}, | |
fixWith: { | |
type: "string", | |
description: "Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.", | |
}, | |
suggest: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
description: "Types to suggest replacing with.", | |
additionalItems: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
type: "object", | |
properties: { | |
types: { | |
type: "object", | |
additionalProperties: { | |
$ref: "#/items/0/$defs/banConfig", | |
}, | |
}, | |
extendDefaults: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"block-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"always", | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/block-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Disallow or enforce spaces inside of blocks after opening block and before closing block", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/block-spacing", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
enum: [ | |
"always", | |
"never", | |
], | |
}, | |
], | |
messages: { | |
missing: "Requires a space {{location}} '{{token}}'.", | |
extra: "Unexpected space(s) {{location}} '{{token}}'.", | |
}, | |
}, | |
}, | |
"brace-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"1tbs", | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/brace-style", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent brace style for blocks", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/brace-style", | |
}, | |
messages: { | |
nextLineOpen: "Opening curly brace does not appear on the same line as controlling statement.", | |
sameLineOpen: "Opening curly brace appears on the same line as controlling statement.", | |
blockSameLine: "Statement inside of curly braces should be on next line.", | |
nextLineClose: "Closing curly brace does not appear on the same line as the subsequent block.", | |
singleLineClose: "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.", | |
sameLineClose: "Closing curly brace appears on the same line as the subsequent block.", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
enum: [ | |
"1tbs", | |
"stroustrup", | |
"allman", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
allowSingleLine: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"class-literal-property-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"fields", | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Enforce that literals on classes are exposed in a consistent style", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/class-literal-property-style", | |
}, | |
hasSuggestions: true, | |
messages: { | |
preferFieldStyle: "Literals should be exposed using readonly fields.", | |
preferFieldStyleSuggestion: "Replace the literals with readonly fields.", | |
preferGetterStyle: "Literals should be exposed using getters.", | |
preferGetterStyleSuggestion: "Replace the literals with getters.", | |
}, | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"fields", | |
"getters", | |
], | |
}, | |
], | |
}, | |
}, | |
"class-methods-use-this": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
enforceForClassFields: true, | |
exceptMethods: [ | |
], | |
ignoreClassesThatImplementAnInterface: false, | |
ignoreOverrideMethods: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce that class methods utilize `this`", | |
extendsBaseRule: true, | |
requiresTypeChecking: false, | |
url: "https://typescript-eslint.io/rules/class-methods-use-this", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
exceptMethods: { | |
type: "array", | |
description: "Allows specified method names to be ignored with this rule", | |
items: { | |
type: "string", | |
}, | |
}, | |
enforceForClassFields: { | |
type: "boolean", | |
description: "Enforces that functions used as instance field initializers utilize `this`", | |
default: true, | |
}, | |
ignoreOverrideMethods: { | |
type: "boolean", | |
description: "Ignore members marked with the `override` modifier", | |
}, | |
ignoreClassesThatImplementAnInterface: { | |
oneOf: [ | |
{ | |
type: "boolean", | |
description: "Ignore all classes that implement an interface", | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"public-fields", | |
], | |
description: "Ignore only the public fields of classes that implement an interface", | |
}, | |
], | |
description: "Ignore classes that specifically implement some interface", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
missingThis: "Expected 'this' to be used by class {{name}}.", | |
}, | |
}, | |
}, | |
"comma-dangle": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"never", | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/comma-dangle", | |
], | |
type: "layout", | |
docs: { | |
description: "Require or disallow trailing commas", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/comma-dangle", | |
}, | |
schema: { | |
$defs: { | |
value: { | |
type: "string", | |
enum: [ | |
"always-multiline", | |
"always", | |
"never", | |
"only-multiline", | |
], | |
}, | |
valueWithIgnore: { | |
type: "string", | |
enum: [ | |
"always-multiline", | |
"always", | |
"never", | |
"only-multiline", | |
"ignore", | |
], | |
}, | |
}, | |
type: "array", | |
items: [ | |
{ | |
oneOf: [ | |
{ | |
$ref: "#/$defs/value", | |
}, | |
{ | |
type: "object", | |
properties: { | |
arrays: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
objects: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
imports: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
exports: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
functions: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
enums: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
generics: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
tuples: { | |
$ref: "#/$defs/valueWithIgnore", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
additionalItems: false, | |
}, | |
fixable: "code", | |
hasSuggestions: undefined, | |
messages: { | |
unexpected: "Unexpected trailing comma.", | |
missing: "Missing trailing comma.", | |
}, | |
}, | |
}, | |
"comma-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
before: false, | |
after: true, | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/comma-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent spacing before and after commas", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/comma-spacing", | |
}, | |
fixable: "whitespace", | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
default: false, | |
}, | |
after: { | |
type: "boolean", | |
default: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
unexpected: "There should be no space {{loc}} ','.", | |
missing: "A space is required {{loc}} ','.", | |
}, | |
}, | |
}, | |
"consistent-generic-constructors": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"constructor", | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce specifying generic type arguments on type annotation or constructor name of a constructor call", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/consistent-generic-constructors", | |
}, | |
messages: { | |
preferTypeAnnotation: "The generic type arguments should be specified as part of the type annotation.", | |
preferConstructor: "The generic type arguments should be specified as part of the constructor type arguments.", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"type-annotation", | |
"constructor", | |
], | |
}, | |
], | |
}, | |
}, | |
"consistent-indexed-object-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"record", | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require or disallow the `Record` type", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/consistent-indexed-object-style", | |
}, | |
messages: { | |
preferRecord: "A record is preferred over an index signature.", | |
preferIndexSignature: "An index signature is preferred over a record.", | |
}, | |
fixable: "code", | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"record", | |
"index-signature", | |
], | |
}, | |
], | |
}, | |
}, | |
"consistent-return": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
treatUndefinedAsUnspecified: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require `return` statements to either always or never specify values", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/consistent-return", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
treatUndefinedAsUnspecified: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
missingReturn: "Expected to return a value at the end of {{name}}.", | |
missingReturnValue: "{{name}} expected a return value.", | |
unexpectedReturnValue: "{{name}} expected no return value.", | |
}, | |
}, | |
}, | |
"consistent-type-assertions": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
assertionStyle: "as", | |
objectLiteralTypeAssertions: "allow", | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
fixable: "code", | |
hasSuggestions: true, | |
docs: { | |
description: "Enforce consistent usage of type assertions", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/consistent-type-assertions", | |
}, | |
messages: { | |
as: "Use 'as {{cast}}' instead of '<{{cast}}>'.", | |
"angle-bracket": "Use '<{{cast}}>' instead of 'as {{cast}}'.", | |
never: "Do not use any type assertions.", | |
unexpectedObjectTypeAssertion: "Always prefer const x: T = { ... }.", | |
replaceObjectTypeAssertionWithAnnotation: "Use const x: {{cast}} = { ... } instead.", | |
replaceObjectTypeAssertionWithSatisfies: "Use const x = { ... } satisfies {{cast}} instead.", | |
}, | |
schema: [ | |
{ | |
oneOf: [ | |
{ | |
type: "object", | |
properties: { | |
assertionStyle: { | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"assertionStyle", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
assertionStyle: { | |
type: "string", | |
enum: [ | |
"as", | |
"angle-bracket", | |
], | |
}, | |
objectLiteralTypeAssertions: { | |
type: "string", | |
enum: [ | |
"allow", | |
"allow-as-parameter", | |
"never", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"assertionStyle", | |
], | |
}, | |
], | |
}, | |
], | |
}, | |
}, | |
"consistent-type-definitions": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"interface", | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce type definitions to consistently use either `interface` or `type`", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/consistent-type-definitions", | |
}, | |
messages: { | |
interfaceOverType: "Use an `interface` instead of a `type`.", | |
typeOverInterface: "Use a `type` instead of an `interface`.", | |
}, | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"interface", | |
"type", | |
], | |
}, | |
], | |
fixable: "code", | |
}, | |
}, | |
"consistent-type-exports": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
fixMixedExportsWithInlineTypeSpecifier: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce consistent usage of type exports", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/consistent-type-exports", | |
}, | |
messages: { | |
typeOverValue: "All exports in the declaration are only used as types. Use `export type`.", | |
singleExportIsType: "Type export {{exportNames}} is not a value and should be exported using `export type`.", | |
multipleExportsAreTypes: "Type exports {{exportNames}} are not values and should be exported using `export type`.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
fixMixedExportsWithInlineTypeSpecifier: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
fixable: "code", | |
}, | |
}, | |
"consistent-type-imports": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
prefer: "type-imports", | |
disallowTypeAnnotations: true, | |
fixStyle: "separate-type-imports", | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce consistent usage of type imports", | |
url: "https://typescript-eslint.io/rules/consistent-type-imports", | |
}, | |
messages: { | |
typeOverValue: "All imports in the declaration are only used as types. Use `import type`.", | |
someImportsAreOnlyTypes: "Imports {{typeImports}} are only used as type.", | |
avoidImportType: "Use an `import` instead of an `import type`.", | |
noImportTypeAnnotations: "`import()` type annotations are forbidden.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
disallowTypeAnnotations: { | |
type: "boolean", | |
}, | |
fixStyle: { | |
type: "string", | |
enum: [ | |
"separate-type-imports", | |
"inline-type-imports", | |
], | |
}, | |
prefer: { | |
type: "string", | |
enum: [ | |
"type-imports", | |
"no-type-imports", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
fixable: "code", | |
}, | |
}, | |
"default-param-last": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce default parameters to be last", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/default-param-last", | |
}, | |
schema: [ | |
], | |
messages: { | |
shouldBeLast: "Default parameters should be last.", | |
}, | |
}, | |
}, | |
"dot-notation": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowPrivateClassPropertyAccess: false, | |
allowProtectedClassPropertyAccess: false, | |
allowIndexSignaturePropertyAccess: false, | |
allowKeywords: true, | |
allowPattern: "", | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce dot notation whenever possible", | |
recommended: "stylistic", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/dot-notation", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowKeywords: { | |
type: "boolean", | |
default: true, | |
}, | |
allowPattern: { | |
type: "string", | |
default: "", | |
}, | |
allowPrivateClassPropertyAccess: { | |
type: "boolean", | |
default: false, | |
}, | |
allowProtectedClassPropertyAccess: { | |
type: "boolean", | |
default: false, | |
}, | |
allowIndexSignaturePropertyAccess: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
fixable: "code", | |
hasSuggestions: undefined, | |
messages: { | |
useDot: "[{{key}}] is better written in dot notation.", | |
useBrackets: ".{{key}} is a syntax error.", | |
}, | |
}, | |
}, | |
"explicit-function-return-type": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowExpressions: false, | |
allowTypedFunctionExpressions: true, | |
allowHigherOrderFunctions: true, | |
allowDirectConstAssertionInArrowFunctions: true, | |
allowConciseArrowFunctionExpressionsStartingWithVoid: false, | |
allowFunctionsWithoutTypeParameters: false, | |
allowedNames: [ | |
], | |
allowIIFEs: false, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Require explicit return types on functions and class methods", | |
url: "https://typescript-eslint.io/rules/explicit-function-return-type", | |
}, | |
messages: { | |
missingReturnType: "Missing return type on function.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowConciseArrowFunctionExpressionsStartingWithVoid: { | |
description: "Whether to allow arrow functions that start with the `void` keyword.", | |
type: "boolean", | |
}, | |
allowExpressions: { | |
description: "Whether to ignore function expressions (functions which are not part of a declaration).", | |
type: "boolean", | |
}, | |
allowHigherOrderFunctions: { | |
description: "Whether to ignore functions immediately returning another function expression.", | |
type: "boolean", | |
}, | |
allowTypedFunctionExpressions: { | |
description: "Whether to ignore type annotations on the variable of function expressions.", | |
type: "boolean", | |
}, | |
allowDirectConstAssertionInArrowFunctions: { | |
description: "Whether to ignore arrow functions immediately returning a `as const` value.", | |
type: "boolean", | |
}, | |
allowFunctionsWithoutTypeParameters: { | |
description: "Whether to ignore functions that don't have generic type parameters.", | |
type: "boolean", | |
}, | |
allowedNames: { | |
description: "An array of function/method names that will not have their arguments or return values checked.", | |
items: { | |
type: "string", | |
}, | |
type: "array", | |
}, | |
allowIIFEs: { | |
description: "Whether to ignore immediately invoked function expressions (IIFEs).", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"explicit-member-accessibility": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
accessibility: "explicit", | |
}, | |
], | |
meta: { | |
hasSuggestions: true, | |
type: "problem", | |
docs: { | |
description: "Require explicit accessibility modifiers on class properties and methods", | |
url: "https://typescript-eslint.io/rules/explicit-member-accessibility", | |
}, | |
fixable: "code", | |
messages: { | |
missingAccessibility: "Missing accessibility modifier on {{type}} {{name}}.", | |
unwantedPublicAccessibility: "Public accessibility modifier on {{type}} {{name}}.", | |
addExplicitAccessibility: "Add '{{ type }}' accessibility modifier", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
accessibilityLevel: { | |
oneOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"explicit", | |
], | |
description: "Always require an accessor.", | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"no-public", | |
], | |
description: "Require an accessor except when public.", | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"off", | |
], | |
description: "Never check whether there is an accessor.", | |
}, | |
], | |
}, | |
}, | |
type: "object", | |
properties: { | |
accessibility: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
overrides: { | |
type: "object", | |
properties: { | |
accessors: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
constructors: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
methods: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
properties: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
parameterProperties: { | |
$ref: "#/items/0/$defs/accessibilityLevel", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
ignoredMethodNames: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"explicit-module-boundary-types": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowArgumentsExplicitlyTypedAsAny: false, | |
allowDirectConstAssertionInArrowFunctions: true, | |
allowedNames: [ | |
], | |
allowHigherOrderFunctions: true, | |
allowTypedFunctionExpressions: true, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Require explicit return and argument types on exported functions' and classes' public class methods", | |
url: "https://typescript-eslint.io/rules/explicit-module-boundary-types", | |
}, | |
messages: { | |
missingReturnType: "Missing return type on function.", | |
missingArgType: "Argument '{{name}}' should be typed.", | |
missingArgTypeUnnamed: "{{type}} argument should be typed.", | |
anyTypedArg: "Argument '{{name}}' should be typed with a non-any type.", | |
anyTypedArgUnnamed: "{{type}} argument should be typed with a non-any type.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowArgumentsExplicitlyTypedAsAny: { | |
description: "Whether to ignore arguments that are explicitly typed as `any`.", | |
type: "boolean", | |
}, | |
allowDirectConstAssertionInArrowFunctions: { | |
description: "Whether to ignore return type annotations on body-less arrow functions that return an `as const` type assertion.\nYou must still type the parameters of the function.", | |
type: "boolean", | |
}, | |
allowedNames: { | |
description: "An array of function/method names that will not have their arguments or return values checked.", | |
items: { | |
type: "string", | |
}, | |
type: "array", | |
}, | |
allowHigherOrderFunctions: { | |
description: "Whether to ignore return type annotations on functions immediately returning another function expression.\nYou must still type the parameters of the function.", | |
type: "boolean", | |
}, | |
allowTypedFunctionExpressions: { | |
description: "Whether to ignore type annotations on the variable of a function expression.", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"func-call-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"never", | |
{ | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/func-call-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Require or disallow spacing between function identifiers and their invocations", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/func-call-spacing", | |
}, | |
fixable: "whitespace", | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
], | |
minItems: 0, | |
maxItems: 1, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "string", | |
enum: [ | |
"always", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
allowNewlines: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
minItems: 0, | |
maxItems: 2, | |
}, | |
], | |
}, | |
messages: { | |
unexpectedWhitespace: "Unexpected whitespace between function name and paren.", | |
unexpectedNewline: "Unexpected newline between function name and paren.", | |
missing: "Missing space between function name and paren.", | |
}, | |
}, | |
}, | |
indent: { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
4, | |
{ | |
SwitchCase: 1, | |
flatTernaryExpressions: false, | |
ignoredNodes: [ | |
], | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/indent", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent indentation", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/indent", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
oneOf: [ | |
{ | |
enum: [ | |
"tab", | |
], | |
}, | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
SwitchCase: { | |
type: "integer", | |
minimum: 0, | |
default: 0, | |
}, | |
VariableDeclarator: { | |
oneOf: [ | |
{ | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
var: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
let: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
const: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
outerIIFEBody: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"off", | |
], | |
}, | |
], | |
}, | |
MemberExpression: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"off", | |
], | |
}, | |
], | |
}, | |
FunctionDeclaration: { | |
type: "object", | |
properties: { | |
parameters: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
body: { | |
type: "integer", | |
minimum: 0, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
FunctionExpression: { | |
type: "object", | |
properties: { | |
parameters: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
body: { | |
type: "integer", | |
minimum: 0, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
StaticBlock: { | |
type: "object", | |
properties: { | |
body: { | |
type: "integer", | |
minimum: 0, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
CallExpression: { | |
type: "object", | |
properties: { | |
arguments: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
ArrayExpression: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
ObjectExpression: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
ImportDeclaration: { | |
oneOf: [ | |
{ | |
type: "integer", | |
minimum: 0, | |
}, | |
{ | |
enum: [ | |
"first", | |
"off", | |
], | |
}, | |
], | |
}, | |
flatTernaryExpressions: { | |
type: "boolean", | |
default: false, | |
}, | |
offsetTernaryExpressions: { | |
type: "boolean", | |
default: false, | |
}, | |
ignoredNodes: { | |
type: "array", | |
items: { | |
type: "string", | |
not: { | |
pattern: ":exit$", | |
}, | |
}, | |
}, | |
ignoreComments: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
wrongIndentation: "Expected indentation of {{expected}} but found {{actual}}.", | |
}, | |
}, | |
}, | |
"init-declarations": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"always", | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require or disallow initialization in variable declarations", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/init-declarations", | |
}, | |
hasSuggestions: undefined, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"always", | |
], | |
}, | |
], | |
minItems: 0, | |
maxItems: 1, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
ignoreForLoopInit: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
minItems: 0, | |
maxItems: 2, | |
}, | |
], | |
}, | |
messages: { | |
initialized: "Variable '{{idName}}' should be initialized on declaration.", | |
notInitialized: "Variable '{{idName}}' should not be initialized on declaration.", | |
}, | |
}, | |
}, | |
"key-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/key-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent spacing between property names and type annotations in types and interfaces", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/key-spacing", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
anyOf: [ | |
{ | |
type: "object", | |
properties: { | |
align: { | |
anyOf: [ | |
{ | |
enum: [ | |
"colon", | |
"value", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
on: { | |
enum: [ | |
"colon", | |
"value", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
properties: { | |
singleLine: { | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
multiLine: { | |
type: "object", | |
properties: { | |
align: { | |
anyOf: [ | |
{ | |
enum: [ | |
"colon", | |
"value", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
on: { | |
enum: [ | |
"colon", | |
"value", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
properties: { | |
singleLine: { | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
multiLine: { | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
align: { | |
type: "object", | |
properties: { | |
mode: { | |
enum: [ | |
"strict", | |
"minimum", | |
], | |
}, | |
on: { | |
enum: [ | |
"colon", | |
"value", | |
], | |
}, | |
beforeColon: { | |
type: "boolean", | |
}, | |
afterColon: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
messages: { | |
extraKey: "Extra space after {{computed}}key '{{key}}'.", | |
extraValue: "Extra space before value for {{computed}}key '{{key}}'.", | |
missingKey: "Missing space after {{computed}}key '{{key}}'.", | |
missingValue: "Missing space before value for {{computed}}key '{{key}}'.", | |
}, | |
}, | |
}, | |
"keyword-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/keyword-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent spacing before and after keywords", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/keyword-spacing", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
default: true, | |
}, | |
after: { | |
type: "boolean", | |
default: true, | |
}, | |
overrides: { | |
type: "object", | |
properties: { | |
abstract: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
as: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
async: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
await: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
boolean: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
break: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
byte: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
case: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
catch: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
char: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
class: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
const: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
continue: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
debugger: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
default: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
delete: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
do: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
double: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
else: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
enum: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
export: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
extends: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
false: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
final: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
finally: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
float: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
for: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
from: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
function: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
get: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
goto: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
if: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
implements: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
import: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
in: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
instanceof: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
int: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
interface: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
let: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
long: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
native: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
new: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
null: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
of: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
package: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
private: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
protected: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
public: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
return: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
set: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
short: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
static: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
super: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
switch: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
synchronized: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
this: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
throw: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
throws: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
transient: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
true: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
try: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
typeof: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
var: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
void: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
volatile: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
while: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
with: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
yield: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
type: { | |
type: "object", | |
properties: { | |
before: { | |
type: "boolean", | |
}, | |
after: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
expectedBefore: "Expected space(s) before \"{{value}}\".", | |
expectedAfter: "Expected space(s) after \"{{value}}\".", | |
unexpectedBefore: "Unexpected space(s) before \"{{value}}\".", | |
unexpectedAfter: "Unexpected space(s) after \"{{value}}\".", | |
}, | |
}, | |
}, | |
"lines-around-comment": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
beforeBlockComment: true, | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/lines-around-comment", | |
], | |
type: "layout", | |
docs: { | |
description: "Require empty lines around comments", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/lines-around-comment", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
beforeBlockComment: { | |
type: "boolean", | |
default: true, | |
}, | |
afterBlockComment: { | |
type: "boolean", | |
default: false, | |
}, | |
beforeLineComment: { | |
type: "boolean", | |
default: false, | |
}, | |
afterLineComment: { | |
type: "boolean", | |
default: false, | |
}, | |
allowBlockStart: { | |
type: "boolean", | |
default: false, | |
}, | |
allowBlockEnd: { | |
type: "boolean", | |
default: false, | |
}, | |
allowClassStart: { | |
type: "boolean", | |
}, | |
allowClassEnd: { | |
type: "boolean", | |
}, | |
allowObjectStart: { | |
type: "boolean", | |
}, | |
allowObjectEnd: { | |
type: "boolean", | |
}, | |
allowArrayStart: { | |
type: "boolean", | |
}, | |
allowArrayEnd: { | |
type: "boolean", | |
}, | |
allowInterfaceStart: { | |
type: "boolean", | |
}, | |
allowInterfaceEnd: { | |
type: "boolean", | |
}, | |
allowTypeStart: { | |
type: "boolean", | |
}, | |
allowTypeEnd: { | |
type: "boolean", | |
}, | |
allowEnumStart: { | |
type: "boolean", | |
}, | |
allowEnumEnd: { | |
type: "boolean", | |
}, | |
allowModuleStart: { | |
type: "boolean", | |
}, | |
allowModuleEnd: { | |
type: "boolean", | |
}, | |
ignorePattern: { | |
type: "string", | |
}, | |
applyDefaultIgnorePatterns: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
messages: { | |
after: "Expected line after comment.", | |
before: "Expected line before comment.", | |
}, | |
}, | |
}, | |
"lines-between-class-members": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"always", | |
{ | |
exceptAfterOverload: true, | |
exceptAfterSingleLine: false, | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/lines-between-class-members", | |
], | |
type: "layout", | |
docs: { | |
description: "Require or disallow an empty line between class members", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/lines-between-class-members", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
anyOf: [ | |
{ | |
type: "object", | |
properties: { | |
enforce: { | |
type: "array", | |
items: { | |
type: "object", | |
properties: { | |
blankLine: { | |
enum: [ | |
"always", | |
"never", | |
], | |
}, | |
prev: { | |
enum: [ | |
"method", | |
"field", | |
"*", | |
], | |
}, | |
next: { | |
enum: [ | |
"method", | |
"field", | |
"*", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"blankLine", | |
"prev", | |
"next", | |
], | |
}, | |
minItems: 1, | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"enforce", | |
], | |
}, | |
{ | |
enum: [ | |
"always", | |
"never", | |
], | |
}, | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
exceptAfterSingleLine: { | |
type: "boolean", | |
default: false, | |
}, | |
exceptAfterOverload: { | |
type: "boolean", | |
default: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
never: "Unexpected blank line between class members.", | |
always: "Expected blank line between class members.", | |
}, | |
}, | |
}, | |
"max-params": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
max: 3, | |
countVoidThis: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce a maximum number of parameters in function definitions", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/max-params", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
maximum: { | |
type: "integer", | |
minimum: 0, | |
}, | |
max: { | |
type: "integer", | |
minimum: 0, | |
}, | |
countVoidThis: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}.", | |
}, | |
}, | |
}, | |
"member-delimiter-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
multiline: { | |
delimiter: "semi", | |
requireLast: true, | |
}, | |
singleline: { | |
delimiter: "semi", | |
requireLast: false, | |
}, | |
multilineDetection: "brackets", | |
}, | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/member-delimiter-style", | |
], | |
type: "layout", | |
docs: { | |
description: "Require a specific member delimiter style for interfaces and type literals", | |
url: "https://typescript-eslint.io/rules/member-delimiter-style", | |
}, | |
fixable: "whitespace", | |
messages: { | |
unexpectedComma: "Unexpected separator (,).", | |
unexpectedSemi: "Unexpected separator (;).", | |
expectedComma: "Expected a comma.", | |
expectedSemi: "Expected a semicolon.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
multiLineOption: { | |
type: "string", | |
enum: [ | |
"none", | |
"semi", | |
"comma", | |
], | |
}, | |
singleLineOption: { | |
type: "string", | |
enum: [ | |
"semi", | |
"comma", | |
], | |
}, | |
delimiterConfig: { | |
type: "object", | |
properties: { | |
multiline: { | |
type: "object", | |
properties: { | |
delimiter: { | |
$ref: "#/items/0/$defs/multiLineOption", | |
}, | |
requireLast: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
singleline: { | |
type: "object", | |
properties: { | |
delimiter: { | |
$ref: "#/items/0/$defs/singleLineOption", | |
}, | |
requireLast: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
type: "object", | |
properties: { | |
multiline: { | |
type: "object", | |
properties: { | |
delimiter: { | |
$ref: "#/items/0/$defs/multiLineOption", | |
}, | |
requireLast: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
singleline: { | |
type: "object", | |
properties: { | |
delimiter: { | |
$ref: "#/items/0/$defs/singleLineOption", | |
}, | |
requireLast: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
overrides: { | |
type: "object", | |
properties: { | |
interface: { | |
$ref: "#/items/0/$defs/delimiterConfig", | |
}, | |
typeLiteral: { | |
$ref: "#/items/0/$defs/delimiterConfig", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
multilineDetection: { | |
type: "string", | |
enum: [ | |
"brackets", | |
"last-member", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"member-ordering": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
default: { | |
memberTypes: [ | |
"signature", | |
"call-signature", | |
"public-static-field", | |
"protected-static-field", | |
"private-static-field", | |
"#private-static-field", | |
"public-decorated-field", | |
"protected-decorated-field", | |
"private-decorated-field", | |
"public-instance-field", | |
"protected-instance-field", | |
"private-instance-field", | |
"#private-instance-field", | |
"public-abstract-field", | |
"protected-abstract-field", | |
"public-field", | |
"protected-field", | |
"private-field", | |
"#private-field", | |
"static-field", | |
"instance-field", | |
"abstract-field", | |
"decorated-field", | |
"field", | |
"static-initialization", | |
"public-constructor", | |
"protected-constructor", | |
"private-constructor", | |
"constructor", | |
"public-static-accessor", | |
"protected-static-accessor", | |
"private-static-accessor", | |
"#private-static-accessor", | |
"public-decorated-accessor", | |
"protected-decorated-accessor", | |
"private-decorated-accessor", | |
"public-instance-accessor", | |
"protected-instance-accessor", | |
"private-instance-accessor", | |
"#private-instance-accessor", | |
"public-abstract-accessor", | |
"protected-abstract-accessor", | |
"public-accessor", | |
"protected-accessor", | |
"private-accessor", | |
"#private-accessor", | |
"static-accessor", | |
"instance-accessor", | |
"abstract-accessor", | |
"decorated-accessor", | |
"accessor", | |
"public-static-get", | |
"protected-static-get", | |
"private-static-get", | |
"#private-static-get", | |
"public-decorated-get", | |
"protected-decorated-get", | |
"private-decorated-get", | |
"public-instance-get", | |
"protected-instance-get", | |
"private-instance-get", | |
"#private-instance-get", | |
"public-abstract-get", | |
"protected-abstract-get", | |
"public-get", | |
"protected-get", | |
"private-get", | |
"#private-get", | |
"static-get", | |
"instance-get", | |
"abstract-get", | |
"decorated-get", | |
"get", | |
"public-static-set", | |
"protected-static-set", | |
"private-static-set", | |
"#private-static-set", | |
"public-decorated-set", | |
"protected-decorated-set", | |
"private-decorated-set", | |
"public-instance-set", | |
"protected-instance-set", | |
"private-instance-set", | |
"#private-instance-set", | |
"public-abstract-set", | |
"protected-abstract-set", | |
"public-set", | |
"protected-set", | |
"private-set", | |
"#private-set", | |
"static-set", | |
"instance-set", | |
"abstract-set", | |
"decorated-set", | |
"set", | |
"public-static-method", | |
"protected-static-method", | |
"private-static-method", | |
"#private-static-method", | |
"public-decorated-method", | |
"protected-decorated-method", | |
"private-decorated-method", | |
"public-instance-method", | |
"protected-instance-method", | |
"private-instance-method", | |
"#private-instance-method", | |
"public-abstract-method", | |
"protected-abstract-method", | |
"public-method", | |
"protected-method", | |
"private-method", | |
"#private-method", | |
"static-method", | |
"instance-method", | |
"abstract-method", | |
"decorated-method", | |
"method", | |
], | |
}, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require a consistent member declaration order", | |
url: "https://typescript-eslint.io/rules/member-ordering", | |
}, | |
messages: { | |
incorrectOrder: "Member {{member}} should be declared before member {{beforeMember}}.", | |
incorrectGroupOrder: "Member {{name}} should be declared before all {{rank}} definitions.", | |
incorrectRequiredMembersOrder: "Member {{member}} should be declared after all {{optionalOrRequired}} members.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
orderOptions: { | |
type: "string", | |
enum: [ | |
"alphabetically", | |
"alphabetically-case-insensitive", | |
"as-written", | |
"natural", | |
"natural-case-insensitive", | |
], | |
}, | |
optionalityOrderOptions: { | |
type: "string", | |
enum: [ | |
"optional-first", | |
"required-first", | |
], | |
}, | |
allItems: { | |
type: "string", | |
enum: [ | |
"readonly-signature", | |
"signature", | |
"readonly-field", | |
"public-readonly-field", | |
"public-decorated-readonly-field", | |
"decorated-readonly-field", | |
"static-readonly-field", | |
"public-static-readonly-field", | |
"instance-readonly-field", | |
"public-instance-readonly-field", | |
"abstract-readonly-field", | |
"public-abstract-readonly-field", | |
"protected-readonly-field", | |
"protected-decorated-readonly-field", | |
"protected-static-readonly-field", | |
"protected-instance-readonly-field", | |
"protected-abstract-readonly-field", | |
"private-readonly-field", | |
"private-decorated-readonly-field", | |
"private-static-readonly-field", | |
"private-instance-readonly-field", | |
"#private-readonly-field", | |
"#private-static-readonly-field", | |
"#private-instance-readonly-field", | |
"field", | |
"public-field", | |
"public-decorated-field", | |
"decorated-field", | |
"static-field", | |
"public-static-field", | |
"instance-field", | |
"public-instance-field", | |
"abstract-field", | |
"public-abstract-field", | |
"protected-field", | |
"protected-decorated-field", | |
"protected-static-field", | |
"protected-instance-field", | |
"protected-abstract-field", | |
"private-field", | |
"private-decorated-field", | |
"private-static-field", | |
"private-instance-field", | |
"#private-field", | |
"#private-static-field", | |
"#private-instance-field", | |
"method", | |
"public-method", | |
"public-decorated-method", | |
"decorated-method", | |
"static-method", | |
"public-static-method", | |
"instance-method", | |
"public-instance-method", | |
"abstract-method", | |
"public-abstract-method", | |
"protected-method", | |
"protected-decorated-method", | |
"protected-static-method", | |
"protected-instance-method", | |
"protected-abstract-method", | |
"private-method", | |
"private-decorated-method", | |
"private-static-method", | |
"private-instance-method", | |
"#private-method", | |
"#private-static-method", | |
"#private-instance-method", | |
"call-signature", | |
"constructor", | |
"public-constructor", | |
"protected-constructor", | |
"private-constructor", | |
"accessor", | |
"public-accessor", | |
"public-decorated-accessor", | |
"decorated-accessor", | |
"static-accessor", | |
"public-static-accessor", | |
"instance-accessor", | |
"public-instance-accessor", | |
"abstract-accessor", | |
"public-abstract-accessor", | |
"protected-accessor", | |
"protected-decorated-accessor", | |
"protected-static-accessor", | |
"protected-instance-accessor", | |
"protected-abstract-accessor", | |
"private-accessor", | |
"private-decorated-accessor", | |
"private-static-accessor", | |
"private-instance-accessor", | |
"#private-accessor", | |
"#private-static-accessor", | |
"#private-instance-accessor", | |
"get", | |
"public-get", | |
"public-decorated-get", | |
"decorated-get", | |
"static-get", | |
"public-static-get", | |
"instance-get", | |
"public-instance-get", | |
"abstract-get", | |
"public-abstract-get", | |
"protected-get", | |
"protected-decorated-get", | |
"protected-static-get", | |
"protected-instance-get", | |
"protected-abstract-get", | |
"private-get", | |
"private-decorated-get", | |
"private-static-get", | |
"private-instance-get", | |
"#private-get", | |
"#private-static-get", | |
"#private-instance-get", | |
"set", | |
"public-set", | |
"public-decorated-set", | |
"decorated-set", | |
"static-set", | |
"public-static-set", | |
"instance-set", | |
"public-instance-set", | |
"abstract-set", | |
"public-abstract-set", | |
"protected-set", | |
"protected-decorated-set", | |
"protected-static-set", | |
"protected-instance-set", | |
"protected-abstract-set", | |
"private-set", | |
"private-decorated-set", | |
"private-static-set", | |
"private-instance-set", | |
"#private-set", | |
"#private-static-set", | |
"#private-instance-set", | |
"static-initialization", | |
"static-static-initialization", | |
"public-static-static-initialization", | |
"instance-static-initialization", | |
"public-instance-static-initialization", | |
"abstract-static-initialization", | |
"public-abstract-static-initialization", | |
"protected-static-static-initialization", | |
"protected-instance-static-initialization", | |
"protected-abstract-static-initialization", | |
"private-static-static-initialization", | |
"private-instance-static-initialization", | |
"#private-static-static-initialization", | |
"#private-instance-static-initialization", | |
], | |
}, | |
typeItems: { | |
type: "string", | |
enum: [ | |
"readonly-signature", | |
"signature", | |
"readonly-field", | |
"field", | |
"method", | |
"constructor", | |
], | |
}, | |
baseConfig: { | |
oneOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
{ | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
$ref: "#/items/0/$defs/allItems", | |
}, | |
{ | |
type: "array", | |
items: { | |
$ref: "#/items/0/$defs/allItems", | |
}, | |
}, | |
], | |
}, | |
}, | |
{ | |
type: "object", | |
properties: { | |
memberTypes: { | |
oneOf: [ | |
{ | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
$ref: "#/items/0/$defs/allItems", | |
}, | |
{ | |
type: "array", | |
items: { | |
$ref: "#/items/0/$defs/allItems", | |
}, | |
}, | |
], | |
}, | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
], | |
}, | |
order: { | |
$ref: "#/items/0/$defs/orderOptions", | |
}, | |
optionalityOrder: { | |
$ref: "#/items/0/$defs/optionalityOrderOptions", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
typesConfig: { | |
oneOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
{ | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
$ref: "#/items/0/$defs/typeItems", | |
}, | |
{ | |
type: "array", | |
items: { | |
$ref: "#/items/0/$defs/typeItems", | |
}, | |
}, | |
], | |
}, | |
}, | |
{ | |
type: "object", | |
properties: { | |
memberTypes: { | |
oneOf: [ | |
{ | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
$ref: "#/items/0/$defs/typeItems", | |
}, | |
{ | |
type: "array", | |
items: { | |
$ref: "#/items/0/$defs/typeItems", | |
}, | |
}, | |
], | |
}, | |
}, | |
{ | |
type: "string", | |
enum: [ | |
"never", | |
], | |
}, | |
], | |
}, | |
order: { | |
$ref: "#/items/0/$defs/orderOptions", | |
}, | |
optionalityOrder: { | |
$ref: "#/items/0/$defs/optionalityOrderOptions", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
type: "object", | |
properties: { | |
default: { | |
$ref: "#/items/0/$defs/baseConfig", | |
}, | |
classes: { | |
$ref: "#/items/0/$defs/baseConfig", | |
}, | |
classExpressions: { | |
$ref: "#/items/0/$defs/baseConfig", | |
}, | |
interfaces: { | |
$ref: "#/items/0/$defs/typesConfig", | |
}, | |
typeLiterals: { | |
$ref: "#/items/0/$defs/typesConfig", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"method-signature-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"property", | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce using a particular method signature syntax", | |
url: "https://typescript-eslint.io/rules/method-signature-style", | |
}, | |
fixable: "code", | |
messages: { | |
errorMethod: "Shorthand method signature is forbidden. Use a function property instead.", | |
errorProperty: "Function property signature is forbidden. Use a method shorthand instead.", | |
}, | |
schema: [ | |
{ | |
type: "string", | |
enum: [ | |
"property", | |
"method", | |
], | |
}, | |
], | |
}, | |
}, | |
"naming-convention": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
selector: "default", | |
format: [ | |
"camelCase", | |
], | |
leadingUnderscore: "allow", | |
trailingUnderscore: "allow", | |
}, | |
{ | |
selector: "import", | |
format: [ | |
"camelCase", | |
"PascalCase", | |
], | |
}, | |
{ | |
selector: "variable", | |
format: [ | |
"camelCase", | |
"UPPER_CASE", | |
], | |
leadingUnderscore: "allow", | |
trailingUnderscore: "allow", | |
}, | |
{ | |
selector: "typeLike", | |
format: [ | |
"PascalCase", | |
], | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Enforce naming conventions for everything across a codebase", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/naming-convention", | |
}, | |
type: "suggestion", | |
messages: { | |
unexpectedUnderscore: "{{type}} name `{{name}}` must not have a {{position}} underscore.", | |
missingUnderscore: "{{type}} name `{{name}}` must have {{count}} {{position}} underscore(s).", | |
missingAffix: "{{type}} name `{{name}}` must have one of the following {{position}}es: {{affixes}}", | |
satisfyCustom: "{{type}} name `{{name}}` must {{regexMatch}} the RegExp: {{regex}}", | |
doesNotMatchFormat: "{{type}} name `{{name}}` must match one of the following formats: {{formats}}", | |
doesNotMatchFormatTrimmed: "{{type}} name `{{name}}` trimmed as `{{processedName}}` must match one of the following formats: {{formats}}", | |
}, | |
schema: { | |
$defs: { | |
underscoreOptions: { | |
type: "string", | |
enum: [ | |
"forbid", | |
"allow", | |
"require", | |
"requireDouble", | |
"allowDouble", | |
"allowSingleOrDouble", | |
], | |
}, | |
predefinedFormats: { | |
type: "string", | |
enum: [ | |
"camelCase", | |
"strictCamelCase", | |
"PascalCase", | |
"StrictPascalCase", | |
"snake_case", | |
"UPPER_CASE", | |
], | |
}, | |
typeModifiers: { | |
type: "string", | |
enum: [ | |
"boolean", | |
"string", | |
"number", | |
"function", | |
"array", | |
], | |
}, | |
prefixSuffixConfig: { | |
type: "array", | |
items: { | |
type: "string", | |
minLength: 1, | |
}, | |
additionalItems: false, | |
}, | |
matchRegexConfig: { | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
match: { | |
type: "boolean", | |
}, | |
regex: { | |
type: "string", | |
}, | |
}, | |
required: [ | |
"match", | |
"regex", | |
], | |
}, | |
formatOptionsConfig: { | |
oneOf: [ | |
{ | |
type: "array", | |
items: { | |
$ref: "#/$defs/predefinedFormats", | |
}, | |
additionalItems: false, | |
}, | |
{ | |
type: "null", | |
}, | |
], | |
}, | |
}, | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
type: "object", | |
description: "Multiple selectors in one config", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"default", | |
"variableLike", | |
"memberLike", | |
"typeLike", | |
"method", | |
"property", | |
"accessor", | |
"variable", | |
"function", | |
"parameter", | |
"parameterProperty", | |
"classicAccessor", | |
"enumMember", | |
"classMethod", | |
"objectLiteralMethod", | |
"typeMethod", | |
"classProperty", | |
"objectLiteralProperty", | |
"typeProperty", | |
"autoAccessor", | |
"class", | |
"interface", | |
"typeAlias", | |
"enum", | |
"typeParameter", | |
"import", | |
], | |
}, | |
additionalItems: false, | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"const", | |
"readonly", | |
"static", | |
"public", | |
"protected", | |
"private", | |
"#private", | |
"abstract", | |
"destructured", | |
"global", | |
"exported", | |
"unused", | |
"requiresQuotes", | |
"override", | |
"async", | |
"default", | |
"namespace", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'default'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"default", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"const", | |
"readonly", | |
"static", | |
"public", | |
"protected", | |
"private", | |
"#private", | |
"abstract", | |
"destructured", | |
"global", | |
"exported", | |
"unused", | |
"requiresQuotes", | |
"override", | |
"async", | |
"default", | |
"namespace", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'variableLike'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"variableLike", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"unused", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'variable'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"variable", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"const", | |
"destructured", | |
"exported", | |
"global", | |
"unused", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'function'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"function", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"exported", | |
"global", | |
"unused", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'parameter'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"parameter", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"destructured", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'memberLike'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"memberLike", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"#private", | |
"protected", | |
"public", | |
"readonly", | |
"requiresQuotes", | |
"static", | |
"override", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'classProperty'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"classProperty", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"#private", | |
"protected", | |
"public", | |
"readonly", | |
"requiresQuotes", | |
"static", | |
"override", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'objectLiteralProperty'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"objectLiteralProperty", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"public", | |
"requiresQuotes", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'typeProperty'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"typeProperty", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"public", | |
"readonly", | |
"requiresQuotes", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'parameterProperty'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"parameterProperty", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"private", | |
"protected", | |
"public", | |
"readonly", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'property'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"property", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"#private", | |
"protected", | |
"public", | |
"readonly", | |
"requiresQuotes", | |
"static", | |
"override", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'classMethod'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"classMethod", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"#private", | |
"protected", | |
"public", | |
"requiresQuotes", | |
"static", | |
"override", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'objectLiteralMethod'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"objectLiteralMethod", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"public", | |
"requiresQuotes", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'typeMethod'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"typeMethod", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"public", | |
"requiresQuotes", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'method'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"method", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"#private", | |
"protected", | |
"public", | |
"requiresQuotes", | |
"static", | |
"override", | |
"async", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'classicAccessor'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"classicAccessor", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"protected", | |
"public", | |
"requiresQuotes", | |
"static", | |
"override", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'autoAccessor'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"autoAccessor", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"protected", | |
"public", | |
"requiresQuotes", | |
"static", | |
"override", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'accessor'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"accessor", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"private", | |
"protected", | |
"public", | |
"requiresQuotes", | |
"static", | |
"override", | |
], | |
}, | |
additionalItems: false, | |
}, | |
types: { | |
type: "array", | |
items: { | |
$ref: "#/$defs/typeModifiers", | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'enumMember'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"enumMember", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"requiresQuotes", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'typeLike'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"typeLike", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"exported", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'class'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"class", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"abstract", | |
"exported", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'interface'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"interface", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"exported", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'typeAlias'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"typeAlias", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"exported", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'enum'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"enum", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"exported", | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'typeParameter'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"typeParameter", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"unused", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
description: "Selector 'import'", | |
properties: { | |
format: { | |
$ref: "#/$defs/formatOptionsConfig", | |
}, | |
custom: { | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
leadingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
trailingUnderscore: { | |
$ref: "#/$defs/underscoreOptions", | |
}, | |
prefix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
suffix: { | |
$ref: "#/$defs/prefixSuffixConfig", | |
}, | |
failureMessage: { | |
type: "string", | |
}, | |
filter: { | |
oneOf: [ | |
{ | |
type: "string", | |
minLength: 1, | |
}, | |
{ | |
$ref: "#/$defs/matchRegexConfig", | |
}, | |
], | |
}, | |
selector: { | |
type: "string", | |
enum: [ | |
"import", | |
], | |
}, | |
modifiers: { | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"default", | |
"namespace", | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
required: [ | |
"selector", | |
"format", | |
], | |
additionalProperties: false, | |
}, | |
], | |
}, | |
additionalItems: false, | |
}, | |
}, | |
}, | |
"no-array-constructor": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow generic `Array` constructors", | |
recommended: "recommended", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-array-constructor", | |
}, | |
fixable: "code", | |
messages: { | |
useLiteral: "The array literal notation [] is preferable.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-array-delete": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
hasSuggestions: true, | |
type: "problem", | |
docs: { | |
description: "Disallow using the `delete` operator on array values", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-array-delete", | |
}, | |
messages: { | |
noArrayDelete: "Using the `delete` operator with an array expression is unsafe.", | |
useSplice: "Use `array.splice()` instead.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-base-to-string": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignoredTypeNames: [ | |
"Error", | |
"RegExp", | |
"URL", | |
"URLSearchParams", | |
], | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Require `.toString()` to only be called on objects which provide useful information when stringified", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-base-to-string", | |
}, | |
messages: { | |
baseToString: "'{{name}}' {{certainty}} evaluate to '[object Object]' when stringified.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignoredTypeNames: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-confusing-non-null-assertion": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow non-null assertion in locations that may be confusing", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/no-confusing-non-null-assertion", | |
}, | |
hasSuggestions: true, | |
messages: { | |
confusingEqual: "Confusing combinations of non-null assertion and equal test like \"a! == b\", which looks very similar to not equal \"a !== b\".", | |
confusingAssign: "Confusing combinations of non-null assertion and equal test like \"a! = b\", which looks very similar to not equal \"a != b\".", | |
notNeedInEqualTest: "Unnecessary non-null assertion (!) in equal test.", | |
notNeedInAssign: "Unnecessary non-null assertion (!) in assignment left hand.", | |
wrapUpLeft: "Wrap up left hand to avoid putting non-null assertion \"!\" and \"=\" together.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-confusing-void-expression": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignoreArrowShorthand: false, | |
ignoreVoidOperator: false, | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Require expressions of type void to appear in statement position", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-confusing-void-expression", | |
}, | |
messages: { | |
invalidVoidExpr: "Placing a void expression inside another expression is forbidden. Move it to its own statement instead.", | |
invalidVoidExprWrapVoid: "Void expressions used inside another expression must be moved to its own statement or marked explicitly with the `void` operator.", | |
invalidVoidExprArrow: "Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.", | |
invalidVoidExprArrowWrapVoid: "Void expressions returned from an arrow function shorthand must be marked explicitly with the `void` operator.", | |
invalidVoidExprReturn: "Returning a void expression from a function is forbidden. Please move it before the `return` statement.", | |
invalidVoidExprReturnLast: "Returning a void expression from a function is forbidden. Please remove the `return` statement.", | |
invalidVoidExprReturnWrapVoid: "Void expressions returned from a function must be marked explicitly with the `void` operator.", | |
voidExprWrapVoid: "Mark with an explicit `void` operator.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignoreArrowShorthand: { | |
type: "boolean", | |
}, | |
ignoreVoidOperator: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
type: "problem", | |
fixable: "code", | |
hasSuggestions: true, | |
}, | |
}, | |
"no-dupe-class-members": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow duplicate class members", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-dupe-class-members", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
], | |
messages: { | |
unexpected: "Duplicate name '{{name}}'.", | |
}, | |
}, | |
}, | |
"no-duplicate-enum-values": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow duplicate enum member values", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-duplicate-enum-values", | |
}, | |
hasSuggestions: false, | |
messages: { | |
duplicateValue: "Duplicate enum member value {{value}}.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-duplicate-type-constituents": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignoreIntersections: false, | |
ignoreUnions: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow duplicate constituents of union or intersection types", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-duplicate-type-constituents", | |
}, | |
fixable: "code", | |
messages: { | |
duplicate: "{{type}} type constituent is duplicated with {{previous}}.", | |
}, | |
schema: [ | |
{ | |
additionalProperties: false, | |
type: "object", | |
properties: { | |
ignoreIntersections: { | |
type: "boolean", | |
}, | |
ignoreUnions: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
}, | |
}, | |
"no-dynamic-delete": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow using the `delete` operator on computed key expressions", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/no-dynamic-delete", | |
}, | |
fixable: "code", | |
messages: { | |
dynamicDelete: "Do not delete dynamically computed property keys.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-empty-function": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow empty functions", | |
recommended: "stylistic", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-empty-function", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
enum: [ | |
"functions", | |
"arrowFunctions", | |
"generatorFunctions", | |
"methods", | |
"generatorMethods", | |
"getters", | |
"setters", | |
"constructors", | |
"private-constructors", | |
"protected-constructors", | |
"asyncFunctions", | |
"asyncMethods", | |
"decoratedFunctions", | |
"overrideMethods", | |
], | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
unexpected: "Unexpected empty {{name}}.", | |
}, | |
}, | |
}, | |
"no-empty-interface": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowSingleExtends: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow the declaration of empty interfaces", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/no-empty-interface", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
noEmpty: "An empty interface is equivalent to `{}`.", | |
noEmptyWithSuper: "An interface declaring no members is equivalent to its supertype.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
allowSingleExtends: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
}, | |
}, | |
"no-explicit-any": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
fixToUnknown: false, | |
ignoreRestArgs: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow the `any` type", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-explicit-any", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
unexpectedAny: "Unexpected any. Specify a different type.", | |
suggestUnknown: "Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.", | |
suggestNever: "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
fixToUnknown: { | |
description: "Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type.", | |
type: "boolean", | |
}, | |
ignoreRestArgs: { | |
description: "Whether to ignore rest parameter arrays.", | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
}, | |
}, | |
"no-extra-non-null-assertion": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow extra non-null assertions", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-extra-non-null-assertion", | |
}, | |
fixable: "code", | |
schema: [ | |
], | |
messages: { | |
noExtraNonNullAssertion: "Forbidden extra non-null assertion.", | |
}, | |
}, | |
}, | |
"no-extra-parens": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"all", | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/no-extra-parens", | |
], | |
type: "layout", | |
docs: { | |
description: "Disallow unnecessary parentheses", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-extra-parens", | |
}, | |
fixable: "code", | |
hasSuggestions: undefined, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"functions", | |
], | |
}, | |
], | |
minItems: 0, | |
maxItems: 1, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
enum: [ | |
"all", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
conditionalAssign: { | |
type: "boolean", | |
}, | |
ternaryOperandBinaryExpressions: { | |
type: "boolean", | |
}, | |
nestedBinaryExpressions: { | |
type: "boolean", | |
}, | |
returnAssign: { | |
type: "boolean", | |
}, | |
ignoreJSX: { | |
enum: [ | |
"none", | |
"all", | |
"single-line", | |
"multi-line", | |
], | |
}, | |
enforceForArrowConditionals: { | |
type: "boolean", | |
}, | |
enforceForSequenceExpressions: { | |
type: "boolean", | |
}, | |
enforceForNewInMemberExpressions: { | |
type: "boolean", | |
}, | |
enforceForFunctionPrototypeMethods: { | |
type: "boolean", | |
}, | |
allowParensAfterCommentPattern: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
minItems: 0, | |
maxItems: 2, | |
}, | |
], | |
}, | |
messages: { | |
unexpected: "Unnecessary parentheses around expression.", | |
}, | |
}, | |
}, | |
"no-extra-semi": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/no-extra-semi", | |
], | |
type: "suggestion", | |
docs: { | |
description: "Disallow unnecessary semicolons", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-extra-semi", | |
}, | |
fixable: "code", | |
hasSuggestions: undefined, | |
schema: [ | |
], | |
messages: { | |
unexpected: "Unnecessary semicolon.", | |
}, | |
}, | |
}, | |
"no-extraneous-class": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowConstructorOnly: false, | |
allowEmpty: false, | |
allowStaticOnly: false, | |
allowWithDecorator: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow classes used as namespaces", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/no-extraneous-class", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
allowConstructorOnly: { | |
description: "Whether to allow extraneous classes that contain only a constructor.", | |
type: "boolean", | |
}, | |
allowEmpty: { | |
description: "Whether to allow extraneous classes that have no body (i.e. are empty).", | |
type: "boolean", | |
}, | |
allowStaticOnly: { | |
description: "Whether to allow extraneous classes that only contain static members.", | |
type: "boolean", | |
}, | |
allowWithDecorator: { | |
description: "Whether to allow extraneous classes that include a decorator.", | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
messages: { | |
empty: "Unexpected empty class.", | |
onlyStatic: "Unexpected class with only static properties.", | |
onlyConstructor: "Unexpected class with only a constructor.", | |
}, | |
}, | |
}, | |
"no-floating-promises": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignoreVoid: true, | |
ignoreIIFE: false, | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Require Promise-like statements to be handled appropriately", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-floating-promises", | |
}, | |
hasSuggestions: true, | |
messages: { | |
floating: "Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler.", | |
floatingFixAwait: "Add await operator.", | |
floatingVoid: "Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.", | |
floatingFixVoid: "Add void operator to ignore.", | |
floatingUselessRejectionHandler: "Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler. A rejection handler that is not a function will be ignored.", | |
floatingUselessRejectionHandlerVoid: "Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. A rejection handler that is not a function will be ignored.", | |
floatingPromiseArray: "An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar.", | |
floatingPromiseArrayVoid: "An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking the expression as ignored with the `void` operator.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignoreVoid: { | |
description: "Whether to ignore `void` expressions.", | |
type: "boolean", | |
}, | |
ignoreIIFE: { | |
description: "Whether to ignore async IIFEs (Immediately Invoked Function Expressions).", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
type: "problem", | |
}, | |
}, | |
"no-for-in-array": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow iterating over an array with a for-in loop", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-for-in-array", | |
}, | |
messages: { | |
forInViolation: "For-in loops over arrays skips holes, returns indices as strings, and may visit the prototype chain or other enumerable properties. Use a more robust iteration method such as for-of or array.forEach instead.", | |
}, | |
schema: [ | |
], | |
type: "problem", | |
}, | |
}, | |
"no-implied-eval": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow the use of `eval()`-like methods", | |
recommended: "recommended", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-implied-eval", | |
}, | |
messages: { | |
noImpliedEvalError: "Implied eval. Consider passing a function.", | |
noFunctionConstructor: "Implied eval. Do not use the Function constructor to create functions.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-import-type-side-effects": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers", | |
url: "https://typescript-eslint.io/rules/no-import-type-side-effects", | |
}, | |
fixable: "code", | |
messages: { | |
useTopLevelQualifier: "TypeScript will only remove the inline type specifiers which will leave behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-inferrable-types": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignoreParameters: false, | |
ignoreProperties: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/no-inferrable-types", | |
}, | |
fixable: "code", | |
messages: { | |
noInferrableType: "Type {{type}} trivially inferred from a {{type}} literal, remove type annotation.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
ignoreParameters: { | |
type: "boolean", | |
}, | |
ignoreProperties: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-invalid-this": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
capIsConstructor: true, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow `this` keywords outside of classes or class-like objects", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-invalid-this", | |
}, | |
messages: { | |
unexpectedThis: "Unexpected 'this'.", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
capIsConstructor: { | |
type: "boolean", | |
default: true, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-invalid-void-type": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowInGenericTypeArguments: true, | |
allowAsThisParameter: false, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow `void` type outside of generic or return types", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/no-invalid-void-type", | |
}, | |
messages: { | |
invalidVoidForGeneric: "{{ generic }} may not have void as a type argument.", | |
invalidVoidNotReturnOrGeneric: "void is only valid as a return type or generic type argument.", | |
invalidVoidNotReturn: "void is only valid as a return type.", | |
invalidVoidNotReturnOrThisParam: "void is only valid as return type or type of `this` parameter.", | |
invalidVoidNotReturnOrThisParamOrGeneric: "void is only valid as a return type or generic type argument or the type of a `this` parameter.", | |
invalidVoidUnionConstituent: "void is not valid as a constituent in a union type", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowInGenericTypeArguments: { | |
oneOf: [ | |
{ | |
type: "boolean", | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
minItems: 1, | |
}, | |
], | |
}, | |
allowAsThisParameter: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-loop-func": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow function declarations that contain unsafe references inside loop statements", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-loop-func", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
], | |
messages: { | |
unsafeRefs: "Function declared in a loop contains unsafe references to variable(s) {{ varNames }}.", | |
}, | |
}, | |
}, | |
"no-loss-of-precision": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow literal numbers that lose precision", | |
recommended: "recommended", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-loss-of-precision", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
], | |
messages: { | |
noLossOfPrecision: "This number literal will lose precision at runtime.", | |
}, | |
}, | |
}, | |
"no-magic-numbers": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
ignore: [ | |
], | |
ignoreArrayIndexes: false, | |
enforceConst: false, | |
detectObjects: false, | |
ignoreNumericLiteralTypes: false, | |
ignoreEnums: false, | |
ignoreReadonlyClassProperties: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow magic numbers", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-magic-numbers", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
detectObjects: { | |
type: "boolean", | |
default: false, | |
}, | |
enforceConst: { | |
type: "boolean", | |
default: false, | |
}, | |
ignore: { | |
type: "array", | |
items: { | |
anyOf: [ | |
{ | |
type: "number", | |
}, | |
{ | |
type: "string", | |
pattern: "^[+-]?(?:0|[1-9][0-9]*)n$", | |
}, | |
], | |
}, | |
uniqueItems: true, | |
}, | |
ignoreArrayIndexes: { | |
type: "boolean", | |
default: false, | |
}, | |
ignoreDefaultValues: { | |
type: "boolean", | |
default: false, | |
}, | |
ignoreClassFieldInitialValues: { | |
type: "boolean", | |
default: false, | |
}, | |
ignoreNumericLiteralTypes: { | |
type: "boolean", | |
}, | |
ignoreEnums: { | |
type: "boolean", | |
}, | |
ignoreReadonlyClassProperties: { | |
type: "boolean", | |
}, | |
ignoreTypeIndexes: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
useConst: "Number constants declarations must use 'const'.", | |
noMagic: "No magic number: {{raw}}.", | |
}, | |
}, | |
}, | |
"no-meaningless-void-operator": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
checkNever: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow the `void` operator except when used to discard a value", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-meaningless-void-operator", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
meaninglessVoidOperator: "void operator shouldn't be used on {{type}}; it should convey that a return value is being ignored", | |
removeVoid: "Remove 'void'", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
checkNever: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-misused-new": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Enforce valid definition of `new` and `constructor`", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-misused-new", | |
}, | |
schema: [ | |
], | |
messages: { | |
errorMessageInterface: "Interfaces cannot be constructed, only classes.", | |
errorMessageClass: "Class cannot have method named `new`.", | |
}, | |
}, | |
}, | |
"no-misused-promises": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
checksConditionals: true, | |
checksVoidReturn: true, | |
checksSpreads: true, | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Disallow Promises in places not designed to handle them", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-misused-promises", | |
}, | |
messages: { | |
voidReturnArgument: "Promise returned in function argument where a void return was expected.", | |
voidReturnVariable: "Promise-returning function provided to variable where a void return was expected.", | |
voidReturnProperty: "Promise-returning function provided to property where a void return was expected.", | |
voidReturnReturnValue: "Promise-returning function provided to return value where a void return was expected.", | |
voidReturnAttribute: "Promise-returning function provided to attribute where a void return was expected.", | |
conditional: "Expected non-Promise value in a boolean conditional.", | |
spread: "Expected a non-Promise value to be spreaded in an object.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
checksConditionals: { | |
type: "boolean", | |
}, | |
checksVoidReturn: { | |
oneOf: [ | |
{ | |
type: "boolean", | |
}, | |
{ | |
additionalProperties: false, | |
properties: { | |
arguments: { | |
type: "boolean", | |
}, | |
attributes: { | |
type: "boolean", | |
}, | |
properties: { | |
type: "boolean", | |
}, | |
returns: { | |
type: "boolean", | |
}, | |
variables: { | |
type: "boolean", | |
}, | |
}, | |
type: "object", | |
}, | |
], | |
}, | |
checksSpreads: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
type: "problem", | |
}, | |
}, | |
"no-mixed-enums": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow enums from having both number and string members", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-mixed-enums", | |
}, | |
messages: { | |
mixed: "Mixing number and string enums can be confusing.", | |
}, | |
schema: [ | |
], | |
type: "problem", | |
}, | |
}, | |
"no-namespace": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowDeclarations: false, | |
allowDefinitionFiles: true, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow TypeScript namespaces", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-namespace", | |
}, | |
messages: { | |
moduleSyntaxIsPreferred: "ES2015 module syntax is preferred over namespaces.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowDeclarations: { | |
description: "Whether to allow `declare` with custom TypeScript namespaces.", | |
type: "boolean", | |
}, | |
allowDefinitionFiles: { | |
description: "Whether to allow `declare` with custom TypeScript namespaces inside definition files.", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-non-null-asserted-nullish-coalescing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow non-null assertions in the left operand of a nullish coalescing operator", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/no-non-null-asserted-nullish-coalescing", | |
}, | |
messages: { | |
noNonNullAssertedNullishCoalescing: "The nullish coalescing operator is designed to handle undefined and null - using a non-null assertion is not needed.", | |
suggestRemovingNonNull: "Remove the non-null assertion.", | |
}, | |
schema: [ | |
], | |
hasSuggestions: true, | |
}, | |
}, | |
"no-non-null-asserted-optional-chain": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow non-null assertions after an optional chain expression", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain", | |
}, | |
hasSuggestions: true, | |
messages: { | |
noNonNullOptionalChain: "Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong.", | |
suggestRemovingNonNull: "You should remove the non-null assertion.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-non-null-assertion": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow non-null assertions using the `!` postfix operator", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/no-non-null-assertion", | |
}, | |
hasSuggestions: true, | |
messages: { | |
noNonNull: "Forbidden non-null assertion.", | |
suggestOptionalChain: "Consider using the optional chain operator `?.` instead. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-redeclare": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
builtinGlobals: true, | |
ignoreDeclarationMerge: true, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow variable redeclaration", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-redeclare", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
builtinGlobals: { | |
type: "boolean", | |
}, | |
ignoreDeclarationMerge: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
redeclared: "'{{id}}' is already defined.", | |
redeclaredAsBuiltin: "'{{id}}' is already defined as a built-in global variable.", | |
redeclaredBySyntax: "'{{id}}' is already defined by a variable declaration.", | |
}, | |
}, | |
}, | |
"no-redundant-type-constituents": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow members of unions and intersections that do nothing or override type information", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-redundant-type-constituents", | |
}, | |
messages: { | |
literalOverridden: "{{literal}} is overridden by {{primitive}} in this union type.", | |
primitiveOverridden: "{{primitive}} is overridden by the {{literal}} in this intersection type.", | |
overridden: "'{{typeName}}' is overridden by other types in this {{container}} type.", | |
overrides: "'{{typeName}}' overrides all other types in this {{container}} type.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-require-imports": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow invocation of `require()`", | |
url: "https://typescript-eslint.io/rules/no-require-imports", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
description: "Patterns of import paths to allow requiring from.", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
noRequireImports: "A `require()` style import is forbidden.", | |
}, | |
}, | |
}, | |
"no-restricted-imports": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow specified modules when loaded by `import`", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-restricted-imports", | |
}, | |
messages: { | |
path: "'{{importSource}}' import is restricted from being used.", | |
pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}", | |
patterns: "'{{importSource}}' import is restricted from being used by a pattern.", | |
patternWithCustomMessage: "'{{importSource}}' import is restricted from being used by a pattern. {{customMessage}}", | |
patternAndImportName: "'{{importName}}' import from '{{importSource}}' is restricted from being used by a pattern.", | |
patternAndImportNameWithCustomMessage: "'{{importName}}' import from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}", | |
patternAndEverything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern.", | |
patternAndEverythingWithRegexImportName: "* import is invalid because import name matching '{{importNames}}' pattern from '{{importSource}}' is restricted from being used.", | |
patternAndEverythingWithCustomMessage: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}", | |
patternAndEverythingWithRegexImportNameAndCustomMessage: "* import is invalid because import name matching '{{importNames}}' pattern from '{{importSource}}' is restricted from being used. {{customMessage}}", | |
everything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted.", | |
everythingWithCustomMessage: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted. {{customMessage}}", | |
importName: "'{{importName}}' import from '{{importSource}}' is restricted.", | |
importNameWithCustomMessage: "'{{importName}}' import from '{{importSource}}' is restricted. {{customMessage}}", | |
}, | |
fixable: undefined, | |
schema: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
name: { | |
type: "string", | |
}, | |
message: { | |
type: "string", | |
minLength: 1, | |
}, | |
importNames: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
allowTypeImports: { | |
type: "boolean", | |
description: "Disallow value imports, but allow type-only imports.", | |
}, | |
}, | |
required: [ | |
"name", | |
], | |
}, | |
], | |
}, | |
uniqueItems: true, | |
}, | |
{ | |
type: "array", | |
items: [ | |
{ | |
type: "object", | |
properties: { | |
paths: { | |
type: "array", | |
items: { | |
anyOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
name: { | |
type: "string", | |
}, | |
message: { | |
type: "string", | |
minLength: 1, | |
}, | |
importNames: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
allowTypeImports: { | |
type: "boolean", | |
description: "Disallow value imports, but allow type-only imports.", | |
}, | |
}, | |
required: [ | |
"name", | |
], | |
}, | |
], | |
}, | |
uniqueItems: true, | |
}, | |
patterns: { | |
anyOf: [ | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
uniqueItems: true, | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
importNames: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
minItems: 1, | |
uniqueItems: true, | |
}, | |
group: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
minItems: 1, | |
uniqueItems: true, | |
}, | |
importNamePattern: { | |
type: "string", | |
}, | |
message: { | |
type: "string", | |
minLength: 1, | |
}, | |
caseSensitive: { | |
type: "boolean", | |
}, | |
allowTypeImports: { | |
type: "boolean", | |
description: "Disallow value imports, but allow type-only imports.", | |
}, | |
}, | |
required: [ | |
"group", | |
], | |
}, | |
uniqueItems: true, | |
}, | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
}, | |
"no-shadow": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
builtinGlobals: false, | |
hoist: "functions", | |
ignoreOnInitialization: false, | |
ignoreTypeValueShadow: true, | |
ignoreFunctionTypeParameterNameValueShadow: true, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow variable declarations from shadowing variables declared in the outer scope", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-shadow", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
builtinGlobals: { | |
type: "boolean", | |
}, | |
hoist: { | |
type: "string", | |
enum: [ | |
"all", | |
"functions", | |
"never", | |
], | |
}, | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
ignoreOnInitialization: { | |
type: "boolean", | |
}, | |
ignoreTypeValueShadow: { | |
type: "boolean", | |
}, | |
ignoreFunctionTypeParameterNameValueShadow: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
noShadow: "'{{name}}' is already declared in the upper scope on line {{shadowedLine}} column {{shadowedColumn}}.", | |
noShadowGlobal: "'{{name}}' is already a global variable.", | |
}, | |
}, | |
}, | |
"no-this-alias": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowDestructuring: true, | |
allowedNames: [ | |
], | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow aliasing `this`", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-this-alias", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
allowDestructuring: { | |
description: "Whether to ignore destructurings, such as `const { props, state } = this`.", | |
type: "boolean", | |
}, | |
allowedNames: { | |
description: "Names to ignore, such as [\"self\"] for `const self = this;`.", | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
}, | |
], | |
messages: { | |
thisAssignment: "Unexpected aliasing of 'this' to local variable.", | |
thisDestructure: "Unexpected aliasing of members of 'this' to local variables.", | |
}, | |
}, | |
}, | |
"no-throw-literal": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowThrowingAny: true, | |
allowThrowingUnknown: true, | |
}, | |
], | |
meta: { | |
type: "problem", | |
deprecated: true, | |
replacedBy: [ | |
"@typescript-eslint/only-throw-error", | |
], | |
docs: { | |
description: "Disallow throwing literals as exceptions", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-throw-literal", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowThrowingAny: { | |
type: "boolean", | |
}, | |
allowThrowingUnknown: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
object: "Expected an error object to be thrown.", | |
undef: "Do not throw undefined.", | |
}, | |
}, | |
}, | |
"no-type-alias": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowAliases: "never", | |
allowCallbacks: "never", | |
allowConditionalTypes: "never", | |
allowConstructors: "never", | |
allowLiterals: "never", | |
allowMappedTypes: "never", | |
allowTupleTypes: "never", | |
allowGenerics: "never", | |
}, | |
], | |
meta: { | |
deprecated: true, | |
type: "suggestion", | |
docs: { | |
description: "Disallow type aliases", | |
url: "https://typescript-eslint.io/rules/no-type-alias", | |
}, | |
messages: { | |
noTypeAlias: "Type {{alias}} are not allowed.", | |
noCompositionAlias: "{{typeName}} in {{compositionType}} types are not allowed.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
expandedOptions: { | |
type: "string", | |
enum: [ | |
"always", | |
"never", | |
"in-unions", | |
"in-intersections", | |
"in-unions-and-intersections", | |
], | |
}, | |
simpleOptions: { | |
type: "string", | |
enum: [ | |
"always", | |
"never", | |
], | |
}, | |
}, | |
type: "object", | |
properties: { | |
allowAliases: { | |
description: "Whether to allow direct one-to-one type aliases.", | |
$ref: "#/items/0/$defs/expandedOptions", | |
}, | |
allowCallbacks: { | |
description: "Whether to allow type aliases for callbacks.", | |
$ref: "#/items/0/$defs/simpleOptions", | |
}, | |
allowConditionalTypes: { | |
description: "Whether to allow type aliases for conditional types.", | |
$ref: "#/items/0/$defs/simpleOptions", | |
}, | |
allowConstructors: { | |
description: "Whether to allow type aliases with constructors.", | |
$ref: "#/items/0/$defs/simpleOptions", | |
}, | |
allowLiterals: { | |
description: "Whether to allow type aliases with object literal types.", | |
$ref: "#/items/0/$defs/expandedOptions", | |
}, | |
allowMappedTypes: { | |
description: "Whether to allow type aliases with mapped types.", | |
$ref: "#/items/0/$defs/expandedOptions", | |
}, | |
allowTupleTypes: { | |
description: "Whether to allow type aliases with tuple types.", | |
$ref: "#/items/0/$defs/expandedOptions", | |
}, | |
allowGenerics: { | |
description: "Whether to allow type aliases with generic types.", | |
$ref: "#/items/0/$defs/simpleOptions", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"no-unnecessary-boolean-literal-compare": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowComparingNullableBooleansToTrue: true, | |
allowComparingNullableBooleansToFalse: true, | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Disallow unnecessary equality comparisons against boolean literals", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare", | |
}, | |
fixable: "code", | |
messages: { | |
direct: "This expression unnecessarily compares a boolean value to a boolean instead of using it directly.", | |
negated: "This expression unnecessarily compares a boolean value to a boolean instead of negating it.", | |
comparingNullableToTrueDirect: "This expression unnecessarily compares a nullable boolean value to true instead of using it directly.", | |
comparingNullableToTrueNegated: "This expression unnecessarily compares a nullable boolean value to true instead of negating it.", | |
comparingNullableToFalse: "This expression unnecessarily compares a nullable boolean value to false instead of using the ?? operator to provide a default.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowComparingNullableBooleansToTrue: { | |
description: "Whether to allow comparisons between nullable boolean variables and `true`.", | |
type: "boolean", | |
}, | |
allowComparingNullableBooleansToFalse: { | |
description: "Whether to allow comparisons between nullable boolean variables and `false`.", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-unnecessary-condition": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowConstantLoopConditions: false, | |
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow conditionals where the type is always truthy or always falsy", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unnecessary-condition", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowConstantLoopConditions: { | |
description: "Whether to ignore constant loop conditions, such as `while (true)`.", | |
type: "boolean", | |
}, | |
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: { | |
description: "Whether to not error when running with a tsconfig that has strictNullChecks turned.", | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
fixable: "code", | |
messages: { | |
alwaysTruthy: "Unnecessary conditional, value is always truthy.", | |
alwaysFalsy: "Unnecessary conditional, value is always falsy.", | |
alwaysTruthyFunc: "This callback should return a conditional, but return is always truthy.", | |
alwaysFalsyFunc: "This callback should return a conditional, but return is always falsy.", | |
neverNullish: "Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined.", | |
alwaysNullish: "Unnecessary conditional, left-hand side of `??` operator is always `null` or `undefined`.", | |
literalBooleanExpression: "Unnecessary conditional, both sides of the expression are literal values.", | |
noOverlapBooleanExpression: "Unnecessary conditional, the types have no overlap.", | |
never: "Unnecessary conditional, value is `never`.", | |
neverOptionalChain: "Unnecessary optional chain on a non-nullish value.", | |
noStrictNullCheck: "This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.", | |
}, | |
}, | |
}, | |
"no-unnecessary-qualifier": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow unnecessary namespace qualifiers", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unnecessary-qualifier", | |
}, | |
fixable: "code", | |
messages: { | |
unnecessaryQualifier: "Qualifier is unnecessary since '{{ name }}' is in scope.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-unnecessary-type-arguments": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow type arguments that are equal to the default", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unnecessary-type-arguments", | |
}, | |
fixable: "code", | |
messages: { | |
unnecessaryTypeParameter: "This is the default value for this type parameter, so it can be omitted.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-unnecessary-type-assertion": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Disallow type assertions that do not change the type of an expression", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unnecessary-type-assertion", | |
}, | |
fixable: "code", | |
messages: { | |
unnecessaryAssertion: "This assertion is unnecessary since it does not change the type of the expression.", | |
contextuallyUnnecessary: "This assertion is unnecessary since the receiver accepts the original type of the expression.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
typesToIgnore: { | |
description: "A list of type names to ignore.", | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
}, | |
}, | |
}, | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-unnecessary-type-constraint": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow unnecessary constraints on generic types", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-unnecessary-type-constraint", | |
}, | |
hasSuggestions: true, | |
messages: { | |
unnecessaryConstraint: "Constraining the generic type `{{name}}` to `{{constraint}}` does nothing and is unnecessary.", | |
removeUnnecessaryConstraint: "Remove the unnecessary `{{constraint}}` constraint.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-unsafe-argument": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow calling a function with a value with type `any`", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-argument", | |
}, | |
messages: { | |
unsafeArgument: "Unsafe argument of type `{{sender}}` assigned to a parameter of type `{{receiver}}`.", | |
unsafeTupleSpread: "Unsafe spread of a tuple type. The argument is of type `{{sender}}` and is assigned to a parameter of type `{{receiver}}`.", | |
unsafeArraySpread: "Unsafe spread of an `any` array type.", | |
unsafeSpread: "Unsafe spread of an `any` type.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-assignment": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow assigning a value with type `any` to variables and properties", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-assignment", | |
}, | |
messages: { | |
anyAssignment: "Unsafe assignment of an `any` value.", | |
anyAssignmentThis: "Unsafe assignment of an `any` value. `this` is typed as `any`.\nYou can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.", | |
unsafeArrayPattern: "Unsafe array destructuring of an `any` array value.", | |
unsafeArrayPatternFromTuple: "Unsafe array destructuring of a tuple element with an `any` value.", | |
unsafeAssignment: "Unsafe assignment of type {{sender}} to a variable of type {{receiver}}.", | |
unsafeArraySpread: "Unsafe spread of an `any` value in an array.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-call": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow calling a value with type `any`", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-call", | |
}, | |
messages: { | |
unsafeCall: "Unsafe call of an `any` typed value.", | |
unsafeCallThis: "Unsafe call of an `any` typed value. `this` is typed as `any`.\nYou can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.", | |
unsafeNew: "Unsafe construction of an any type value.", | |
unsafeTemplateTag: "Unsafe any typed template tag.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-declaration-merging": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow unsafe declaration merging", | |
recommended: "recommended", | |
requiresTypeChecking: false, | |
url: "https://typescript-eslint.io/rules/no-unsafe-declaration-merging", | |
}, | |
messages: { | |
unsafeMerging: "Unsafe declaration merging between classes and interfaces.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-enum-comparison": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
hasSuggestions: true, | |
type: "suggestion", | |
docs: { | |
description: "Disallow comparing an enum value with a non-enum value", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-enum-comparison", | |
}, | |
messages: { | |
mismatchedCase: "The case statement does not have a shared enum type with the switch predicate.", | |
mismatchedCondition: "The two values in this comparison do not have a shared enum type.", | |
replaceValueWithEnum: "Replace with an enum value comparison.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-member-access": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow member access on a value with type `any`", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-member-access", | |
}, | |
messages: { | |
unsafeMemberExpression: "Unsafe member access {{property}} on an `any` value.", | |
unsafeThisMemberExpression: "Unsafe member access {{property}} on an `any` value. `this` is typed as `any`.\nYou can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.", | |
unsafeComputedMemberAccess: "Computed name {{property}} resolves to an any value.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-return": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow returning a value with type `any` from a function", | |
recommended: "recommended", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-return", | |
}, | |
messages: { | |
unsafeReturn: "Unsafe return of an `{{type}}` typed value.", | |
unsafeReturnThis: "Unsafe return of an `{{type}}` typed value. `this` is typed as `any`.\nYou can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.", | |
unsafeReturnAssignment: "Unsafe return of type `{{sender}}` from function with return type `{{receiver}}`.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unsafe-unary-minus": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Require unary negation to take a number", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-unsafe-unary-minus", | |
}, | |
messages: { | |
unaryMinus: "Argument of unary negation should be assignable to number | bigint but is {{type}} instead.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-unused-expressions": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowShortCircuit: false, | |
allowTernary: false, | |
allowTaggedTemplates: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Disallow unused expressions", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-unused-expressions", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowShortCircuit: { | |
type: "boolean", | |
default: false, | |
}, | |
allowTernary: { | |
type: "boolean", | |
default: false, | |
}, | |
allowTaggedTemplates: { | |
type: "boolean", | |
default: false, | |
}, | |
enforceForJSX: { | |
type: "boolean", | |
default: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
unusedExpression: "Expected an assignment or function call and instead saw an expression.", | |
}, | |
}, | |
}, | |
"no-unused-vars": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow unused variables", | |
recommended: "recommended", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-unused-vars", | |
}, | |
schema: [ | |
{ | |
oneOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"all", | |
"local", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
vars: { | |
type: "string", | |
enum: [ | |
"all", | |
"local", | |
], | |
}, | |
varsIgnorePattern: { | |
type: "string", | |
}, | |
args: { | |
type: "string", | |
enum: [ | |
"all", | |
"after-used", | |
"none", | |
], | |
}, | |
ignoreRestSiblings: { | |
type: "boolean", | |
}, | |
argsIgnorePattern: { | |
type: "string", | |
}, | |
caughtErrors: { | |
type: "string", | |
enum: [ | |
"all", | |
"none", | |
], | |
}, | |
caughtErrorsIgnorePattern: { | |
type: "string", | |
}, | |
destructuredArrayIgnorePattern: { | |
type: "string", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
messages: { | |
unusedVar: "'{{varName}}' is {{action}} but never used{{additional}}.", | |
}, | |
}, | |
}, | |
"no-use-before-define": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
functions: true, | |
classes: true, | |
enums: true, | |
variables: true, | |
typedefs: true, | |
ignoreTypeReferences: true, | |
allowNamedExports: false, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow the use of variables before they are defined", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-use-before-define", | |
}, | |
messages: { | |
noUseBeforeDefine: "'{{name}}' was used before it was defined.", | |
}, | |
schema: [ | |
{ | |
oneOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"nofunc", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
functions: { | |
type: "boolean", | |
}, | |
classes: { | |
type: "boolean", | |
}, | |
enums: { | |
type: "boolean", | |
}, | |
variables: { | |
type: "boolean", | |
}, | |
typedefs: { | |
type: "boolean", | |
}, | |
ignoreTypeReferences: { | |
type: "boolean", | |
}, | |
allowNamedExports: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
], | |
}, | |
}, | |
"no-useless-constructor": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow unnecessary constructors", | |
recommended: "strict", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/no-useless-constructor", | |
}, | |
hasSuggestions: undefined, | |
schema: [ | |
], | |
messages: { | |
noUselessConstructor: "Useless constructor.", | |
}, | |
}, | |
}, | |
"no-useless-empty-export": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Disallow empty exports that don't change anything in a module file", | |
url: "https://typescript-eslint.io/rules/no-useless-empty-export", | |
}, | |
fixable: "code", | |
hasSuggestions: false, | |
messages: { | |
uselessExport: "Empty export does nothing and can be removed.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"no-useless-template-literals": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
fixable: "code", | |
type: "suggestion", | |
docs: { | |
description: "Disallow unnecessary template literals", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/no-useless-template-literals", | |
}, | |
messages: { | |
noUselessTemplateLiteral: "Template literal expression is unnecessary and can be simplified.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"no-var-requires": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow `require` statements except in import statements", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/no-var-requires", | |
}, | |
messages: { | |
noVarReqs: "Require statement not part of import statement.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
type: "string", | |
}, | |
description: "Patterns of import paths to allow requiring from.", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"non-nullable-type-assertion-style": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Enforce non-null assertions over explicit type casts", | |
recommended: "stylistic", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/non-nullable-type-assertion-style", | |
}, | |
fixable: "code", | |
messages: { | |
preferNonNullAssertion: "Use a ! assertion to more succinctly remove null and undefined from the type.", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"object-curly-spacing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
"never", | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/object-curly-spacing", | |
], | |
type: "layout", | |
docs: { | |
description: "Enforce consistent spacing inside braces", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/object-curly-spacing", | |
}, | |
fixable: "whitespace", | |
schema: [ | |
{ | |
enum: [ | |
"always", | |
"never", | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
arraysInObjects: { | |
type: "boolean", | |
}, | |
objectsInObjects: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
requireSpaceBefore: "A space is required before '{{token}}'.", | |
requireSpaceAfter: "A space is required after '{{token}}'.", | |
unexpectedSpaceBefore: "There should be no space before '{{token}}'.", | |
unexpectedSpaceAfter: "There should be no space after '{{token}}'.", | |
}, | |
}, | |
}, | |
"only-throw-error": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowThrowingAny: true, | |
allowThrowingUnknown: true, | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Disallow throwing non-`Error` values as exceptions", | |
recommended: "strict", | |
extendsBaseRule: "no-throw-literal", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/only-throw-error", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowThrowingAny: { | |
type: "boolean", | |
}, | |
allowThrowingUnknown: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
object: "Expected an error object to be thrown.", | |
undef: "Do not throw undefined.", | |
}, | |
}, | |
}, | |
"padding-line-between-statements": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
deprecated: true, | |
replacedBy: [ | |
"@stylistic/ts/padding-line-between-statements", | |
], | |
type: "layout", | |
docs: { | |
description: "Require or disallow padding lines between statements", | |
extendsBaseRule: true, | |
url: "https://typescript-eslint.io/rules/padding-line-between-statements", | |
}, | |
fixable: "whitespace", | |
hasSuggestions: false, | |
schema: { | |
$defs: { | |
paddingType: { | |
type: "string", | |
enum: [ | |
"any", | |
"never", | |
"always", | |
], | |
}, | |
statementType: { | |
anyOf: [ | |
{ | |
type: "string", | |
enum: [ | |
"*", | |
"block-like", | |
"exports", | |
"require", | |
"directive", | |
"expression", | |
"iife", | |
"multiline-block-like", | |
"multiline-expression", | |
"multiline-const", | |
"multiline-let", | |
"multiline-var", | |
"singleline-const", | |
"singleline-let", | |
"singleline-var", | |
"block", | |
"empty", | |
"function", | |
"break", | |
"case", | |
"class", | |
"const", | |
"continue", | |
"debugger", | |
"default", | |
"do", | |
"export", | |
"for", | |
"if", | |
"import", | |
"let", | |
"return", | |
"switch", | |
"throw", | |
"try", | |
"var", | |
"while", | |
"with", | |
"interface", | |
"type", | |
], | |
}, | |
{ | |
type: "array", | |
items: { | |
type: "string", | |
enum: [ | |
"*", | |
"block-like", | |
"exports", | |
"require", | |
"directive", | |
"expression", | |
"iife", | |
"multiline-block-like", | |
"multiline-expression", | |
"multiline-const", | |
"multiline-let", | |
"multiline-var", | |
"singleline-const", | |
"singleline-let", | |
"singleline-var", | |
"block", | |
"empty", | |
"function", | |
"break", | |
"case", | |
"class", | |
"const", | |
"continue", | |
"debugger", | |
"default", | |
"do", | |
"export", | |
"for", | |
"if", | |
"import", | |
"let", | |
"return", | |
"switch", | |
"throw", | |
"try", | |
"var", | |
"while", | |
"with", | |
"interface", | |
"type", | |
], | |
}, | |
minItems: 1, | |
uniqueItems: true, | |
additionalItems: false, | |
}, | |
], | |
}, | |
}, | |
type: "array", | |
additionalItems: false, | |
items: { | |
type: "object", | |
properties: { | |
blankLine: { | |
$ref: "#/$defs/paddingType", | |
}, | |
prev: { | |
$ref: "#/$defs/statementType", | |
}, | |
next: { | |
$ref: "#/$defs/statementType", | |
}, | |
}, | |
additionalProperties: false, | |
required: [ | |
"blankLine", | |
"prev", | |
"next", | |
], | |
}, | |
}, | |
messages: { | |
unexpectedBlankLine: "Unexpected blank line before this statement.", | |
expectedBlankLine: "Expected blank line before this statement.", | |
}, | |
}, | |
}, | |
"parameter-properties": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
prefer: "class-property", | |
}, | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Require or disallow parameter properties in class constructors", | |
url: "https://typescript-eslint.io/rules/parameter-properties", | |
}, | |
messages: { | |
preferClassProperty: "Property {{parameter}} should be declared as a class property.", | |
preferParameterProperty: "Property {{parameter}} should be declared as a parameter property.", | |
}, | |
schema: [ | |
{ | |
$defs: { | |
modifier: { | |
type: "string", | |
enum: [ | |
"readonly", | |
"private", | |
"protected", | |
"public", | |
"private readonly", | |
"protected readonly", | |
"public readonly", | |
], | |
}, | |
}, | |
type: "object", | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
$ref: "#/items/0/$defs/modifier", | |
}, | |
}, | |
prefer: { | |
type: "string", | |
enum: [ | |
"class-property", | |
"parameter-property", | |
], | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"prefer-as-const": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce the use of `as const` over literal type", | |
recommended: "recommended", | |
url: "https://typescript-eslint.io/rules/prefer-as-const", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
preferConstAssertion: "Expected a `const` instead of a literal type assertion.", | |
variableConstAssertion: "Expected a `const` assertion instead of a literal type annotation.", | |
variableSuggest: "You should use `as const` instead of type annotation.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-destructuring": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
VariableDeclarator: { | |
array: true, | |
object: true, | |
}, | |
AssignmentExpression: { | |
array: true, | |
object: true, | |
}, | |
}, | |
{ | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require destructuring from arrays and/or objects", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-destructuring", | |
}, | |
schema: [ | |
{ | |
oneOf: [ | |
{ | |
type: "object", | |
properties: { | |
VariableDeclarator: { | |
type: "object", | |
properties: { | |
array: { | |
type: "boolean", | |
}, | |
object: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
AssignmentExpression: { | |
type: "object", | |
properties: { | |
array: { | |
type: "boolean", | |
}, | |
object: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
{ | |
type: "object", | |
properties: { | |
array: { | |
type: "boolean", | |
}, | |
object: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
{ | |
type: "object", | |
properties: { | |
enforceForRenamedProperties: { | |
type: "boolean", | |
}, | |
enforceForDeclarationWithTypeAnnotation: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
fixable: "code", | |
hasSuggestions: undefined, | |
messages: { | |
preferDestructuring: "Use {{type}} destructuring.", | |
}, | |
}, | |
}, | |
"prefer-enum-initializers": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require each enum member value to be explicitly initialized", | |
url: "https://typescript-eslint.io/rules/prefer-enum-initializers", | |
}, | |
hasSuggestions: true, | |
messages: { | |
defineInitializer: "The value of the member '{{ name }}' should be explicitly defined.", | |
defineInitializerSuggestion: "Can be fixed to {{ name }} = {{ suggested }}", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-find": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-find", | |
}, | |
messages: { | |
preferFind: "Prefer .find(...) instead of .filter(...)[0].", | |
preferFindSuggestion: "Use .find(...) instead of .filter(...)[0].", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
hasSuggestions: true, | |
}, | |
}, | |
"prefer-for-of": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce the use of `for-of` loop over the standard `for` loop where possible", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/prefer-for-of", | |
}, | |
messages: { | |
preferForOf: "Expected a `for-of` loop instead of a `for` loop with this simple iteration.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-function-type": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
docs: { | |
description: "Enforce using function types instead of interfaces with call signatures", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/prefer-function-type", | |
}, | |
fixable: "code", | |
messages: { | |
functionTypeOverCallableType: "{{ literalOrInterface }} only has a call signature, you should use a function type instead.", | |
unexpectedThisOnFunctionOnlyInterface: "`this` refers to the function type '{{ interfaceName }}', did you intend to use a generic `this` parameter like `<Self>(this: Self, ...) => Self` instead?", | |
}, | |
schema: [ | |
], | |
type: "suggestion", | |
}, | |
}, | |
"prefer-includes": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce `includes` method over `indexOf` method", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-includes", | |
}, | |
fixable: "code", | |
messages: { | |
preferIncludes: "Use 'includes()' method instead.", | |
preferStringIncludes: "Use `String#includes()` method with a string instead.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-literal-enum-member": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowBitwiseExpressions: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require all enum members to be literal values", | |
recommended: "strict", | |
requiresTypeChecking: false, | |
url: "https://typescript-eslint.io/rules/prefer-literal-enum-member", | |
}, | |
messages: { | |
notLiteral: "Explicit enum value must only be a literal value (string, number, boolean, etc).", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowBitwiseExpressions: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"prefer-namespace-keyword": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules", | |
recommended: "stylistic", | |
url: "https://typescript-eslint.io/rules/prefer-namespace-keyword", | |
}, | |
fixable: "code", | |
messages: { | |
useNamespace: "Use 'namespace' instead of 'module' to declare custom TypeScript modules.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-nullish-coalescing": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false, | |
ignoreConditionalTests: false, | |
ignoreTernaryTests: false, | |
ignoreMixedLogicalExpressions: false, | |
ignorePrimitives: { | |
bigint: false, | |
boolean: false, | |
number: false, | |
string: false, | |
}, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce using the nullish coalescing operator instead of logical assignments or chaining", | |
recommended: "stylistic", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-nullish-coalescing", | |
}, | |
hasSuggestions: true, | |
messages: { | |
preferNullishOverOr: "Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.", | |
preferNullishOverTernary: "Prefer using nullish coalescing operator (`??`) instead of a ternary expression, as it is simpler to read.", | |
suggestNullish: "Fix to nullish coalescing operator (`??`).", | |
noStrictNullCheck: "This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: { | |
type: "boolean", | |
}, | |
ignoreConditionalTests: { | |
type: "boolean", | |
}, | |
ignoreMixedLogicalExpressions: { | |
type: "boolean", | |
}, | |
ignorePrimitives: { | |
oneOf: [ | |
{ | |
type: "object", | |
properties: { | |
bigint: { | |
type: "boolean", | |
}, | |
boolean: { | |
type: "boolean", | |
}, | |
number: { | |
type: "boolean", | |
}, | |
string: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
{ | |
type: "boolean", | |
enum: [ | |
true, | |
], | |
}, | |
], | |
}, | |
ignoreTernaryTests: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
}, | |
}, | |
"prefer-optional-chain": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
checkAny: true, | |
checkUnknown: true, | |
checkString: true, | |
checkNumber: true, | |
checkBoolean: true, | |
checkBigInt: true, | |
requireNullish: false, | |
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects", | |
recommended: "stylistic", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-optional-chain", | |
}, | |
fixable: "code", | |
hasSuggestions: true, | |
messages: { | |
preferOptionalChain: "Prefer using an optional chain expression instead, as it's more concise and easier to read.", | |
optionalChainSuggest: "Change to an optional chain.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
checkAny: { | |
type: "boolean", | |
description: "Check operands that are typed as `any` when inspecting \"loose boolean\" operands.", | |
}, | |
checkUnknown: { | |
type: "boolean", | |
description: "Check operands that are typed as `unknown` when inspecting \"loose boolean\" operands.", | |
}, | |
checkString: { | |
type: "boolean", | |
description: "Check operands that are typed as `string` when inspecting \"loose boolean\" operands.", | |
}, | |
checkNumber: { | |
type: "boolean", | |
description: "Check operands that are typed as `number` when inspecting \"loose boolean\" operands.", | |
}, | |
checkBoolean: { | |
type: "boolean", | |
description: "Check operands that are typed as `boolean` when inspecting \"loose boolean\" operands.", | |
}, | |
checkBigInt: { | |
type: "boolean", | |
description: "Check operands that are typed as `bigint` when inspecting \"loose boolean\" operands.", | |
}, | |
requireNullish: { | |
type: "boolean", | |
description: "Skip operands that are not typed with `null` and/or `undefined` when inspecting \"loose boolean\" operands.", | |
}, | |
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: { | |
type: "boolean", | |
description: "Allow autofixers that will change the return type of the expression. This option is considered unsafe as it may break the build.", | |
}, | |
}, | |
}, | |
], | |
}, | |
}, | |
"prefer-promise-reject-errors": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowEmptyReject: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require using Error objects as Promise rejection reasons", | |
recommended: "strict", | |
extendsBaseRule: true, | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-promise-reject-errors", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowEmptyReject: { | |
type: "boolean", | |
}, | |
}, | |
additionalProperties: false, | |
}, | |
], | |
messages: { | |
rejectAnError: "Expected the Promise rejection reason to be an Error.", | |
}, | |
}, | |
}, | |
"prefer-readonly": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
onlyInlineLambdas: false, | |
}, | |
], | |
meta: { | |
docs: { | |
description: "Require private members to be marked as `readonly` if they're never modified outside of the constructor", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-readonly", | |
}, | |
fixable: "code", | |
messages: { | |
preferReadonly: "Member '{{name}}' is never reassigned; mark it as `readonly`.", | |
}, | |
schema: [ | |
{ | |
additionalProperties: false, | |
properties: { | |
onlyInlineLambdas: { | |
type: "boolean", | |
}, | |
}, | |
type: "object", | |
}, | |
], | |
type: "suggestion", | |
}, | |
}, | |
"prefer-readonly-parameter-types": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allow: [ | |
], | |
checkParameterProperties: true, | |
ignoreInferredTypes: false, | |
treatMethodsAsReadonly: false, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-readonly-parameter-types", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
allow: { | |
type: "array", | |
items: { | |
oneOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
from: { | |
type: "string", | |
enum: [ | |
"file", | |
], | |
}, | |
name: { | |
oneOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
minItems: 1, | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
], | |
}, | |
path: { | |
type: "string", | |
}, | |
}, | |
required: [ | |
"from", | |
"name", | |
], | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
from: { | |
type: "string", | |
enum: [ | |
"lib", | |
], | |
}, | |
name: { | |
oneOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
minItems: 1, | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
], | |
}, | |
}, | |
required: [ | |
"from", | |
"name", | |
], | |
}, | |
{ | |
type: "object", | |
additionalProperties: false, | |
properties: { | |
from: { | |
type: "string", | |
enum: [ | |
"package", | |
], | |
}, | |
name: { | |
oneOf: [ | |
{ | |
type: "string", | |
}, | |
{ | |
type: "array", | |
minItems: 1, | |
uniqueItems: true, | |
items: { | |
type: "string", | |
}, | |
}, | |
], | |
}, | |
package: { | |
type: "string", | |
}, | |
}, | |
required: [ | |
"from", | |
"name", | |
"package", | |
], | |
}, | |
], | |
}, | |
}, | |
checkParameterProperties: { | |
type: "boolean", | |
}, | |
ignoreInferredTypes: { | |
type: "boolean", | |
}, | |
treatMethodsAsReadonly: { | |
type: "boolean", | |
}, | |
}, | |
}, | |
], | |
messages: { | |
shouldBeReadonly: "Parameter should be a read only type.", | |
}, | |
}, | |
}, | |
"prefer-reduce-type-parameter": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Enforce using type parameter when calling `Array#reduce` instead of casting", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-reduce-type-parameter", | |
}, | |
messages: { | |
preferTypeParameter: "Unnecessary cast: Array#reduce accepts a type parameter for the default value.", | |
}, | |
fixable: "code", | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-regexp-exec": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
fixable: "code", | |
docs: { | |
description: "Enforce `RegExp#exec` over `String#match` if no global flag is provided", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-regexp-exec", | |
}, | |
messages: { | |
regExpExecOverStringMatch: "Use the `RegExp#exec()` method instead.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"prefer-return-this-type": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce that `this` is used when only `this` type is returned", | |
recommended: "strict", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-return-this-type", | |
}, | |
messages: { | |
useThisType: "Use `this` type instead.", | |
}, | |
schema: [ | |
], | |
fixable: "code", | |
}, | |
}, | |
"prefer-string-starts-ends-with": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowSingleElementEquality: "never", | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
docs: { | |
description: "Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings", | |
recommended: "stylistic", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/prefer-string-starts-ends-with", | |
}, | |
messages: { | |
preferStartsWith: "Use 'String#startsWith' method instead.", | |
preferEndsWith: "Use the 'String#endsWith' method instead.", | |
}, | |
schema: [ | |
{ | |
additionalProperties: false, | |
properties: { | |
allowSingleElementEquality: { | |
description: "Whether to allow equality checks against the first or last element of a string.", | |
enum: [ | |
"always", | |
"never", | |
], | |
type: "string", | |
}, | |
}, | |
type: "object", | |
}, | |
], | |
fixable: "code", | |
}, | |
}, | |
"prefer-ts-expect-error": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
], | |
meta: { | |
type: "problem", | |
docs: { | |
description: "Enforce using `@ts-expect-error` over `@ts-ignore`", | |
recommended: "strict", | |
url: "https://typescript-eslint.io/rules/prefer-ts-expect-error", | |
}, | |
fixable: "code", | |
messages: { | |
preferExpectErrorComment: "Use \"@ts-expect-error\" to ensure an error is actually being suppressed.", | |
}, | |
schema: [ | |
], | |
}, | |
}, | |
"promise-function-async": { | |
create: function(context) { | |
const optionsWithDefault = (0, applyDefault_1.applyDefault)(defaultOptions, context.options); | |
return create(context, optionsWithDefault); | |
}, | |
defaultOptions: [ | |
{ | |
allowAny: true, | |
allowedPromiseNames: [ | |
], | |
checkArrowFunctions: true, | |
checkFunctionDeclarations: true, | |
checkFunctionExpressions: true, | |
checkMethodDeclarations: true, | |
}, | |
], | |
meta: { | |
type: "suggestion", | |
fixable: "code", | |
docs: { | |
description: "Require any function or method that returns a Promise to be marked async", | |
requiresTypeChecking: true, | |
url: "https://typescript-eslint.io/rules/promise-function-async", | |
}, | |
messages: { | |
missingAsync: "Functions that return promises must be async.", | |
}, | |
schema: [ | |
{ | |
type: "object", | |
properties: { | |
allowAny: { | |
description: "Whether to consider `any` and `unknown` to be Promises.", | |
type: "boolean", | |
}, | |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment