oxlint-plugin-eslint 1.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +36 -0
- package/common/ast-utils.cjs +5843 -0
- package/common/chunk.cjs +9 -0
- package/common/eslint-utils.cjs +1633 -0
- package/common/fix-tracker.cjs +89 -0
- package/common/ignore.cjs +123 -0
- package/common/keywords.cjs +15 -0
- package/common/regexpp.cjs +1720 -0
- package/common/regular-expressions.cjs +40 -0
- package/common/string-utils.cjs +39 -0
- package/index.js +7477 -0
- package/package.json +34 -0
- package/rules/accessor-pairs.cjs +233 -0
- package/rules/array-bracket-newline.cjs +172 -0
- package/rules/array-bracket-spacing.cjs +184 -0
- package/rules/array-callback-return.cjs +262 -0
- package/rules/array-element-newline.cjs +178 -0
- package/rules/arrow-body-style.cjs +135 -0
- package/rules/arrow-parens.cjs +130 -0
- package/rules/arrow-spacing.cjs +129 -0
- package/rules/block-scoped-var.cjs +101 -0
- package/rules/block-spacing.cjs +125 -0
- package/rules/brace-style.cjs +141 -0
- package/rules/callback-return.cjs +117 -0
- package/rules/camelcase.cjs +194 -0
- package/rules/capitalized-comments.cjs +168 -0
- package/rules/class-methods-use-this.cjs +155 -0
- package/rules/comma-dangle.cjs +274 -0
- package/rules/comma-spacing.cjs +111 -0
- package/rules/comma-style.cjs +180 -0
- package/rules/complexity.cjs +100 -0
- package/rules/computed-property-spacing.cjs +155 -0
- package/rules/consistent-return.cjs +113 -0
- package/rules/consistent-this.cjs +109 -0
- package/rules/constructor-super.cjs +207 -0
- package/rules/curly.cjs +173 -0
- package/rules/default-case-last.cjs +36 -0
- package/rules/default-case.cjs +50 -0
- package/rules/default-param-last.cjs +61 -0
- package/rules/dot-location.cjs +87 -0
- package/rules/dot-notation.cjs +77 -0
- package/rules/eol-last.cjs +91 -0
- package/rules/eqeqeq.cjs +127 -0
- package/rules/for-direction.cjs +94 -0
- package/rules/func-call-spacing.cjs +127 -0
- package/rules/func-name-matching.cjs +138 -0
- package/rules/func-names.cjs +121 -0
- package/rules/func-style.cjs +103 -0
- package/rules/function-call-argument-newline.cjs +109 -0
- package/rules/function-paren-newline.cjs +173 -0
- package/rules/generator-star-spacing.cjs +174 -0
- package/rules/getter-return.cjs +129 -0
- package/rules/global-require.cjs +84 -0
- package/rules/grouped-accessor-pairs.cjs +146 -0
- package/rules/guard-for-in.cjs +39 -0
- package/rules/handle-callback-err.cjs +86 -0
- package/rules/id-blacklist.cjs +135 -0
- package/rules/id-denylist.cjs +126 -0
- package/rules/id-length.cjs +119 -0
- package/rules/id-match.cjs +139 -0
- package/rules/implicit-arrow-linebreak.cjs +76 -0
- package/rules/indent-legacy.cjs +520 -0
- package/rules/indent.cjs +842 -0
- package/rules/init-declarations.cjs +88 -0
- package/rules/jsx-quotes.cjs +84 -0
- package/rules/key-spacing.cjs +399 -0
- package/rules/keyword-spacing.cjs +464 -0
- package/rules/line-comment-position.cjs +75 -0
- package/rules/linebreak-style.cjs +89 -0
- package/rules/lines-around-comment.cjs +290 -0
- package/rules/lines-around-directive.cjs +129 -0
- package/rules/lines-between-class-members.cjs +212 -0
- package/rules/logical-assignment-operators.cjs +305 -0
- package/rules/max-classes-per-file.cjs +61 -0
- package/rules/max-depth.cjs +117 -0
- package/rules/max-len.cjs +256 -0
- package/rules/max-lines-per-function.cjs +116 -0
- package/rules/max-lines.cjs +109 -0
- package/rules/max-nested-callbacks.cjs +78 -0
- package/rules/max-params.cjs +78 -0
- package/rules/max-statements-per-line.cjs +147 -0
- package/rules/max-statements.cjs +119 -0
- package/rules/multiline-comment-style.cjs +319 -0
- package/rules/multiline-ternary.cjs +106 -0
- package/rules/new-cap.cjs +139 -0
- package/rules/new-parens.cjs +70 -0
- package/rules/newline-after-var.cjs +159 -0
- package/rules/newline-before-return.cjs +128 -0
- package/rules/newline-per-chained-call.cjs +100 -0
- package/rules/no-alert.cjs +84 -0
- package/rules/no-array-constructor.cjs +91 -0
- package/rules/no-async-promise-executor.cjs +33 -0
- package/rules/no-await-in-loop.cjs +75 -0
- package/rules/no-bitwise.cjs +106 -0
- package/rules/no-buffer-constructor.cjs +51 -0
- package/rules/no-caller.cjs +34 -0
- package/rules/no-case-declarations.cjs +56 -0
- package/rules/no-catch-shadow.cjs +57 -0
- package/rules/no-class-assign.cjs +55 -0
- package/rules/no-compare-neg-zero.cjs +52 -0
- package/rules/no-cond-assign.cjs +104 -0
- package/rules/no-confusing-arrow.cjs +87 -0
- package/rules/no-console.cjs +138 -0
- package/rules/no-const-assign.cjs +50 -0
- package/rules/no-constant-binary-expression.cjs +284 -0
- package/rules/no-constant-condition.cjs +119 -0
- package/rules/no-constructor-return.cjs +43 -0
- package/rules/no-continue.cjs +33 -0
- package/rules/no-control-regex.cjs +74 -0
- package/rules/no-debugger.cjs +33 -0
- package/rules/no-delete-var.cjs +32 -0
- package/rules/no-div-regex.cjs +39 -0
- package/rules/no-dupe-args.cjs +61 -0
- package/rules/no-dupe-class-members.cjs +77 -0
- package/rules/no-dupe-else-if.cjs +74 -0
- package/rules/no-dupe-keys.cjs +88 -0
- package/rules/no-duplicate-case.cjs +49 -0
- package/rules/no-duplicate-imports.cjs +166 -0
- package/rules/no-else-return.cjs +182 -0
- package/rules/no-empty-character-class.cjs +47 -0
- package/rules/no-empty-function.cjs +141 -0
- package/rules/no-empty-pattern.cjs +50 -0
- package/rules/no-empty-static-block.cjs +50 -0
- package/rules/no-empty.cjs +78 -0
- package/rules/no-eq-null.cjs +34 -0
- package/rules/no-eval.cjs +165 -0
- package/rules/no-ex-assign.cjs +45 -0
- package/rules/no-extend-native.cjs +103 -0
- package/rules/no-extra-bind.cjs +127 -0
- package/rules/no-extra-boolean-cast.cjs +159 -0
- package/rules/no-extra-label.cjs +116 -0
- package/rules/no-extra-parens.cjs +665 -0
- package/rules/no-extra-semi.cjs +103 -0
- package/rules/no-fallthrough.cjs +136 -0
- package/rules/no-floating-decimal.cjs +66 -0
- package/rules/no-func-assign.cjs +63 -0
- package/rules/no-global-assign.cjs +62 -0
- package/rules/no-implicit-coercion.cjs +219 -0
- package/rules/no-implicit-globals.cjs +77 -0
- package/rules/no-implied-eval.cjs +87 -0
- package/rules/no-import-assign.cjs +123 -0
- package/rules/no-inline-comments.cjs +57 -0
- package/rules/no-inner-declarations.cjs +82 -0
- package/rules/no-invalid-regexp.cjs +130 -0
- package/rules/no-invalid-this.cjs +90 -0
- package/rules/no-irregular-whitespace.cjs +157 -0
- package/rules/no-iterator.cjs +34 -0
- package/rules/no-label-var.cjs +46 -0
- package/rules/no-labels.cjs +106 -0
- package/rules/no-lone-blocks.cjs +75 -0
- package/rules/no-lonely-if.cjs +42 -0
- package/rules/no-loop-func.cjs +143 -0
- package/rules/no-loss-of-precision.cjs +160 -0
- package/rules/no-magic-numbers.cjs +222 -0
- package/rules/no-misleading-character-class.cjs +500 -0
- package/rules/no-mixed-operators.cjs +197 -0
- package/rules/no-mixed-requires.cjs +117 -0
- package/rules/no-mixed-spaces-and-tabs.cjs +87 -0
- package/rules/no-multi-assign.cjs +38 -0
- package/rules/no-multi-spaces.cjs +95 -0
- package/rules/no-multi-str.cjs +44 -0
- package/rules/no-multiple-empty-lines.cjs +112 -0
- package/rules/no-native-reassign.cjs +72 -0
- package/rules/no-negated-condition.cjs +77 -0
- package/rules/no-negated-in-lhs.cjs +43 -0
- package/rules/no-nested-ternary.cjs +33 -0
- package/rules/no-new-func.cjs +50 -0
- package/rules/no-new-native-nonconstructor.cjs +42 -0
- package/rules/no-new-object.cjs +47 -0
- package/rules/no-new-require.cjs +50 -0
- package/rules/no-new-symbol.cjs +48 -0
- package/rules/no-new-wrappers.cjs +44 -0
- package/rules/no-new.cjs +33 -0
- package/rules/no-nonoctal-decimal-escape.cjs +80 -0
- package/rules/no-obj-calls.cjs +64 -0
- package/rules/no-object-constructor.cjs +69 -0
- package/rules/no-octal-escape.cjs +35 -0
- package/rules/no-octal.cjs +32 -0
- package/rules/no-param-reassign.cjs +135 -0
- package/rules/no-path-concat.cjs +52 -0
- package/rules/no-plusplus.cjs +64 -0
- package/rules/no-process-env.cjs +51 -0
- package/rules/no-process-exit.cjs +50 -0
- package/rules/no-promise-executor-return.cjs +131 -0
- package/rules/no-proto.cjs +34 -0
- package/rules/no-prototype-builtins.cjs +85 -0
- package/rules/no-redeclare.cjs +103 -0
- package/rules/no-regex-spaces.cjs +115 -0
- package/rules/no-restricted-exports.cjs +117 -0
- package/rules/no-restricted-globals.cjs +147 -0
- package/rules/no-restricted-imports.cjs +421 -0
- package/rules/no-restricted-modules.cjs +144 -0
- package/rules/no-restricted-properties.cjs +123 -0
- package/rules/no-restricted-syntax.cjs +49 -0
- package/rules/no-return-assign.cjs +45 -0
- package/rules/no-return-await.cjs +88 -0
- package/rules/no-script-url.cjs +49 -0
- package/rules/no-self-assign.cjs +88 -0
- package/rules/no-self-compare.cjs +53 -0
- package/rules/no-sequences.cjs +81 -0
- package/rules/no-setter-return.cjs +110 -0
- package/rules/no-shadow-restricted-names.cjs +60 -0
- package/rules/no-shadow.cjs +302 -0
- package/rules/no-spaced-func.cjs +69 -0
- package/rules/no-sparse-arrays.cjs +40 -0
- package/rules/no-sync.cjs +58 -0
- package/rules/no-tabs.cjs +73 -0
- package/rules/no-template-curly-in-string.cjs +33 -0
- package/rules/no-ternary.cjs +33 -0
- package/rules/no-this-before-super.cjs +177 -0
- package/rules/no-throw-literal.cjs +40 -0
- package/rules/no-trailing-spaces.cjs +123 -0
- package/rules/no-unassigned-vars.cjs +54 -0
- package/rules/no-undef-init.cjs +46 -0
- package/rules/no-undef.cjs +51 -0
- package/rules/no-undefined.cjs +58 -0
- package/rules/no-underscore-dangle.cjs +211 -0
- package/rules/no-unexpected-multiline.cjs +76 -0
- package/rules/no-unmodified-loop-condition.cjs +849 -0
- package/rules/no-unneeded-ternary.cjs +112 -0
- package/rules/no-unreachable-loop.cjs +128 -0
- package/rules/no-unreachable.cjs +195 -0
- package/rules/no-unsafe-finally.cjs +67 -0
- package/rules/no-unsafe-negation.cjs +86 -0
- package/rules/no-unsafe-optional-chaining.cjs +164 -0
- package/rules/no-unused-expressions.cjs +163 -0
- package/rules/no-unused-labels.cjs +97 -0
- package/rules/no-unused-private-class-members.cjs +69 -0
- package/rules/no-unused-vars.cjs +639 -0
- package/rules/no-use-before-define.cjs +245 -0
- package/rules/no-useless-assignment.cjs +250 -0
- package/rules/no-useless-backreference.cjs +137 -0
- package/rules/no-useless-call.cjs +57 -0
- package/rules/no-useless-catch.cjs +38 -0
- package/rules/no-useless-computed-key.cjs +106 -0
- package/rules/no-useless-concat.cjs +78 -0
- package/rules/no-useless-constructor.cjs +152 -0
- package/rules/no-useless-escape.cjs +164 -0
- package/rules/no-useless-rename.cjs +94 -0
- package/rules/no-useless-return.cjs +229 -0
- package/rules/no-var.cjs +235 -0
- package/rules/no-void.cjs +39 -0
- package/rules/no-warning-comments.cjs +112 -0
- package/rules/no-whitespace-before-property.cjs +72 -0
- package/rules/no-with.cjs +32 -0
- package/rules/nonblock-statement-body-position.cjs +107 -0
- package/rules/object-curly-newline.cjs +194 -0
- package/rules/object-curly-spacing.cjs +225 -0
- package/rules/object-property-newline.cjs +81 -0
- package/rules/object-shorthand.cjs +284 -0
- package/rules/one-var-declaration-per-line.cjs +75 -0
- package/rules/one-var.cjs +378 -0
- package/rules/operator-assignment.cjs +146 -0
- package/rules/operator-linebreak.cjs +150 -0
- package/rules/padded-blocks.cjs +192 -0
- package/rules/padding-line-between-statements.cjs +377 -0
- package/rules/prefer-arrow-callback.cjs +185 -0
- package/rules/prefer-const.cjs +240 -0
- package/rules/prefer-destructuring.cjs +188 -0
- package/rules/prefer-exponentiation-operator.cjs +100 -0
- package/rules/prefer-named-capture-group.cjs +111 -0
- package/rules/prefer-numeric-literals.cjs +75 -0
- package/rules/prefer-object-has-own.cjs +54 -0
- package/rules/prefer-object-spread.cjs +170 -0
- package/rules/prefer-promise-reject-errors.cjs +62 -0
- package/rules/prefer-reflect.cjs +100 -0
- package/rules/prefer-regex-literals.cjs +256 -0
- package/rules/prefer-rest-params.cjs +80 -0
- package/rules/prefer-spread.cjs +57 -0
- package/rules/prefer-template.cjs +147 -0
- package/rules/preserve-caught-error.cjs +196 -0
- package/rules/quote-props.cjs +224 -0
- package/rules/quotes.cjs +187 -0
- package/rules/radix.cjs +124 -0
- package/rules/require-atomic-updates.cjs +197 -0
- package/rules/require-await.cjs +90 -0
- package/rules/require-unicode-regexp.cjs +101 -0
- package/rules/require-yield.cjs +56 -0
- package/rules/rest-spread-spacing.cjs +99 -0
- package/rules/semi-spacing.cjs +215 -0
- package/rules/semi-style.cjs +116 -0
- package/rules/semi.cjs +239 -0
- package/rules/sort-imports.cjs +140 -0
- package/rules/sort-keys.cjs +165 -0
- package/rules/sort-vars.cjs +50 -0
- package/rules/space-before-blocks.cjs +132 -0
- package/rules/space-before-function-paren.cjs +126 -0
- package/rules/space-in-parens.cjs +175 -0
- package/rules/space-infix-ops.cjs +133 -0
- package/rules/space-unary-ops.cjs +237 -0
- package/rules/spaced-comment.cjs +233 -0
- package/rules/strict.cjs +206 -0
- package/rules/switch-colon-spacing.cjs +114 -0
- package/rules/symbol-description.cjs +49 -0
- package/rules/template-curly-spacing.cjs +112 -0
- package/rules/template-tag-spacing.cjs +82 -0
- package/rules/unicode-bom.cjs +52 -0
- package/rules/use-isnan.cjs +144 -0
- package/rules/valid-typeof.cjs +104 -0
- package/rules/vars-on-top.cjs +94 -0
- package/rules/wrap-iife.cjs +131 -0
- package/rules/wrap-regex.cjs +57 -0
- package/rules/yield-star-spacing.cjs +115 -0
- package/rules/yoda.cjs +185 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/preserve-caught-error.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to preserve caught errors when re-throwing exceptions
|
|
5
|
+
* @author Amnish Singh Arora
|
|
6
|
+
*/
|
|
7
|
+
var require_preserve_caught_error = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
8
|
+
let astUtils = require_ast_utils$1.t(), UNKNOWN_CAUSE = Symbol("unknown_cause"), BUILT_IN_ERROR_TYPES = new Set([
|
|
9
|
+
"Error",
|
|
10
|
+
"EvalError",
|
|
11
|
+
"RangeError",
|
|
12
|
+
"ReferenceError",
|
|
13
|
+
"SyntaxError",
|
|
14
|
+
"TypeError",
|
|
15
|
+
"URIError",
|
|
16
|
+
"AggregateError"
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Finds and returns information about the `cause` property of an error being thrown.
|
|
20
|
+
* @param {ASTNode} throwStatement `ThrowStatement` to be checked.
|
|
21
|
+
* @returns {{ value: ASTNode; multipleDefinitions: boolean; } | UNKNOWN_CAUSE | null}
|
|
22
|
+
* Information about the `cause` of the error being thrown, such as the value node and
|
|
23
|
+
* whether there are multiple definitions of `cause`. `null` if there is no `cause`.
|
|
24
|
+
*/
|
|
25
|
+
function getErrorCause(throwStatement) {
|
|
26
|
+
let throwExpression = throwStatement.argument, optionsIndex = throwExpression.callee.name === "AggregateError" ? 2 : 1, spreadExpressionIndex = throwExpression.arguments.findIndex((arg) => arg.type === "SpreadElement");
|
|
27
|
+
if (spreadExpressionIndex >= 0 && spreadExpressionIndex <= optionsIndex) return UNKNOWN_CAUSE;
|
|
28
|
+
let errorOptions = throwExpression.arguments[optionsIndex];
|
|
29
|
+
if (errorOptions) {
|
|
30
|
+
if (errorOptions.type === "ObjectExpression") {
|
|
31
|
+
if (errorOptions.properties.some((prop) => prop.type === "SpreadElement")) return UNKNOWN_CAUSE;
|
|
32
|
+
let causeProperties = errorOptions.properties.filter((prop) => astUtils.getStaticPropertyName(prop) === "cause"), causeProperty = causeProperties.at(-1);
|
|
33
|
+
return causeProperty ? {
|
|
34
|
+
value: causeProperty.value,
|
|
35
|
+
multipleDefinitions: causeProperties.length > 1
|
|
36
|
+
} : null;
|
|
37
|
+
}
|
|
38
|
+
return UNKNOWN_CAUSE;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Finds and returns the `CatchClause` node, that the `node` is part of.
|
|
44
|
+
* @param {ASTNode} node The AST node to be evaluated.
|
|
45
|
+
* @returns {ASTNode | null } The closest parent `CatchClause` node, `null` if the `node` is not in a catch block.
|
|
46
|
+
*/
|
|
47
|
+
function findParentCatch(node) {
|
|
48
|
+
let currentNode = node;
|
|
49
|
+
for (; currentNode && currentNode.type !== "CatchClause";) {
|
|
50
|
+
if ([
|
|
51
|
+
"FunctionDeclaration",
|
|
52
|
+
"FunctionExpression",
|
|
53
|
+
"ArrowFunctionExpression",
|
|
54
|
+
"StaticBlock"
|
|
55
|
+
].includes(currentNode.type)) return null;
|
|
56
|
+
currentNode = currentNode.parent;
|
|
57
|
+
}
|
|
58
|
+
return currentNode;
|
|
59
|
+
}
|
|
60
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
61
|
+
module.exports = {
|
|
62
|
+
meta: {
|
|
63
|
+
type: "suggestion",
|
|
64
|
+
defaultOptions: [{ requireCatchParameter: !1 }],
|
|
65
|
+
docs: {
|
|
66
|
+
description: "Disallow losing originally caught error when re-throwing custom errors",
|
|
67
|
+
recommended: !1,
|
|
68
|
+
url: "https://eslint.org/docs/latest/rules/preserve-caught-error"
|
|
69
|
+
},
|
|
70
|
+
schema: [{
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: { requireCatchParameter: {
|
|
73
|
+
type: "boolean",
|
|
74
|
+
description: "Requires the catch blocks to always have the caught error parameter so it is not discarded."
|
|
75
|
+
} },
|
|
76
|
+
additionalProperties: !1
|
|
77
|
+
}],
|
|
78
|
+
messages: {
|
|
79
|
+
missingCause: "There is no `cause` attached to the symptom error being thrown.",
|
|
80
|
+
incorrectCause: "The symptom error is being thrown with an incorrect `cause`.",
|
|
81
|
+
includeCause: "Include the original caught error as the `cause` of the symptom error.",
|
|
82
|
+
missingCatchErrorParam: "The caught error is not accessible because the catch clause lacks the error parameter. Start referencing the caught error using the catch parameter.",
|
|
83
|
+
partiallyLostError: "Re-throws cannot preserve the caught error as a part of it is being lost due to destructuring.",
|
|
84
|
+
caughtErrorShadowed: "The caught error is being attached as `cause`, but is shadowed by a closer scoped redeclaration."
|
|
85
|
+
},
|
|
86
|
+
hasSuggestions: !0
|
|
87
|
+
},
|
|
88
|
+
create(context) {
|
|
89
|
+
let sourceCode = context.sourceCode, [{ requireCatchParameter }] = context.options;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a `ThrowStatement` is constructing and throwing a new `Error` object.
|
|
92
|
+
*
|
|
93
|
+
* Covers all the error types on `globalThis` that support `cause` property:
|
|
94
|
+
* https://github.com/microsoft/TypeScript/blob/main/src/lib/es2022.error.d.ts
|
|
95
|
+
* @param {ASTNode} throwStatement The `ThrowStatement` that needs to be checked.
|
|
96
|
+
* @returns {boolean} `true` if a new "Error" is being thrown, else `false`.
|
|
97
|
+
*/
|
|
98
|
+
function isThrowingNewError(throwStatement) {
|
|
99
|
+
return (throwStatement.argument.type === "NewExpression" || throwStatement.argument.type === "CallExpression") && throwStatement.argument.callee.type === "Identifier" && BUILT_IN_ERROR_TYPES.has(throwStatement.argument.callee.name) && sourceCode.isGlobalReference(throwStatement.argument.callee);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Inserts `cause: <caughtErrorName>` into an inline options object expression.
|
|
103
|
+
* @param {RuleFixer} fixer The fixer object.
|
|
104
|
+
* @param {ASTNode} optionsNode The options object node.
|
|
105
|
+
* @param {string} caughtErrorName The name of the caught error (e.g., "err").
|
|
106
|
+
* @returns {Fix} The fix object.
|
|
107
|
+
*/
|
|
108
|
+
function insertCauseIntoOptions(fixer, optionsNode, caughtErrorName) {
|
|
109
|
+
let properties = optionsNode.properties;
|
|
110
|
+
if (properties.length === 0) return fixer.insertTextAfter(sourceCode.getFirstToken(optionsNode), `cause: ${caughtErrorName}`);
|
|
111
|
+
let lastProp = properties.at(-1);
|
|
112
|
+
return fixer.insertTextAfter(lastProp, `, cause: ${caughtErrorName}`);
|
|
113
|
+
}
|
|
114
|
+
return { ThrowStatement(node) {
|
|
115
|
+
let parentCatch = findParentCatch(node), throwStatement = node;
|
|
116
|
+
if (parentCatch && isThrowingNewError(throwStatement)) {
|
|
117
|
+
if (parentCatch.param && parentCatch.param.type !== "Identifier") {
|
|
118
|
+
context.report({
|
|
119
|
+
messageId: "partiallyLostError",
|
|
120
|
+
node: parentCatch
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
let caughtError = parentCatch.param?.type === "Identifier" ? parentCatch.param : null;
|
|
125
|
+
if (!caughtError) {
|
|
126
|
+
if (requireCatchParameter) {
|
|
127
|
+
context.report({
|
|
128
|
+
node: throwStatement,
|
|
129
|
+
messageId: "missingCatchErrorParam"
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let errorCauseInfo = getErrorCause(throwStatement);
|
|
136
|
+
if (errorCauseInfo === UNKNOWN_CAUSE) return;
|
|
137
|
+
if (errorCauseInfo === null) {
|
|
138
|
+
context.report({
|
|
139
|
+
messageId: "missingCause",
|
|
140
|
+
node: throwStatement,
|
|
141
|
+
suggest: [{
|
|
142
|
+
messageId: "includeCause",
|
|
143
|
+
fix(fixer) {
|
|
144
|
+
let throwExpression = throwStatement.argument, args = throwExpression.arguments;
|
|
145
|
+
if (throwExpression.callee.name === "AggregateError") {
|
|
146
|
+
let errorsArg = args[0], messageArg = args[1], optionsArg = args[2];
|
|
147
|
+
if (!errorsArg) {
|
|
148
|
+
let lastToken = sourceCode.getLastToken(throwExpression), lastCalleeToken = sourceCode.getLastToken(throwExpression.callee), parenToken = sourceCode.getFirstTokenBetween(lastCalleeToken, lastToken, astUtils.isOpeningParenToken);
|
|
149
|
+
return parenToken ? fixer.insertTextAfter(parenToken, `[], "", { cause: ${caughtError.name} }`) : fixer.insertTextAfter(throwExpression.callee, `([], "", { cause: ${caughtError.name} })`);
|
|
150
|
+
}
|
|
151
|
+
return messageArg ? optionsArg ? optionsArg.type === "ObjectExpression" ? insertCauseIntoOptions(fixer, optionsArg, caughtError.name) : null : fixer.insertTextAfter(messageArg, `, { cause: ${caughtError.name} }`) : fixer.insertTextAfter(errorsArg, `, "", { cause: ${caughtError.name} }`);
|
|
152
|
+
}
|
|
153
|
+
let messageArg = args[0], optionsArg = args[1];
|
|
154
|
+
if (!messageArg) {
|
|
155
|
+
let lastToken = sourceCode.getLastToken(throwExpression), lastCalleeToken = sourceCode.getLastToken(throwExpression.callee), parenToken = sourceCode.getFirstTokenBetween(lastCalleeToken, lastToken, astUtils.isOpeningParenToken);
|
|
156
|
+
return parenToken ? fixer.insertTextAfter(parenToken, `"", { cause: ${caughtError.name} }`) : fixer.insertTextAfter(throwExpression.callee, `("", { cause: ${caughtError.name} })`);
|
|
157
|
+
}
|
|
158
|
+
return optionsArg ? optionsArg.type === "ObjectExpression" ? insertCauseIntoOptions(fixer, optionsArg, caughtError.name) : null : fixer.insertTextAfter(messageArg, `, { cause: ${caughtError.name} }`);
|
|
159
|
+
}
|
|
160
|
+
}]
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
let { value: thrownErrorCause } = errorCauseInfo;
|
|
165
|
+
if (!(thrownErrorCause.type === "Identifier" && thrownErrorCause.name === caughtError.name)) {
|
|
166
|
+
let suggest = errorCauseInfo.multipleDefinitions ? null : [{
|
|
167
|
+
messageId: "includeCause",
|
|
168
|
+
fix(fixer) {
|
|
169
|
+
return thrownErrorCause.parent.method || thrownErrorCause.parent.shorthand || thrownErrorCause.parent.kind !== "init" ? fixer.replaceText(thrownErrorCause.parent, `cause: ${caughtError.name}`) : fixer.replaceText(thrownErrorCause, caughtError.name);
|
|
170
|
+
}
|
|
171
|
+
}];
|
|
172
|
+
context.report({
|
|
173
|
+
messageId: "incorrectCause",
|
|
174
|
+
node: thrownErrorCause,
|
|
175
|
+
suggest
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
let scope = sourceCode.getScope(throwStatement);
|
|
180
|
+
do {
|
|
181
|
+
if (scope.set.get(caughtError.name)) break;
|
|
182
|
+
scope = scope.upper;
|
|
183
|
+
} while (scope);
|
|
184
|
+
scope?.block !== parentCatch && context.report({
|
|
185
|
+
messageId: "caughtErrorShadowed",
|
|
186
|
+
node: throwStatement
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}));
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src-js/generated/plugin-eslint/rules/preserve-caught-error.cjs
|
|
195
|
+
module.exports = require_preserve_caught_error().create;
|
|
196
|
+
//#endregion
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs"), require_keywords$1 = require("../common/keywords.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/quote-props.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Rule to flag non-quoted property names in object literals.
|
|
5
|
+
* @author Mathias Bynens <http://mathiasbynens.be/>
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_quote_props = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let espree = require_ast_utils$1.r(), astUtils = require_ast_utils$1.t(), keywords = require_keywords$1.t();
|
|
10
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
deprecated: {
|
|
14
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
15
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
16
|
+
deprecatedSince: "8.53.0",
|
|
17
|
+
availableUntil: "11.0.0",
|
|
18
|
+
replacedBy: [{
|
|
19
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
20
|
+
url: "https://eslint.style/guide/migration",
|
|
21
|
+
plugin: {
|
|
22
|
+
name: "@stylistic/eslint-plugin",
|
|
23
|
+
url: "https://eslint.style"
|
|
24
|
+
},
|
|
25
|
+
rule: {
|
|
26
|
+
name: "quote-props",
|
|
27
|
+
url: "https://eslint.style/rules/quote-props"
|
|
28
|
+
}
|
|
29
|
+
}]
|
|
30
|
+
},
|
|
31
|
+
type: "suggestion",
|
|
32
|
+
docs: {
|
|
33
|
+
description: "Require quotes around object literal property names",
|
|
34
|
+
recommended: !1,
|
|
35
|
+
url: "https://eslint.org/docs/latest/rules/quote-props"
|
|
36
|
+
},
|
|
37
|
+
schema: { anyOf: [{
|
|
38
|
+
type: "array",
|
|
39
|
+
items: [{ enum: [
|
|
40
|
+
"always",
|
|
41
|
+
"as-needed",
|
|
42
|
+
"consistent",
|
|
43
|
+
"consistent-as-needed"
|
|
44
|
+
] }],
|
|
45
|
+
minItems: 0,
|
|
46
|
+
maxItems: 1
|
|
47
|
+
}, {
|
|
48
|
+
type: "array",
|
|
49
|
+
items: [{ enum: [
|
|
50
|
+
"always",
|
|
51
|
+
"as-needed",
|
|
52
|
+
"consistent",
|
|
53
|
+
"consistent-as-needed"
|
|
54
|
+
] }, {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
keywords: { type: "boolean" },
|
|
58
|
+
unnecessary: { type: "boolean" },
|
|
59
|
+
numbers: { type: "boolean" }
|
|
60
|
+
},
|
|
61
|
+
additionalProperties: !1
|
|
62
|
+
}],
|
|
63
|
+
minItems: 0,
|
|
64
|
+
maxItems: 2
|
|
65
|
+
}] },
|
|
66
|
+
fixable: "code",
|
|
67
|
+
messages: {
|
|
68
|
+
requireQuotesDueToReservedWord: "Properties should be quoted as '{{property}}' is a reserved word.",
|
|
69
|
+
inconsistentlyQuotedProperty: "Inconsistently quoted property '{{key}}' found.",
|
|
70
|
+
unnecessarilyQuotedProperty: "Unnecessarily quoted property '{{property}}' found.",
|
|
71
|
+
unquotedReservedProperty: "Unquoted reserved word '{{property}}' used as key.",
|
|
72
|
+
unquotedNumericProperty: "Unquoted number literal '{{property}}' used as key.",
|
|
73
|
+
unquotedPropertyFound: "Unquoted property '{{property}}' found.",
|
|
74
|
+
redundantQuoting: "Properties shouldn't be quoted as all quotes are redundant."
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
create(context) {
|
|
78
|
+
let MODE = context.options[0], KEYWORDS = context.options[1] && context.options[1].keywords, CHECK_UNNECESSARY = !context.options[1] || context.options[1].unnecessary !== !1, NUMBERS = context.options[1] && context.options[1].numbers, sourceCode = context.sourceCode;
|
|
79
|
+
/**
|
|
80
|
+
* Checks whether a certain string constitutes an ES3 token
|
|
81
|
+
* @param {string} tokenStr The string to be checked.
|
|
82
|
+
* @returns {boolean} `true` if it is an ES3 token.
|
|
83
|
+
*/
|
|
84
|
+
function isKeyword(tokenStr) {
|
|
85
|
+
return keywords.includes(tokenStr);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if an espree-tokenized key has redundant quotes (i.e. whether quotes are unnecessary)
|
|
89
|
+
* @param {string} rawKey The raw key value from the source
|
|
90
|
+
* @param {espreeTokens} tokens The espree-tokenized node key
|
|
91
|
+
* @param {boolean} [skipNumberLiterals=false] Indicates whether number literals should be checked
|
|
92
|
+
* @returns {boolean} Whether or not a key has redundant quotes.
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
function areQuotesRedundant(rawKey, tokens, skipNumberLiterals) {
|
|
96
|
+
return tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === rawKey.length && ([
|
|
97
|
+
"Identifier",
|
|
98
|
+
"Keyword",
|
|
99
|
+
"Null",
|
|
100
|
+
"Boolean"
|
|
101
|
+
].includes(tokens[0].type) || tokens[0].type === "Numeric" && !skipNumberLiterals && String(+tokens[0].value) === tokens[0].value);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns a string representation of a property node with quotes removed
|
|
105
|
+
* @param {ASTNode} key Key AST Node, which may or may not be quoted
|
|
106
|
+
* @returns {string} A replacement string for this property
|
|
107
|
+
*/
|
|
108
|
+
function getUnquotedKey(key) {
|
|
109
|
+
return key.type === "Identifier" ? key.name : key.value;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns a string representation of a property node with quotes added
|
|
113
|
+
* @param {ASTNode} key Key AST Node, which may or may not be quoted
|
|
114
|
+
* @returns {string} A replacement string for this property
|
|
115
|
+
*/
|
|
116
|
+
function getQuotedKey(key) {
|
|
117
|
+
return key.type === "Literal" && typeof key.value == "string" ? sourceCode.getText(key) : `"${key.type === "Identifier" ? key.name : key.value}"`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Ensures that a property's key is quoted only when necessary
|
|
121
|
+
* @param {ASTNode} node Property AST node
|
|
122
|
+
* @returns {void}
|
|
123
|
+
*/
|
|
124
|
+
function checkUnnecessaryQuotes(node) {
|
|
125
|
+
let key = node.key;
|
|
126
|
+
if (!(node.method || node.computed || node.shorthand)) if (key.type === "Literal" && typeof key.value == "string") {
|
|
127
|
+
let tokens;
|
|
128
|
+
try {
|
|
129
|
+
tokens = espree.tokenize(key.value);
|
|
130
|
+
} catch {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (tokens.length !== 1 || isKeyword(tokens[0].value) && KEYWORDS) return;
|
|
134
|
+
CHECK_UNNECESSARY && areQuotesRedundant(key.value, tokens, NUMBERS) && context.report({
|
|
135
|
+
node,
|
|
136
|
+
messageId: "unnecessarilyQuotedProperty",
|
|
137
|
+
data: { property: key.value },
|
|
138
|
+
fix: (fixer) => fixer.replaceText(key, getUnquotedKey(key))
|
|
139
|
+
});
|
|
140
|
+
} else KEYWORDS && key.type === "Identifier" && isKeyword(key.name) ? context.report({
|
|
141
|
+
node,
|
|
142
|
+
messageId: "unquotedReservedProperty",
|
|
143
|
+
data: { property: key.name },
|
|
144
|
+
fix: (fixer) => fixer.replaceText(key, getQuotedKey(key))
|
|
145
|
+
}) : NUMBERS && key.type === "Literal" && astUtils.isNumericLiteral(key) && context.report({
|
|
146
|
+
node,
|
|
147
|
+
messageId: "unquotedNumericProperty",
|
|
148
|
+
data: { property: key.value },
|
|
149
|
+
fix: (fixer) => fixer.replaceText(key, getQuotedKey(key))
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Ensures that a property's key is quoted
|
|
154
|
+
* @param {ASTNode} node Property AST node
|
|
155
|
+
* @returns {void}
|
|
156
|
+
*/
|
|
157
|
+
function checkOmittedQuotes(node) {
|
|
158
|
+
let key = node.key;
|
|
159
|
+
!node.method && !node.computed && !node.shorthand && !(key.type === "Literal" && typeof key.value == "string") && context.report({
|
|
160
|
+
node,
|
|
161
|
+
messageId: "unquotedPropertyFound",
|
|
162
|
+
data: { property: key.name || key.value },
|
|
163
|
+
fix: (fixer) => fixer.replaceText(key, getQuotedKey(key))
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Ensures that an object's keys are consistently quoted, optionally checks for redundancy of quotes
|
|
168
|
+
* @param {ASTNode} node Property AST node
|
|
169
|
+
* @param {boolean} checkQuotesRedundancy Whether to check quotes' redundancy
|
|
170
|
+
* @returns {void}
|
|
171
|
+
*/
|
|
172
|
+
function checkConsistency(node, checkQuotesRedundancy) {
|
|
173
|
+
let quotedProps = [], unquotedProps = [], keywordKeyName = null, necessaryQuotes = !1;
|
|
174
|
+
node.properties.forEach((property) => {
|
|
175
|
+
let key = property.key;
|
|
176
|
+
if (!(!key || property.method || property.computed || property.shorthand)) if (key.type === "Literal" && typeof key.value == "string") {
|
|
177
|
+
if (quotedProps.push(property), checkQuotesRedundancy) {
|
|
178
|
+
let tokens;
|
|
179
|
+
try {
|
|
180
|
+
tokens = espree.tokenize(key.value);
|
|
181
|
+
} catch {
|
|
182
|
+
necessaryQuotes = !0;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
necessaryQuotes = necessaryQuotes || !areQuotesRedundant(key.value, tokens) || KEYWORDS && isKeyword(tokens[0].value);
|
|
186
|
+
}
|
|
187
|
+
} else KEYWORDS && checkQuotesRedundancy && key.type === "Identifier" && isKeyword(key.name) ? (unquotedProps.push(property), necessaryQuotes = !0, keywordKeyName = key.name) : unquotedProps.push(property);
|
|
188
|
+
}), checkQuotesRedundancy && quotedProps.length && !necessaryQuotes ? quotedProps.forEach((property) => {
|
|
189
|
+
context.report({
|
|
190
|
+
node: property,
|
|
191
|
+
messageId: "redundantQuoting",
|
|
192
|
+
fix: (fixer) => fixer.replaceText(property.key, getUnquotedKey(property.key))
|
|
193
|
+
});
|
|
194
|
+
}) : unquotedProps.length && keywordKeyName ? unquotedProps.forEach((property) => {
|
|
195
|
+
context.report({
|
|
196
|
+
node: property,
|
|
197
|
+
messageId: "requireQuotesDueToReservedWord",
|
|
198
|
+
data: { property: keywordKeyName },
|
|
199
|
+
fix: (fixer) => fixer.replaceText(property.key, getQuotedKey(property.key))
|
|
200
|
+
});
|
|
201
|
+
}) : quotedProps.length && unquotedProps.length && unquotedProps.forEach((property) => {
|
|
202
|
+
context.report({
|
|
203
|
+
node: property,
|
|
204
|
+
messageId: "inconsistentlyQuotedProperty",
|
|
205
|
+
data: { key: property.key.name || property.key.value },
|
|
206
|
+
fix: (fixer) => fixer.replaceText(property.key, getQuotedKey(property.key))
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
Property(node) {
|
|
212
|
+
(MODE === "always" || !MODE) && checkOmittedQuotes(node), MODE === "as-needed" && checkUnnecessaryQuotes(node);
|
|
213
|
+
},
|
|
214
|
+
ObjectExpression(node) {
|
|
215
|
+
MODE === "consistent" && checkConsistency(node, !1), MODE === "consistent-as-needed" && checkConsistency(node, !0);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}));
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src-js/generated/plugin-eslint/rules/quote-props.cjs
|
|
223
|
+
module.exports = require_quote_props().create;
|
|
224
|
+
//#endregion
|
package/rules/quotes.cjs
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const require_chunk = require("../common/chunk.cjs"), require_ast_utils$1 = require("../common/ast-utils.cjs");
|
|
2
|
+
//#region ../../node_modules/.pnpm/eslint@9.39.3_jiti@2.6.1/node_modules/eslint/lib/rules/quotes.js
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview A rule to choose between single and double quote marks
|
|
5
|
+
* @author Matt DuVall <http://www.mattduvall.com/>, Brandon Payton
|
|
6
|
+
* @deprecated in ESLint v8.53.0
|
|
7
|
+
*/
|
|
8
|
+
var require_quotes = /* @__PURE__ */ require_chunk.t(((exports, module) => {
|
|
9
|
+
let astUtils = require_ast_utils$1.t(), QUOTE_SETTINGS = {
|
|
10
|
+
double: {
|
|
11
|
+
quote: "\"",
|
|
12
|
+
alternateQuote: "'",
|
|
13
|
+
description: "doublequote"
|
|
14
|
+
},
|
|
15
|
+
single: {
|
|
16
|
+
quote: "'",
|
|
17
|
+
alternateQuote: "\"",
|
|
18
|
+
description: "singlequote"
|
|
19
|
+
},
|
|
20
|
+
backtick: {
|
|
21
|
+
quote: "`",
|
|
22
|
+
alternateQuote: "\"",
|
|
23
|
+
description: "backtick"
|
|
24
|
+
}
|
|
25
|
+
}, UNESCAPED_LINEBREAK_PATTERN = new RegExp(String.raw`(^|[^\\])(\\\\)*[${Array.from(astUtils.LINEBREAKS).join("")}]`, "u");
|
|
26
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
27
|
+
QUOTE_SETTINGS.double.convert = QUOTE_SETTINGS.single.convert = QUOTE_SETTINGS.backtick.convert = function(str) {
|
|
28
|
+
let newQuote = this.quote, oldQuote = str[0];
|
|
29
|
+
return newQuote === oldQuote ? str : newQuote + str.slice(1, -1).replace(/\\(\$\{|\r\n?|\n|.)|["'`]|\$\{|(\r\n?|\n)/gu, (match, escaped, newline) => escaped === oldQuote || oldQuote === "`" && escaped === "${" ? escaped : match === newQuote || newQuote === "`" && match === "${" ? `\\${match}` : newline && oldQuote === "`" ? "\\n" : match) + newQuote;
|
|
30
|
+
}, module.exports = {
|
|
31
|
+
meta: {
|
|
32
|
+
deprecated: {
|
|
33
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
34
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
35
|
+
deprecatedSince: "8.53.0",
|
|
36
|
+
availableUntil: "11.0.0",
|
|
37
|
+
replacedBy: [{
|
|
38
|
+
message: "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
39
|
+
url: "https://eslint.style/guide/migration",
|
|
40
|
+
plugin: {
|
|
41
|
+
name: "@stylistic/eslint-plugin",
|
|
42
|
+
url: "https://eslint.style"
|
|
43
|
+
},
|
|
44
|
+
rule: {
|
|
45
|
+
name: "quotes",
|
|
46
|
+
url: "https://eslint.style/rules/quotes"
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
},
|
|
50
|
+
type: "layout",
|
|
51
|
+
docs: {
|
|
52
|
+
description: "Enforce the consistent use of either backticks, double, or single quotes",
|
|
53
|
+
recommended: !1,
|
|
54
|
+
url: "https://eslint.org/docs/latest/rules/quotes"
|
|
55
|
+
},
|
|
56
|
+
fixable: "code",
|
|
57
|
+
schema: [{ enum: [
|
|
58
|
+
"single",
|
|
59
|
+
"double",
|
|
60
|
+
"backtick"
|
|
61
|
+
] }, { anyOf: [{ enum: ["avoid-escape"] }, {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
avoidEscape: { type: "boolean" },
|
|
65
|
+
allowTemplateLiterals: { type: "boolean" }
|
|
66
|
+
},
|
|
67
|
+
additionalProperties: !1
|
|
68
|
+
}] }],
|
|
69
|
+
messages: { wrongQuotes: "Strings must use {{description}}." }
|
|
70
|
+
},
|
|
71
|
+
create(context) {
|
|
72
|
+
let quoteOption = context.options[0], settings = QUOTE_SETTINGS[quoteOption || "double"], options = context.options[1], allowTemplateLiterals = options && options.allowTemplateLiterals === !0, sourceCode = context.sourceCode, avoidEscape = options && options.avoidEscape === !0;
|
|
73
|
+
options === "avoid-escape" && (avoidEscape = !0);
|
|
74
|
+
/**
|
|
75
|
+
* Determines if a given node is part of JSX syntax.
|
|
76
|
+
*
|
|
77
|
+
* This function returns `true` in the following cases:
|
|
78
|
+
*
|
|
79
|
+
* - `<div className="foo"></div>` ... If the literal is an attribute value, the parent of the literal is `JSXAttribute`.
|
|
80
|
+
* - `<div>foo</div>` ... If the literal is a text content, the parent of the literal is `JSXElement`.
|
|
81
|
+
* - `<>foo</>` ... If the literal is a text content, the parent of the literal is `JSXFragment`.
|
|
82
|
+
*
|
|
83
|
+
* In particular, this function returns `false` in the following cases:
|
|
84
|
+
*
|
|
85
|
+
* - `<div className={"foo"}></div>`
|
|
86
|
+
* - `<div>{"foo"}</div>`
|
|
87
|
+
*
|
|
88
|
+
* In both cases, inside of the braces is handled as normal JavaScript.
|
|
89
|
+
* The braces are `JSXExpressionContainer` nodes.
|
|
90
|
+
* @param {ASTNode} node The Literal node to check.
|
|
91
|
+
* @returns {boolean} True if the node is a part of JSX, false if not.
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
function isJSXLiteral(node) {
|
|
95
|
+
return node.parent.type === "JSXAttribute" || node.parent.type === "JSXElement" || node.parent.type === "JSXFragment";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks whether or not a given node is a directive.
|
|
99
|
+
* The directive is a `ExpressionStatement` which has only a string literal not surrounded by
|
|
100
|
+
* parentheses.
|
|
101
|
+
* @param {ASTNode} node A node to check.
|
|
102
|
+
* @returns {boolean} Whether or not the node is a directive.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
function isDirective(node) {
|
|
106
|
+
return node.type === "ExpressionStatement" && node.expression.type === "Literal" && typeof node.expression.value == "string" && !astUtils.isParenthesised(sourceCode, node.expression);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Checks whether a specified node is either part of, or immediately follows a (possibly empty) directive prologue.
|
|
110
|
+
* @see {@link http://www.ecma-international.org/ecma-262/6.0/#sec-directive-prologues-and-the-use-strict-directive}
|
|
111
|
+
* @param {ASTNode} node A node to check.
|
|
112
|
+
* @returns {boolean} Whether a specified node is either part of, or immediately follows a (possibly empty) directive prologue.
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
function isExpressionInOrJustAfterDirectivePrologue(node) {
|
|
116
|
+
if (!astUtils.isTopLevelExpressionStatement(node.parent)) return !1;
|
|
117
|
+
let block = node.parent.parent;
|
|
118
|
+
for (let i = 0; i < block.body.length; ++i) {
|
|
119
|
+
let statement = block.body[i];
|
|
120
|
+
if (statement === node.parent) return !0;
|
|
121
|
+
if (!isDirective(statement)) break;
|
|
122
|
+
}
|
|
123
|
+
return !1;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Checks whether or not a given node is allowed as non backtick.
|
|
127
|
+
* @param {ASTNode} node A node to check.
|
|
128
|
+
* @returns {boolean} Whether or not the node is allowed as non backtick.
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
function isAllowedAsNonBacktick(node) {
|
|
132
|
+
let parent = node.parent;
|
|
133
|
+
switch (parent.type) {
|
|
134
|
+
case "ExpressionStatement": return !astUtils.isParenthesised(sourceCode, node) && isExpressionInOrJustAfterDirectivePrologue(node);
|
|
135
|
+
case "Property":
|
|
136
|
+
case "PropertyDefinition":
|
|
137
|
+
case "MethodDefinition": return parent.key === node && !parent.computed;
|
|
138
|
+
case "ImportDeclaration":
|
|
139
|
+
case "ExportNamedDeclaration": return parent.source === node;
|
|
140
|
+
case "ExportAllDeclaration": return parent.exported === node || parent.source === node;
|
|
141
|
+
case "ImportSpecifier": return parent.imported === node;
|
|
142
|
+
case "ExportSpecifier": return parent.local === node || parent.exported === node;
|
|
143
|
+
default: return !1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Checks whether or not a given TemplateLiteral node is actually using any of the special features provided by template literal strings.
|
|
148
|
+
* @param {ASTNode} node A TemplateLiteral node to check.
|
|
149
|
+
* @returns {boolean} Whether or not the TemplateLiteral node is using any of the special features provided by template literal strings.
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
function isUsingFeatureOfTemplateLiteral(node) {
|
|
153
|
+
return !!(node.parent.type === "TaggedTemplateExpression" && node === node.parent.quasi || node.expressions.length > 0 || node.quasis.length >= 1 && UNESCAPED_LINEBREAK_PATTERN.test(node.quasis[0].value.raw));
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
Literal(node) {
|
|
157
|
+
let val = node.value, rawVal = node.raw;
|
|
158
|
+
if (settings && typeof val == "string") {
|
|
159
|
+
let isValid = quoteOption === "backtick" && isAllowedAsNonBacktick(node) || isJSXLiteral(node) || astUtils.isSurroundedBy(rawVal, settings.quote);
|
|
160
|
+
!isValid && avoidEscape && (isValid = astUtils.isSurroundedBy(rawVal, settings.alternateQuote) && rawVal.includes(settings.quote)), isValid || context.report({
|
|
161
|
+
node,
|
|
162
|
+
messageId: "wrongQuotes",
|
|
163
|
+
data: { description: settings.description },
|
|
164
|
+
fix(fixer) {
|
|
165
|
+
return quoteOption === "backtick" && astUtils.hasOctalOrNonOctalDecimalEscapeSequence(rawVal) ? null : fixer.replaceText(node, settings.convert(node.raw));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
TemplateLiteral(node) {
|
|
171
|
+
allowTemplateLiterals || quoteOption === "backtick" || isUsingFeatureOfTemplateLiteral(node) || context.report({
|
|
172
|
+
node,
|
|
173
|
+
messageId: "wrongQuotes",
|
|
174
|
+
data: { description: settings.description },
|
|
175
|
+
fix(fixer) {
|
|
176
|
+
return astUtils.isTopLevelExpressionStatement(node.parent) && !astUtils.isParenthesised(sourceCode, node) ? null : fixer.replaceText(node, settings.convert(sourceCode.getText(node)));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}));
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src-js/generated/plugin-eslint/rules/quotes.cjs
|
|
186
|
+
module.exports = require_quotes().create;
|
|
187
|
+
//#endregion
|