eslint-plugin-svelte 3.3.3 → 3.4.1
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/README.md +3 -3
- package/lib/main.d.ts +1 -1
- package/lib/meta.d.ts +1 -1
- package/lib/meta.js +1 -1
- package/lib/rules/@typescript-eslint/no-unnecessary-condition.js +1 -2
- package/lib/rules/block-lang.js +3 -4
- package/lib/rules/comment-directive.js +2 -3
- package/lib/rules/consistent-selector-style.js +1 -2
- package/lib/rules/derived-has-same-inputs-outputs.js +36 -3
- package/lib/rules/first-attribute-linebreak.js +1 -2
- package/lib/rules/html-closing-bracket-new-line.js +1 -2
- package/lib/rules/html-closing-bracket-spacing.js +1 -1
- package/lib/rules/html-quotes.js +1 -2
- package/lib/rules/html-self-closing.js +1 -2
- package/lib/rules/indent-helpers/index.js +2 -3
- package/lib/rules/infinite-reactive-loop.js +3 -4
- package/lib/rules/max-attributes-per-line.js +1 -2
- package/lib/rules/mustache-spacing.js +1 -2
- package/lib/rules/no-at-debug-tags.js +10 -2
- package/lib/rules/no-dupe-else-if-blocks.js +1 -2
- package/lib/rules/no-dupe-on-directives.js +1 -2
- package/lib/rules/no-dupe-use-directives.js +1 -2
- package/lib/rules/no-dynamic-slot-name.js +1 -2
- package/lib/rules/no-extra-reactive-curlies.js +1 -2
- package/lib/rules/no-goto-without-base.js +1 -2
- package/lib/rules/no-immutable-reactive-statements.js +1 -2
- package/lib/rules/no-navigation-without-base.js +1 -2
- package/lib/rules/no-reactive-functions.js +1 -2
- package/lib/rules/no-reactive-literals.js +1 -2
- package/lib/rules/no-reactive-reassign.js +1 -2
- package/lib/rules/no-spaces-around-equal-signs-in-attribute.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -2
- package/lib/rules/no-unnecessary-state-wrap.js +3 -4
- package/lib/rules/no-unused-class-name.js +1 -2
- package/lib/rules/no-unused-props.js +63 -39
- package/lib/rules/no-unused-svelte-ignore.js +1 -2
- package/lib/rules/no-useless-mustaches.js +1 -2
- package/lib/rules/prefer-class-directive.js +1 -2
- package/lib/rules/prefer-destructured-store-props.js +2 -3
- package/lib/rules/prefer-style-directive.js +1 -2
- package/lib/rules/reference-helpers/svelte-store.js +1 -2
- package/lib/rules/require-event-dispatcher-types.js +1 -2
- package/lib/rules/require-store-callbacks-use-set-param.js +39 -2
- package/lib/rules/require-store-reactive-access.js +1 -2
- package/lib/rules/shorthand-attribute.js +1 -2
- package/lib/rules/shorthand-directive.js +1 -2
- package/lib/rules/sort-attributes.js +1 -2
- package/lib/rules/system.js +1 -2
- package/lib/rules/valid-compile.js +1 -2
- package/lib/rules/valid-style-parse.js +2 -3
- package/lib/shared/svelte-compile-warns/extract-leading-comments.js +1 -2
- package/lib/shared/svelte-compile-warns/ignore-comment.js +1 -2
- package/lib/shared/svelte-compile-warns/index.js +10 -11
- package/lib/shared/svelte-compile-warns/transform/babel.js +1 -2
- package/lib/shared/svelte-compile-warns/transform/less.js +1 -2
- package/lib/shared/svelte-compile-warns/transform/postcss.js +2 -3
- package/lib/shared/svelte-compile-warns/transform/stylus.js +1 -2
- package/lib/shared/svelte-compile-warns/transform/typescript.js +1 -2
- package/lib/types.d.ts +4 -4
- package/lib/utils/ast-utils.d.ts +11 -0
- package/lib/utils/ast-utils.js +27 -3
- package/lib/utils/css-utils/style-attribute.js +4 -5
- package/lib/utils/load-module.js +4 -5
- package/lib/utils/svelte-context.js +5 -6
- package/lib/utils/ts-utils/index.js +1 -2
- package/package.json +2 -2
- package/lib/utils/compat.d.ts +0 -22
- package/lib/utils/compat.js +0 -32
package/README.md
CHANGED
|
@@ -272,7 +272,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
|
|
|
272
272
|
| [svelte/no-shorthand-style-property-overrides](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | :star: |
|
|
273
273
|
| [svelte/no-store-async](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-store-async/) | disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features | :star: |
|
|
274
274
|
| [svelte/no-unknown-style-directive-property](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unknown-style-directive-property/) | disallow unknown `style:property` | :star: |
|
|
275
|
-
| [svelte/require-store-callbacks-use-set-param](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-callbacks-use-set-param/) | store callbacks must use `set` param |
|
|
275
|
+
| [svelte/require-store-callbacks-use-set-param](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-callbacks-use-set-param/) | store callbacks must use `set` param | :bulb: |
|
|
276
276
|
| [svelte/require-store-reactive-access](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-store-reactive-access/) | disallow to use of the store itself as an operand. Need to use $ prefix or get function. | :star::wrench: |
|
|
277
277
|
| [svelte/valid-compile](https://sveltejs.github.io/eslint-plugin-svelte/rules/valid-compile/) | disallow warnings when compiling. | |
|
|
278
278
|
| [svelte/valid-style-parse](https://sveltejs.github.io/eslint-plugin-svelte/rules/valid-style-parse/) | require valid style element parsing | |
|
|
@@ -294,7 +294,7 @@ These rules relate to better ways of doing things to help you avoid problems:
|
|
|
294
294
|
|:--------|:------------|:---|
|
|
295
295
|
| [svelte/block-lang](https://sveltejs.github.io/eslint-plugin-svelte/rules/block-lang/) | disallows the use of languages other than those specified in the configuration for the lang attribute of `<script>` and `<style>` blocks. | :bulb: |
|
|
296
296
|
| [svelte/button-has-type](https://sveltejs.github.io/eslint-plugin-svelte/rules/button-has-type/) | disallow usage of button without an explicit type attribute | |
|
|
297
|
-
| [svelte/no-at-debug-tags](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-debug-tags/) | disallow the use of `{@debug}` | :star: |
|
|
297
|
+
| [svelte/no-at-debug-tags](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-debug-tags/) | disallow the use of `{@debug}` | :star::bulb: |
|
|
298
298
|
| [svelte/no-ignored-unsubscribe](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-ignored-unsubscribe/) | disallow ignoring the unsubscribe method returned by the `subscribe()` on Svelte stores. | |
|
|
299
299
|
| [svelte/no-immutable-reactive-statements](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-immutable-reactive-statements/) | disallow reactive statements that don't reference reactive values. | :star: |
|
|
300
300
|
| [svelte/no-inline-styles](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-inline-styles/) | disallow attributes and directives that produce inline styles | |
|
|
@@ -323,7 +323,7 @@ These rules relate to style guidelines, and are therefore quite subjective:
|
|
|
323
323
|
| Rule ID | Description | |
|
|
324
324
|
|:--------|:------------|:---|
|
|
325
325
|
| [svelte/consistent-selector-style](https://sveltejs.github.io/eslint-plugin-svelte/rules/consistent-selector-style/) | enforce a consistent style for CSS selectors | |
|
|
326
|
-
| [svelte/derived-has-same-inputs-outputs](https://sveltejs.github.io/eslint-plugin-svelte/rules/derived-has-same-inputs-outputs/) | derived store should use same variable names between values and callback |
|
|
326
|
+
| [svelte/derived-has-same-inputs-outputs](https://sveltejs.github.io/eslint-plugin-svelte/rules/derived-has-same-inputs-outputs/) | derived store should use same variable names between values and callback | :bulb: |
|
|
327
327
|
| [svelte/first-attribute-linebreak](https://sveltejs.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
|
|
328
328
|
| [svelte/html-closing-bracket-new-line](https://sveltejs.github.io/eslint-plugin-svelte/rules/html-closing-bracket-new-line/) | Require or disallow a line break before tag's closing brackets | :wrench: |
|
|
329
329
|
| [svelte/html-closing-bracket-spacing](https://sveltejs.github.io/eslint-plugin-svelte/rules/html-closing-bracket-spacing/) | require or disallow a space before tag's closing brackets | :wrench: |
|
package/lib/main.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const configs: {
|
|
|
14
14
|
export declare const rules: Record<string, Rule.RuleModule>;
|
|
15
15
|
export declare const meta: {
|
|
16
16
|
name: "eslint-plugin-svelte";
|
|
17
|
-
version: "3.
|
|
17
|
+
version: "3.4.1";
|
|
18
18
|
};
|
|
19
19
|
export declare const processors: {
|
|
20
20
|
'.svelte': typeof processor;
|
package/lib/meta.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "eslint-plugin-svelte";
|
|
2
|
-
export declare const version = "3.
|
|
2
|
+
export declare const version = "3.4.1";
|
package/lib/meta.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../../utils/index.js';
|
|
2
2
|
import { isFalsyType, getConstrainedTypeAtLocation, isTruthyLiteral, isPossiblyFalsyType, isNullishType, isBooleanLiteralType, getTypeScriptTools, isAnyType, isUnknownType, isNeverType, getCallSignaturesOfType, isNullableType, getTypeOfPropertyOfType, getTypeName, isTupleType } from '../../utils/ts-utils/index.js';
|
|
3
|
-
import { getSourceCode } from '../../utils/compat.js';
|
|
4
3
|
/**
|
|
5
4
|
* Returns all types of a union type or an array containing `type` itself if it's no union type.
|
|
6
5
|
* This method is heavily inspired by tsutils. https://github.com/ajafff/tsutils
|
|
@@ -112,7 +111,7 @@ export default createRule('@typescript-eslint/no-unnecessary-condition', {
|
|
|
112
111
|
}
|
|
113
112
|
const { service, ts } = tools;
|
|
114
113
|
const checker = service.program.getTypeChecker();
|
|
115
|
-
const sourceCode =
|
|
114
|
+
const sourceCode = context.sourceCode;
|
|
116
115
|
const compilerOptions = service.program.getCompilerOptions();
|
|
117
116
|
const isStrictNullChecks = compilerOptions.strict
|
|
118
117
|
? compilerOptions.strictNullChecks !== false
|
package/lib/rules/block-lang.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { findAttribute, getLangValue } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('block-lang', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -55,7 +54,7 @@ export default createRule('block-lang', {
|
|
|
55
54
|
hasSuggestions: true
|
|
56
55
|
},
|
|
57
56
|
create(context) {
|
|
58
|
-
if (!
|
|
57
|
+
if (!context.sourceCode.parserServices.isSvelte) {
|
|
59
58
|
return {};
|
|
60
59
|
}
|
|
61
60
|
const enforceScriptPresent = context.options[0]?.enforceScriptPresent ?? false;
|
|
@@ -82,7 +81,7 @@ export default createRule('block-lang', {
|
|
|
82
81
|
context.report({
|
|
83
82
|
loc: { line: 1, column: 1 },
|
|
84
83
|
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(allowedScriptLangs)}.`,
|
|
85
|
-
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script',
|
|
84
|
+
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script', context.sourceCode)
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
87
|
for (const scriptNode of scriptNodes) {
|
|
@@ -95,7 +94,7 @@ export default createRule('block-lang', {
|
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
if (styleNodes.length === 0 && enforceStylePresent) {
|
|
98
|
-
const sourceCode =
|
|
97
|
+
const sourceCode = context.sourceCode;
|
|
99
98
|
context.report({
|
|
100
99
|
loc: { line: 1, column: 1 },
|
|
101
100
|
message: `The <style> block should be present and its lang attribute should be ${prettyPrintLangs(allowedStyleLangs)}.`,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getShared } from '../shared/index.js';
|
|
2
2
|
import { createRule } from '../utils/index.js';
|
|
3
|
-
import { getFilename, getSourceCode } from '../utils/compat.js';
|
|
4
3
|
// -----------------------------------------------------------------------------
|
|
5
4
|
// Helpers
|
|
6
5
|
// -----------------------------------------------------------------------------
|
|
@@ -43,7 +42,7 @@ export default createRule('comment-directive', {
|
|
|
43
42
|
type: 'problem'
|
|
44
43
|
},
|
|
45
44
|
create(context) {
|
|
46
|
-
const shared = getShared(
|
|
45
|
+
const shared = getShared(context.filename);
|
|
47
46
|
if (!shared)
|
|
48
47
|
return {};
|
|
49
48
|
const options = context.options[0] || {};
|
|
@@ -52,7 +51,7 @@ export default createRule('comment-directive', {
|
|
|
52
51
|
ruleId: 'svelte/comment-directive',
|
|
53
52
|
reportUnusedDisableDirectives
|
|
54
53
|
});
|
|
55
|
-
const sourceCode =
|
|
54
|
+
const sourceCode = context.sourceCode;
|
|
56
55
|
/**
|
|
57
56
|
* Parse a given comment.
|
|
58
57
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { findClassesInAttribute } from '../utils/ast-utils.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
import { createRule } from '../utils/index.js';
|
|
4
3
|
export default createRule('consistent-selector-style', {
|
|
5
4
|
meta: {
|
|
@@ -39,7 +38,7 @@ export default createRule('consistent-selector-style', {
|
|
|
39
38
|
type: 'suggestion'
|
|
40
39
|
},
|
|
41
40
|
create(context) {
|
|
42
|
-
const sourceCode =
|
|
41
|
+
const sourceCode = context.sourceCode;
|
|
43
42
|
if (!sourceCode.parserServices.isSvelte ||
|
|
44
43
|
sourceCode.parserServices.getStyleSelectorAST === undefined ||
|
|
45
44
|
sourceCode.parserServices.styleSelectorNodeLoc === undefined) {
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { extractStoreReferences } from './reference-helpers/svelte-store.js';
|
|
3
|
+
import { findVariableForReplacement } from '../utils/ast-utils.js';
|
|
4
|
+
function createFixer(node, variable, name) {
|
|
5
|
+
return function* fix(fixer) {
|
|
6
|
+
yield fixer.replaceText(node, name);
|
|
7
|
+
if (variable) {
|
|
8
|
+
for (const ref of variable.references) {
|
|
9
|
+
yield fixer.replaceText(ref.identifier, name);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
3
14
|
export default createRule('derived-has-same-inputs-outputs', {
|
|
4
15
|
meta: {
|
|
5
16
|
docs: {
|
|
@@ -8,9 +19,11 @@ export default createRule('derived-has-same-inputs-outputs', {
|
|
|
8
19
|
recommended: false,
|
|
9
20
|
conflictWithPrettier: false
|
|
10
21
|
},
|
|
22
|
+
hasSuggestions: true,
|
|
11
23
|
schema: [],
|
|
12
24
|
messages: {
|
|
13
|
-
unexpected: "The argument name should be '{{name}}'."
|
|
25
|
+
unexpected: "The argument name should be '{{name}}'.",
|
|
26
|
+
renameParam: 'Rename the parameter from {{oldName}} to {{newName}}.'
|
|
14
27
|
},
|
|
15
28
|
type: 'suggestion'
|
|
16
29
|
},
|
|
@@ -33,11 +46,21 @@ export default createRule('derived-has-same-inputs-outputs', {
|
|
|
33
46
|
return;
|
|
34
47
|
const expectedName = `$${args.name}`;
|
|
35
48
|
if (expectedName !== fnParam.name) {
|
|
49
|
+
const { hasConflict, variable } = findVariableForReplacement(context, fn.body, fnParam.name, expectedName);
|
|
36
50
|
context.report({
|
|
37
51
|
node: fn,
|
|
38
52
|
loc: fnParam.loc,
|
|
39
53
|
messageId: 'unexpected',
|
|
40
|
-
data: { name: expectedName }
|
|
54
|
+
data: { name: expectedName },
|
|
55
|
+
suggest: hasConflict
|
|
56
|
+
? undefined
|
|
57
|
+
: [
|
|
58
|
+
{
|
|
59
|
+
messageId: 'renameParam',
|
|
60
|
+
data: { oldName: fnParam.name, newName: expectedName },
|
|
61
|
+
fix: createFixer(fnParam, variable, expectedName)
|
|
62
|
+
}
|
|
63
|
+
]
|
|
41
64
|
});
|
|
42
65
|
}
|
|
43
66
|
}
|
|
@@ -57,11 +80,21 @@ export default createRule('derived-has-same-inputs-outputs', {
|
|
|
57
80
|
if (element && element.type === 'Identifier' && argName) {
|
|
58
81
|
const expectedName = `$${argName}`;
|
|
59
82
|
if (expectedName !== element.name) {
|
|
83
|
+
const { hasConflict, variable } = findVariableForReplacement(context, fn.body, element.name, expectedName);
|
|
60
84
|
context.report({
|
|
61
85
|
node: fn,
|
|
62
86
|
loc: element.loc,
|
|
63
87
|
messageId: 'unexpected',
|
|
64
|
-
data: { name: expectedName }
|
|
88
|
+
data: { name: expectedName },
|
|
89
|
+
suggest: hasConflict
|
|
90
|
+
? undefined
|
|
91
|
+
: [
|
|
92
|
+
{
|
|
93
|
+
messageId: 'renameParam',
|
|
94
|
+
data: { oldName: element.name, newName: expectedName },
|
|
95
|
+
fix: createFixer(element, variable, expectedName)
|
|
96
|
+
}
|
|
97
|
+
]
|
|
65
98
|
});
|
|
66
99
|
}
|
|
67
100
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
export default createRule('first-attribute-linebreak', {
|
|
4
3
|
meta: {
|
|
5
4
|
docs: {
|
|
@@ -28,7 +27,7 @@ export default createRule('first-attribute-linebreak', {
|
|
|
28
27
|
create(context) {
|
|
29
28
|
const multiline = context.options[0]?.multiline || 'below';
|
|
30
29
|
const singleline = context.options[0]?.singleline || 'beside';
|
|
31
|
-
const sourceCode =
|
|
30
|
+
const sourceCode = context.sourceCode;
|
|
32
31
|
/**
|
|
33
32
|
* Report attribute
|
|
34
33
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
function getPhrase(lineBreaks) {
|
|
4
3
|
switch (lineBreaks) {
|
|
5
4
|
case 0: {
|
|
@@ -80,7 +79,7 @@ export default createRule('html-closing-bracket-new-line', {
|
|
|
80
79
|
const options = { ...(context.options[0] ?? {}) };
|
|
81
80
|
options.singleline ?? (options.singleline = 'never');
|
|
82
81
|
options.multiline ?? (options.multiline = 'always');
|
|
83
|
-
const sourceCode =
|
|
82
|
+
const sourceCode = context.sourceCode;
|
|
84
83
|
return {
|
|
85
84
|
'SvelteStartTag, SvelteEndTag'(node) {
|
|
86
85
|
const data = node.type === 'SvelteStartTag' && node.selfClosing
|
package/lib/rules/html-quotes.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { getMustacheTokens } from '../utils/ast-utils.js';
|
|
3
3
|
import { getAttributeValueQuoteAndRange } from '../utils/ast-utils.js';
|
|
4
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
5
4
|
const QUOTE_CHARS = {
|
|
6
5
|
double: '"',
|
|
7
6
|
single: "'"
|
|
@@ -45,7 +44,7 @@ export default createRule('html-quotes', {
|
|
|
45
44
|
type: 'layout' // "problem",
|
|
46
45
|
},
|
|
47
46
|
create(context) {
|
|
48
|
-
const sourceCode =
|
|
47
|
+
const sourceCode = context.sourceCode;
|
|
49
48
|
const preferQuote = context.options[0]?.prefer ?? 'double';
|
|
50
49
|
const dynamicQuote = context.options[0]?.dynamic?.quoted ? preferQuote : 'unquoted';
|
|
51
50
|
const avoidInvalidUnquotedInHTML = Boolean(context.options[0]?.dynamic?.avoidInvalidUnquotedInHTML);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { getNodeName, isVoidHtmlElement, isSvgElement, isMathMLElement } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
const TYPE_MESSAGES = {
|
|
5
4
|
normal: 'HTML elements',
|
|
6
5
|
void: 'HTML void elements',
|
|
@@ -149,7 +148,7 @@ export default createRule('html-self-closing', {
|
|
|
149
148
|
context.report({
|
|
150
149
|
node,
|
|
151
150
|
loc: {
|
|
152
|
-
start:
|
|
151
|
+
start: context.sourceCode.getLocFromIndex(node.startTag.range[1] - (node.startTag.selfClosing ? 2 : 1)),
|
|
153
152
|
end: node.loc.end
|
|
154
153
|
},
|
|
155
154
|
messageId: shouldBeClosed ? 'requireClosing' : 'disallowClosing',
|
|
@@ -4,7 +4,6 @@ import * as TS from './ts.js';
|
|
|
4
4
|
import { isNotWhitespace } from './ast.js';
|
|
5
5
|
import { isCommentToken } from '@eslint-community/eslint-utils';
|
|
6
6
|
import { OffsetContext } from './offset-context.js';
|
|
7
|
-
import { getFilename, getSourceCode } from '../../utils/compat.js';
|
|
8
7
|
/**
|
|
9
8
|
* Normalize options.
|
|
10
9
|
* @param type The type of indentation.
|
|
@@ -54,10 +53,10 @@ function parseOptions(options, defaultOptions) {
|
|
|
54
53
|
* @returns AST event handlers.
|
|
55
54
|
*/
|
|
56
55
|
export function defineVisitor(context, defaultOptions) {
|
|
57
|
-
if (!
|
|
56
|
+
if (!context.filename.endsWith('.svelte'))
|
|
58
57
|
return {};
|
|
59
58
|
const options = parseOptions(context.options[0] || {}, defaultOptions);
|
|
60
|
-
const sourceCode =
|
|
59
|
+
const sourceCode = context.sourceCode;
|
|
61
60
|
const offsets = new OffsetContext({ sourceCode, options });
|
|
62
61
|
/**
|
|
63
62
|
* Get the text of the indentation part of the given location.
|
|
@@ -2,12 +2,11 @@ import { ReferenceTracker } from '@eslint-community/eslint-utils';
|
|
|
2
2
|
import { createRule } from '../utils/index.js';
|
|
3
3
|
import { findVariable } from '../utils/ast-utils.js';
|
|
4
4
|
import { traverseNodes } from 'svelte-eslint-parser';
|
|
5
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
6
5
|
/**
|
|
7
6
|
* Get usage of `tick`
|
|
8
7
|
*/
|
|
9
8
|
function extractTickReferences(context) {
|
|
10
|
-
const referenceTracker = new ReferenceTracker(
|
|
9
|
+
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope);
|
|
11
10
|
const a = referenceTracker.iterateEsmReferences({
|
|
12
11
|
svelte: {
|
|
13
12
|
[ReferenceTracker.ESM]: true,
|
|
@@ -27,7 +26,7 @@ function extractTickReferences(context) {
|
|
|
27
26
|
* Get usage of `setTimeout`, `setInterval`, `queueMicrotask`
|
|
28
27
|
*/
|
|
29
28
|
function extractTaskReferences(context) {
|
|
30
|
-
const referenceTracker = new ReferenceTracker(
|
|
29
|
+
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope);
|
|
31
30
|
const a = referenceTracker.iterateGlobalReferences({
|
|
32
31
|
setTimeout: { [ReferenceTracker.CALL]: true },
|
|
33
32
|
setInterval: { [ReferenceTracker.CALL]: true },
|
|
@@ -106,7 +105,7 @@ function isPromiseThenOrCatchBody(node) {
|
|
|
106
105
|
* Get all reactive variable reference.
|
|
107
106
|
*/
|
|
108
107
|
function getReactiveVariableReferences(context) {
|
|
109
|
-
const scopeManager =
|
|
108
|
+
const scopeManager = context.sourceCode.scopeManager;
|
|
110
109
|
// Find the top-level (module or global) scope.
|
|
111
110
|
// Any variable defined at the top-level (module scope or global scope) can be made reactive.
|
|
112
111
|
const toplevelScope = scopeManager.globalScope?.childScopes.find((scope) => scope.type === 'module') ||
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
/**
|
|
4
3
|
* Check whether the component is declared in a single line or not.
|
|
5
4
|
*/
|
|
@@ -54,7 +53,7 @@ export default createRule('max-attributes-per-line', {
|
|
|
54
53
|
create(context) {
|
|
55
54
|
const multilineMaximum = context.options[0]?.multiline ?? 1;
|
|
56
55
|
const singlelineMaximum = context.options[0]?.singleline ?? 1;
|
|
57
|
-
const sourceCode =
|
|
56
|
+
const sourceCode = context.sourceCode;
|
|
58
57
|
/**
|
|
59
58
|
* Report attributes
|
|
60
59
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isClosingBraceToken, isOpeningBraceToken } from '@eslint-community/eslint-utils';
|
|
2
2
|
import { createRule } from '../utils/index.js';
|
|
3
3
|
import { getMustacheTokens } from '../utils/ast-utils.js';
|
|
4
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
5
4
|
const VALUE_SCHEMA = { enum: ['never', 'always'] };
|
|
6
5
|
/**
|
|
7
6
|
* Normalize options.
|
|
@@ -57,7 +56,7 @@ export default createRule('mustache-spacing', {
|
|
|
57
56
|
},
|
|
58
57
|
create(context) {
|
|
59
58
|
const options = parseOptions(context.options[0]);
|
|
60
|
-
const sourceCode =
|
|
59
|
+
const sourceCode = context.sourceCode;
|
|
61
60
|
/** Verify */
|
|
62
61
|
function verifyBraces(openingBrace, closingBrace, openingOption, closingOption, hasExpression) {
|
|
63
62
|
const firstToken = sourceCode.getTokenAfter(openingBrace, {
|
|
@@ -7,9 +7,11 @@ export default createRule('no-at-debug-tags', {
|
|
|
7
7
|
recommended: true,
|
|
8
8
|
default: 'warn'
|
|
9
9
|
},
|
|
10
|
+
hasSuggestions: true,
|
|
10
11
|
schema: [],
|
|
11
12
|
messages: {
|
|
12
|
-
unexpected: 'Unexpected `{@debug}`.'
|
|
13
|
+
unexpected: 'Unexpected `{@debug}`.',
|
|
14
|
+
suggestRemove: 'Remove `{@debug}` from the source'
|
|
13
15
|
},
|
|
14
16
|
type: 'problem'
|
|
15
17
|
},
|
|
@@ -18,7 +20,13 @@ export default createRule('no-at-debug-tags', {
|
|
|
18
20
|
SvelteDebugTag(node) {
|
|
19
21
|
context.report({
|
|
20
22
|
node,
|
|
21
|
-
messageId: 'unexpected'
|
|
23
|
+
messageId: 'unexpected',
|
|
24
|
+
suggest: [
|
|
25
|
+
{
|
|
26
|
+
messageId: 'suggestRemove',
|
|
27
|
+
fix: (fixer) => fixer.remove(node)
|
|
28
|
+
}
|
|
29
|
+
]
|
|
22
30
|
});
|
|
23
31
|
}
|
|
24
32
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { equalTokens } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
/**
|
|
5
4
|
* Splits the given node by the given logical operator.
|
|
6
5
|
* @param operator Logical operator `||` or `&&`.
|
|
@@ -58,7 +57,7 @@ export default createRule('no-dupe-else-if-blocks', {
|
|
|
58
57
|
type: 'problem' // "problem",
|
|
59
58
|
},
|
|
60
59
|
create(context) {
|
|
61
|
-
const sourceCode =
|
|
60
|
+
const sourceCode = context.sourceCode;
|
|
62
61
|
/**
|
|
63
62
|
* Determines whether the two given nodes are considered to be equal. In particular, given that the nodes
|
|
64
63
|
* represent expressions in a boolean context, `||` and `&&` can be considered as commutative operators.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { equalTokens } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('no-dupe-on-directives', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -15,7 +14,7 @@ export default createRule('no-dupe-on-directives', {
|
|
|
15
14
|
type: 'problem'
|
|
16
15
|
},
|
|
17
16
|
create(context) {
|
|
18
|
-
const sourceCode =
|
|
17
|
+
const sourceCode = context.sourceCode;
|
|
19
18
|
const directiveDataMap = new Map();
|
|
20
19
|
return {
|
|
21
20
|
SvelteDirective(node) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { equalTokens, getAttributeKeyText } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('no-dupe-use-directives', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -15,7 +14,7 @@ export default createRule('no-dupe-use-directives', {
|
|
|
15
14
|
type: 'problem'
|
|
16
15
|
},
|
|
17
16
|
create(context) {
|
|
18
|
-
const sourceCode =
|
|
17
|
+
const sourceCode = context.sourceCode;
|
|
19
18
|
const directiveDataMap = new Map();
|
|
20
19
|
return {
|
|
21
20
|
SvelteDirective(node) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { findVariable, getAttributeValueQuoteAndRange, getStringIfConstant } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('no-dynamic-slot-name', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -21,7 +20,7 @@ export default createRule('no-dynamic-slot-name', {
|
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
22
|
create(context) {
|
|
24
|
-
const sourceCode =
|
|
23
|
+
const sourceCode = context.sourceCode;
|
|
25
24
|
return {
|
|
26
25
|
"SvelteElement[name.name='slot'] > SvelteStartTag.startTag > SvelteAttribute[key.name='name']"(node) {
|
|
27
26
|
if (node.value.length === 0) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
export default createRule('no-extra-reactive-curlies', {
|
|
4
3
|
meta: {
|
|
5
4
|
docs: {
|
|
@@ -20,7 +19,7 @@ export default createRule('no-extra-reactive-curlies', {
|
|
|
20
19
|
return {
|
|
21
20
|
// $: { foo = "bar"; }
|
|
22
21
|
[`SvelteReactiveStatement > BlockStatement[body.length=1]`]: (node) => {
|
|
23
|
-
const source =
|
|
22
|
+
const source = context.sourceCode;
|
|
24
23
|
return context.report({
|
|
25
24
|
node,
|
|
26
25
|
loc: node.loc,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { ReferenceTracker } from '@eslint-community/eslint-utils';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
import { findVariable } from '../utils/ast-utils.js';
|
|
5
4
|
export default createRule('no-goto-without-base', {
|
|
6
5
|
meta: {
|
|
@@ -20,7 +19,7 @@ export default createRule('no-goto-without-base', {
|
|
|
20
19
|
create(context) {
|
|
21
20
|
return {
|
|
22
21
|
Program() {
|
|
23
|
-
const referenceTracker = new ReferenceTracker(
|
|
22
|
+
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope);
|
|
24
23
|
const basePathNames = extractBasePathReferences(referenceTracker, context);
|
|
25
24
|
for (const gotoCall of extractGotoReferences(referenceTracker)) {
|
|
26
25
|
if (gotoCall.arguments.length < 1) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { findVariable, iterateIdentifiers } from '../utils/ast-utils.js';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('no-immutable-reactive-statements', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -15,7 +14,7 @@ export default createRule('no-immutable-reactive-statements', {
|
|
|
15
14
|
type: 'suggestion'
|
|
16
15
|
},
|
|
17
16
|
create(context) {
|
|
18
|
-
const scopeManager =
|
|
17
|
+
const scopeManager = context.sourceCode.scopeManager;
|
|
19
18
|
const globalScope = scopeManager.globalScope;
|
|
20
19
|
const toplevelScope = globalScope?.childScopes.find((scope) => scope.type === 'module') || globalScope;
|
|
21
20
|
if (!globalScope || !toplevelScope) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { ReferenceTracker } from '@eslint-community/eslint-utils';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
import { findVariable } from '../utils/ast-utils.js';
|
|
5
4
|
export default createRule('no-navigation-without-base', {
|
|
6
5
|
meta: {
|
|
@@ -41,7 +40,7 @@ export default createRule('no-navigation-without-base', {
|
|
|
41
40
|
let basePathNames = new Set();
|
|
42
41
|
return {
|
|
43
42
|
Program() {
|
|
44
|
-
const referenceTracker = new ReferenceTracker(
|
|
43
|
+
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope);
|
|
45
44
|
basePathNames = extractBasePathReferences(referenceTracker, context);
|
|
46
45
|
const { goto: gotoCalls, pushState: pushStateCalls, replaceState: replaceStateCalls } = extractFunctionCallReferences(referenceTracker);
|
|
47
46
|
if (context.options[0]?.ignoreGoto !== true) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
export default createRule('no-reactive-functions', {
|
|
4
3
|
meta: {
|
|
5
4
|
docs: {
|
|
@@ -33,7 +32,7 @@ export default createRule('no-reactive-functions', {
|
|
|
33
32
|
if (!parent) {
|
|
34
33
|
return false;
|
|
35
34
|
}
|
|
36
|
-
const source =
|
|
35
|
+
const source = context.sourceCode;
|
|
37
36
|
return context.report({
|
|
38
37
|
node: parent,
|
|
39
38
|
loc: parent.loc,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
export default createRule('no-reactive-literals', {
|
|
4
3
|
meta: {
|
|
5
4
|
docs: {
|
|
@@ -40,7 +39,7 @@ export default createRule('no-reactive-literals', {
|
|
|
40
39
|
if (!parent) {
|
|
41
40
|
return false;
|
|
42
41
|
}
|
|
43
|
-
const source =
|
|
42
|
+
const source = context.sourceCode;
|
|
44
43
|
return context.report({
|
|
45
44
|
node: parent,
|
|
46
45
|
loc: parent.loc,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
2
|
import { getPropertyName } from '@eslint-community/eslint-utils';
|
|
3
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
4
3
|
export default createRule('no-reactive-reassign', {
|
|
5
4
|
meta: {
|
|
6
5
|
docs: {
|
|
@@ -36,7 +35,7 @@ export default createRule('no-reactive-reassign', {
|
|
|
36
35
|
},
|
|
37
36
|
create(context) {
|
|
38
37
|
const props = context.options[0]?.props !== false; // default true
|
|
39
|
-
const sourceCode =
|
|
38
|
+
const sourceCode = context.sourceCode;
|
|
40
39
|
const scopeManager = sourceCode.scopeManager;
|
|
41
40
|
const globalScope = scopeManager.globalScope;
|
|
42
41
|
const toplevelScope = globalScope?.childScopes.find((scope) => scope.type === 'module') || globalScope;
|
|
@@ -15,7 +15,7 @@ export default createRule('no-spaces-around-equal-signs-in-attribute', {
|
|
|
15
15
|
type: 'layout'
|
|
16
16
|
},
|
|
17
17
|
create(ctx) {
|
|
18
|
-
const source = ctx.
|
|
18
|
+
const source = ctx.sourceCode;
|
|
19
19
|
/**
|
|
20
20
|
* Returns source text between attribute key and value, and range of that source
|
|
21
21
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createRule } from '../utils/index.js';
|
|
2
|
-
import { getSourceCode } from '../utils/compat.js';
|
|
3
2
|
export default createRule('no-trailing-spaces', {
|
|
4
3
|
meta: {
|
|
5
4
|
type: 'layout',
|
|
@@ -29,7 +28,7 @@ export default createRule('no-trailing-spaces', {
|
|
|
29
28
|
const options = context.options[0];
|
|
30
29
|
const skipBlankLines = options?.skipBlankLines || false;
|
|
31
30
|
const ignoreComments = options?.ignoreComments || false;
|
|
32
|
-
const sourceCode =
|
|
31
|
+
const sourceCode = context.sourceCode;
|
|
33
32
|
const ignoreLineNumbers = new Set();
|
|
34
33
|
if (ignoreComments) {
|
|
35
34
|
for (const { type, loc } of sourceCode.getAllComments()) {
|