eslint-plugin-svelte 2.0.0 → 2.2.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/README.md +33 -1
- package/lib/configs/prettier.d.ts +13 -0
- package/lib/configs/prettier.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -0
- package/lib/rules/button-has-type.js +6 -2
- package/lib/rules/comment-directive.js +10 -5
- package/lib/rules/first-attribute-linebreak.js +3 -3
- package/lib/rules/html-quotes.js +4 -4
- package/lib/rules/indent-helpers/commons.d.ts +1 -0
- package/lib/rules/indent-helpers/es.js +4 -1
- package/lib/rules/indent-helpers/index.js +22 -4
- package/lib/rules/indent-helpers/offset-context.js +2 -4
- package/lib/rules/indent-helpers/svelte.js +1 -1
- package/lib/rules/indent-helpers/ts.js +7 -2
- package/lib/rules/indent.js +2 -0
- package/lib/rules/max-attributes-per-line.js +4 -5
- package/lib/rules/mustache-spacing.js +6 -6
- package/lib/rules/no-inner-declarations.js +1 -2
- package/lib/rules/no-unknown-style-directive-property.js +2 -3
- package/lib/rules/prefer-class-directive.js +8 -3
- package/lib/rules/prefer-style-directive.js +4 -1
- package/lib/rules/require-optimized-style-attribute.js +1 -2
- package/lib/rules/shorthand-attribute.js +2 -2
- package/lib/rules/shorthand-directive.js +2 -2
- package/lib/rules/spaced-html-comment.js +3 -3
- package/lib/rules/system.js +1 -2
- package/lib/rules/valid-compile.js +1 -2
- package/lib/shared/comment-directives.js +2 -3
- package/lib/shared/index.js +2 -3
- package/lib/shared/svelte-compile-warns/index.js +22 -17
- package/lib/shared/svelte-compile-warns/transform/babel.js +1 -2
- package/lib/shared/svelte-compile-warns/transform/load-module.js +9 -21
- package/lib/shared/svelte-compile-warns/transform/postcss.js +8 -6
- package/lib/shared/svelte-compile-warns/transform/typescript.js +1 -1
- package/lib/types.d.ts +8 -2
- package/lib/utils/ast-utils.d.ts +5 -0
- package/lib/utils/ast-utils.js +15 -1
- package/lib/utils/css-utils/style-attribute.js +12 -8
- package/lib/utils/css-utils/utils.js +1 -2
- package/lib/utils/eslint-core.js +1 -2
- package/lib/utils/index.js +9 -1
- package/package.json +51 -53
package/README.md
CHANGED
|
@@ -83,6 +83,7 @@ This plugin provides configs:
|
|
|
83
83
|
|
|
84
84
|
- `plugin:svelte/base` ... Configuration to enable correct Svelte parsing.
|
|
85
85
|
- `plugin:svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior.
|
|
86
|
+
- `plugin:svelte/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/) ([prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte)).
|
|
86
87
|
|
|
87
88
|
See [the rule list](https://ota-meshi.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides.
|
|
88
89
|
|
|
@@ -331,9 +332,40 @@ Please use GitHub's Issues/PRs.
|
|
|
331
332
|
|
|
332
333
|
### Development Tools
|
|
333
334
|
|
|
334
|
-
- `yarn test` runs tests
|
|
335
|
+
- `yarn test` runs tests.
|
|
336
|
+
- `yarn cover` runs tests and measures coverage.
|
|
335
337
|
- `yarn update` runs in order to update readme and recommended configuration.
|
|
336
338
|
|
|
339
|
+
### Test the Rule
|
|
340
|
+
|
|
341
|
+
Rule testing almost always uses fixtures.
|
|
342
|
+
For example, for an `indent` rule, the `.ts` file that runs the test is `tests/src/rules/indent.ts` and the fixture is in `tests/fixtures/rules/indent`.
|
|
343
|
+
The fixture directory has an `invalid` directory and a `valid` directory.
|
|
344
|
+
|
|
345
|
+
- The `invalid` directory contains test cases where the rule reports problems.
|
|
346
|
+
- The `valid` directory contains test cases where the rule does not report a problem.
|
|
347
|
+
|
|
348
|
+
The fixture input file should be named `*-input.svelte`. It is automatically collected and tested.
|
|
349
|
+
If your test requires configuration, you need to add a json file with the configuration.
|
|
350
|
+
|
|
351
|
+
- If you want to apply a configuration to `my-test-input.svelte`, add `my-test-config.json`.
|
|
352
|
+
- If you want to apply the same configuration to all the fixtures in that directory, add `_config.json`.
|
|
353
|
+
|
|
354
|
+
To verify the output of invalid test cases requires `*-errors.json`, and `*-output.svelte` (for auto-fix). However, you don't have to add them yourself. If they do not exist, they will be automatically generated when you run the test. In other words, delete them manually when you want to recreate them.
|
|
355
|
+
|
|
356
|
+
**Tips**:
|
|
357
|
+
|
|
358
|
+
If you want to test only one rule, run the following command (for `indent` rule):
|
|
359
|
+
|
|
360
|
+
```sh
|
|
361
|
+
yarn test -g indent
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Take <https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha> as reference for details.
|
|
365
|
+
|
|
366
|
+
If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
|
|
367
|
+
(Note that `{"only": true}` must be removed before making a pull request.)
|
|
368
|
+
|
|
337
369
|
### Working With Rules
|
|
338
370
|
|
|
339
371
|
This plugin uses [svelte-eslint-parser](https://github.com/ota-meshi/svelte-eslint-parser) for the parser. Check [here](https://ota-meshi.github.io/svelte-eslint-parser/) to find out about AST.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
extends: string[];
|
|
3
|
+
rules: {
|
|
4
|
+
"svelte/first-attribute-linebreak": string;
|
|
5
|
+
"svelte/html-quotes": string;
|
|
6
|
+
"svelte/indent": string;
|
|
7
|
+
"svelte/max-attributes-per-line": string;
|
|
8
|
+
"svelte/mustache-spacing": string;
|
|
9
|
+
"svelte/shorthand-attribute": string;
|
|
10
|
+
"svelte/shorthand-directive": string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export = _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const path_1 = __importDefault(require("path"));
|
|
6
|
+
const base = require.resolve("./base");
|
|
7
|
+
const baseExtend = path_1.default.extname(`${base}`) === ".ts" ? "plugin:svelte/base" : base;
|
|
8
|
+
module.exports = {
|
|
9
|
+
extends: [baseExtend],
|
|
10
|
+
rules: {
|
|
11
|
+
"svelte/first-attribute-linebreak": "off",
|
|
12
|
+
"svelte/html-quotes": "off",
|
|
13
|
+
"svelte/indent": "off",
|
|
14
|
+
"svelte/max-attributes-per-line": "off",
|
|
15
|
+
"svelte/mustache-spacing": "off",
|
|
16
|
+
"svelte/shorthand-attribute": "off",
|
|
17
|
+
"svelte/shorthand-directive": "off",
|
|
18
|
+
},
|
|
19
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ declare const _default: {
|
|
|
33
33
|
"svelte/valid-compile": string;
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
+
prettier: {
|
|
37
|
+
extends: string[];
|
|
38
|
+
rules: {
|
|
39
|
+
"svelte/first-attribute-linebreak": string;
|
|
40
|
+
"svelte/html-quotes": string;
|
|
41
|
+
"svelte/indent": string;
|
|
42
|
+
"svelte/max-attributes-per-line": string;
|
|
43
|
+
"svelte/mustache-spacing": string;
|
|
44
|
+
"svelte/shorthand-attribute": string;
|
|
45
|
+
"svelte/shorthand-directive": string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
36
48
|
};
|
|
37
49
|
rules: {
|
|
38
50
|
[key: string]: RuleModule;
|
package/lib/index.js
CHANGED
|
@@ -28,10 +28,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
const rules_1 = require("./utils/rules");
|
|
29
29
|
const base_1 = __importDefault(require("./configs/base"));
|
|
30
30
|
const recommended_1 = __importDefault(require("./configs/recommended"));
|
|
31
|
+
const prettier_1 = __importDefault(require("./configs/prettier"));
|
|
31
32
|
const processor = __importStar(require("./processor"));
|
|
32
33
|
const configs = {
|
|
33
34
|
base: base_1.default,
|
|
34
35
|
recommended: recommended_1.default,
|
|
36
|
+
prettier: prettier_1.default,
|
|
35
37
|
};
|
|
36
38
|
const rules = rules_1.rules.reduce((obj, r) => {
|
|
37
39
|
obj[r.meta.docs.ruleName] = r;
|
|
@@ -35,8 +35,12 @@ exports.default = (0, utils_1.createRule)("button-has-type", {
|
|
|
35
35
|
type: "suggestion",
|
|
36
36
|
},
|
|
37
37
|
create(context) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const configuration = {
|
|
39
|
+
button: true,
|
|
40
|
+
submit: true,
|
|
41
|
+
reset: true,
|
|
42
|
+
...(context.options[0] ?? {}),
|
|
43
|
+
};
|
|
40
44
|
function isButtonType(type) {
|
|
41
45
|
return type === "button" || type === "submit" || type === "reset";
|
|
42
46
|
}
|
|
@@ -26,7 +26,12 @@ exports.default = (0, utils_1.createRule)("comment-directive", {
|
|
|
26
26
|
additionalProperties: false,
|
|
27
27
|
},
|
|
28
28
|
],
|
|
29
|
-
messages: {
|
|
29
|
+
messages: {
|
|
30
|
+
unused: "Unused {{kind}} directive (no problems were reported).",
|
|
31
|
+
unusedRule: "Unused {{kind}} directive (no problems were reported from '{{rule}}').",
|
|
32
|
+
unusedEnable: "Unused {{kind}} directive (reporting is not suppressed).",
|
|
33
|
+
unusedEnableRule: "Unused {{kind}} directive (reporting from '{{rule}}' is not suppressed).",
|
|
34
|
+
},
|
|
30
35
|
type: "problem",
|
|
31
36
|
},
|
|
32
37
|
create(context) {
|
|
@@ -81,7 +86,7 @@ exports.default = (0, utils_1.createRule)("comment-directive", {
|
|
|
81
86
|
data: { rule: rule.ruleId, kind: parsed.type },
|
|
82
87
|
});
|
|
83
88
|
}
|
|
84
|
-
directives.disableBlock(comment.loc.
|
|
89
|
+
directives.disableBlock(comment.loc.end, rule.ruleId, {
|
|
85
90
|
loc: rule.loc.start,
|
|
86
91
|
});
|
|
87
92
|
}
|
|
@@ -94,7 +99,7 @@ exports.default = (0, utils_1.createRule)("comment-directive", {
|
|
|
94
99
|
data: { kind: parsed.type },
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
|
-
directives.disableBlock(comment.loc.
|
|
102
|
+
directives.disableBlock(comment.loc.end, ALL_RULES, {
|
|
98
103
|
loc: comment.loc.start,
|
|
99
104
|
});
|
|
100
105
|
}
|
|
@@ -105,7 +110,7 @@ exports.default = (0, utils_1.createRule)("comment-directive", {
|
|
|
105
110
|
if (reportUnusedDisableDirectives) {
|
|
106
111
|
context.report({
|
|
107
112
|
loc: rule.loc,
|
|
108
|
-
messageId: "
|
|
113
|
+
messageId: "unusedEnableRule",
|
|
109
114
|
data: { rule: rule.ruleId, kind: parsed.type },
|
|
110
115
|
});
|
|
111
116
|
}
|
|
@@ -118,7 +123,7 @@ exports.default = (0, utils_1.createRule)("comment-directive", {
|
|
|
118
123
|
if (reportUnusedDisableDirectives) {
|
|
119
124
|
context.report({
|
|
120
125
|
loc: comment.loc,
|
|
121
|
-
messageId: "
|
|
126
|
+
messageId: "unusedEnable",
|
|
122
127
|
data: { kind: parsed.type },
|
|
123
128
|
});
|
|
124
129
|
}
|
|
@@ -7,6 +7,7 @@ exports.default = (0, utils_1.createRule)("first-attribute-linebreak", {
|
|
|
7
7
|
description: "enforce the location of first attribute",
|
|
8
8
|
category: "Stylistic Issues",
|
|
9
9
|
recommended: false,
|
|
10
|
+
conflictWithPrettier: true,
|
|
10
11
|
},
|
|
11
12
|
fixable: "whitespace",
|
|
12
13
|
schema: [
|
|
@@ -26,9 +27,8 @@ exports.default = (0, utils_1.createRule)("first-attribute-linebreak", {
|
|
|
26
27
|
type: "layout",
|
|
27
28
|
},
|
|
28
29
|
create(context) {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const singleline = ((_b = context.options[0]) === null || _b === void 0 ? void 0 : _b.singleline) || "beside";
|
|
30
|
+
const multiline = context.options[0]?.multiline || "below";
|
|
31
|
+
const singleline = context.options[0]?.singleline || "beside";
|
|
32
32
|
const sourceCode = context.getSourceCode();
|
|
33
33
|
function report(firstAttribute, location) {
|
|
34
34
|
context.report({
|
package/lib/rules/html-quotes.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.default = (0, utils_1.createRule)("html-quotes", {
|
|
|
18
18
|
description: "enforce quotes style of HTML attributes",
|
|
19
19
|
category: "Stylistic Issues",
|
|
20
20
|
recommended: false,
|
|
21
|
+
conflictWithPrettier: true,
|
|
21
22
|
},
|
|
22
23
|
fixable: "code",
|
|
23
24
|
schema: [
|
|
@@ -45,13 +46,12 @@ exports.default = (0, utils_1.createRule)("html-quotes", {
|
|
|
45
46
|
type: "layout",
|
|
46
47
|
},
|
|
47
48
|
create(context) {
|
|
48
|
-
var _a, _b, _c, _d, _e, _f;
|
|
49
49
|
const sourceCode = context.getSourceCode();
|
|
50
|
-
const preferQuote =
|
|
51
|
-
const dynamicQuote =
|
|
50
|
+
const preferQuote = context.options[0]?.prefer ?? "double";
|
|
51
|
+
const dynamicQuote = context.options[0]?.dynamic?.quoted
|
|
52
52
|
? preferQuote
|
|
53
53
|
: "unquoted";
|
|
54
|
-
const avoidInvalidUnquotedInHTML = Boolean(
|
|
54
|
+
const avoidInvalidUnquotedInHTML = Boolean(context.options[0]?.dynamic?.avoidInvalidUnquotedInHTML);
|
|
55
55
|
function canBeUnquotedInHTML(text) {
|
|
56
56
|
return !/[\s"'<=>`]/u.test(text);
|
|
57
57
|
}
|
|
@@ -729,7 +729,10 @@ function defineVisitor(context) {
|
|
|
729
729
|
},
|
|
730
730
|
};
|
|
731
731
|
const v = visitor;
|
|
732
|
-
return
|
|
732
|
+
return {
|
|
733
|
+
...v,
|
|
734
|
+
...commonVisitor,
|
|
735
|
+
};
|
|
733
736
|
}
|
|
734
737
|
exports.defineVisitor = defineVisitor;
|
|
735
738
|
function getParent(node) {
|
|
@@ -31,7 +31,15 @@ const ast_1 = require("./ast");
|
|
|
31
31
|
const eslint_utils_1 = require("eslint-utils");
|
|
32
32
|
const offset_context_1 = require("./offset-context");
|
|
33
33
|
function parseOptions(options, defaultOptions) {
|
|
34
|
-
const ret =
|
|
34
|
+
const ret = {
|
|
35
|
+
indentChar: " ",
|
|
36
|
+
indentScript: true,
|
|
37
|
+
indentSize: 2,
|
|
38
|
+
switchCase: 1,
|
|
39
|
+
alignAttributesVertically: false,
|
|
40
|
+
ignoredNodes: [],
|
|
41
|
+
...defaultOptions,
|
|
42
|
+
};
|
|
35
43
|
if (Number.isSafeInteger(options.indent)) {
|
|
36
44
|
ret.indentSize = Number(options.indent);
|
|
37
45
|
}
|
|
@@ -39,6 +47,9 @@ function parseOptions(options, defaultOptions) {
|
|
|
39
47
|
ret.indentChar = "\t";
|
|
40
48
|
ret.indentSize = 1;
|
|
41
49
|
}
|
|
50
|
+
if (typeof options.indentScript === "boolean") {
|
|
51
|
+
ret.indentScript = options.indentScript;
|
|
52
|
+
}
|
|
42
53
|
if (options.switchCase != null && Number.isSafeInteger(options.switchCase)) {
|
|
43
54
|
ret.switchCase = options.switchCase;
|
|
44
55
|
}
|
|
@@ -152,7 +163,11 @@ function defineVisitor(context, defaultOptions) {
|
|
|
152
163
|
options,
|
|
153
164
|
offsets,
|
|
154
165
|
};
|
|
155
|
-
const nodesVisitor =
|
|
166
|
+
const nodesVisitor = {
|
|
167
|
+
...ES.defineVisitor(indentContext),
|
|
168
|
+
...SV.defineVisitor(indentContext),
|
|
169
|
+
...TS.defineVisitor(indentContext),
|
|
170
|
+
};
|
|
156
171
|
const knownNodes = new Set(Object.keys(nodesVisitor));
|
|
157
172
|
function compositingIgnoresVisitor(visitor) {
|
|
158
173
|
for (const ignoreSelector of options.ignoredNodes) {
|
|
@@ -171,7 +186,9 @@ function defineVisitor(context, defaultOptions) {
|
|
|
171
186
|
}
|
|
172
187
|
return visitor;
|
|
173
188
|
}
|
|
174
|
-
return compositingIgnoresVisitor(
|
|
189
|
+
return compositingIgnoresVisitor({
|
|
190
|
+
...nodesVisitor,
|
|
191
|
+
"*:exit"(node) {
|
|
175
192
|
if (!knownNodes.has(node.type)) {
|
|
176
193
|
offsets.ignore(node);
|
|
177
194
|
}
|
|
@@ -218,6 +235,7 @@ function defineVisitor(context, defaultOptions) {
|
|
|
218
235
|
};
|
|
219
236
|
}
|
|
220
237
|
}
|
|
221
|
-
}
|
|
238
|
+
},
|
|
239
|
+
});
|
|
222
240
|
}
|
|
223
241
|
exports.defineVisitor = defineVisitor;
|
|
@@ -126,9 +126,8 @@ class OffsetContext {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
ignore(node) {
|
|
129
|
-
var _a;
|
|
130
129
|
const range = node.range;
|
|
131
|
-
const n =
|
|
130
|
+
const n = this.ignoreRanges.get(range[0]) ?? 0;
|
|
132
131
|
this.ignoreRanges.set(range[0], Math.max(n, range[1]));
|
|
133
132
|
}
|
|
134
133
|
getOffsetCalculator() {
|
|
@@ -183,13 +182,12 @@ class OffsetCalculator {
|
|
|
183
182
|
return null;
|
|
184
183
|
}
|
|
185
184
|
saveExpectedIndent(tokens, expectedIndent) {
|
|
186
|
-
var _a;
|
|
187
185
|
for (const token of tokens) {
|
|
188
186
|
const offsetInfo = this.offsets.get(token.range[0]);
|
|
189
187
|
if (offsetInfo == null) {
|
|
190
188
|
continue;
|
|
191
189
|
}
|
|
192
|
-
offsetInfo.expectedIndent =
|
|
190
|
+
offsetInfo.expectedIndent = offsetInfo.expectedIndent ?? expectedIndent;
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
193
|
}
|
|
@@ -10,7 +10,7 @@ function defineVisitor(context) {
|
|
|
10
10
|
const { sourceCode, offsets, options } = context;
|
|
11
11
|
const visitor = {
|
|
12
12
|
SvelteScriptElement(node) {
|
|
13
|
-
offsets.setOffsetElementList(node.body, node.startTag, node.endTag, 1);
|
|
13
|
+
offsets.setOffsetElementList(node.body, node.startTag, node.endTag, options.indentScript ? 1 : 0);
|
|
14
14
|
},
|
|
15
15
|
SvelteStyleElement(node) {
|
|
16
16
|
node.children.forEach((n) => offsets.ignore(n));
|
|
@@ -542,7 +542,7 @@ function defineVisitor(context) {
|
|
|
542
542
|
}
|
|
543
543
|
if (decorators[0] === node) {
|
|
544
544
|
if (parent.range[0] === node.range[0]) {
|
|
545
|
-
const startParentToken = sourceCode.getTokenAfter(decorators[
|
|
545
|
+
const startParentToken = sourceCode.getTokenAfter(decorators[decorators?.length - 1]);
|
|
546
546
|
offsets.setOffsetToken(startParentToken, 0, atToken);
|
|
547
547
|
}
|
|
548
548
|
else {
|
|
@@ -730,6 +730,11 @@ function defineVisitor(context) {
|
|
|
730
730
|
},
|
|
731
731
|
};
|
|
732
732
|
const v = visitor;
|
|
733
|
-
return
|
|
733
|
+
return {
|
|
734
|
+
...v,
|
|
735
|
+
...commonsVisitor,
|
|
736
|
+
...extendsESVisitor,
|
|
737
|
+
...deprecatedVisitor,
|
|
738
|
+
};
|
|
734
739
|
}
|
|
735
740
|
exports.defineVisitor = defineVisitor;
|
package/lib/rules/indent.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
8
8
|
description: "enforce consistent indentation",
|
|
9
9
|
category: "Stylistic Issues",
|
|
10
10
|
recommended: false,
|
|
11
|
+
conflictWithPrettier: true,
|
|
11
12
|
},
|
|
12
13
|
fixable: "whitespace",
|
|
13
14
|
schema: [
|
|
@@ -17,6 +18,7 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
17
18
|
indent: {
|
|
18
19
|
anyOf: [{ type: "integer", minimum: 1 }, { enum: ["tab"] }],
|
|
19
20
|
},
|
|
21
|
+
indentScript: { type: "boolean" },
|
|
20
22
|
switchCase: { type: "integer", minimum: 0 },
|
|
21
23
|
alignAttributesVertically: { type: "boolean" },
|
|
22
24
|
ignoredNodes: {
|
|
@@ -5,10 +5,9 @@ function isSingleLine(node) {
|
|
|
5
5
|
return node.loc.start.line === node.loc.end.line;
|
|
6
6
|
}
|
|
7
7
|
function groupAttributesByLine(attributes) {
|
|
8
|
-
var _a, _b;
|
|
9
8
|
const group = [];
|
|
10
9
|
for (const attr of attributes) {
|
|
11
|
-
if (
|
|
10
|
+
if (group[0]?.[0]?.loc.end.line === attr.loc.start.line) {
|
|
12
11
|
group[0].push(attr);
|
|
13
12
|
}
|
|
14
13
|
else {
|
|
@@ -23,6 +22,7 @@ exports.default = (0, utils_1.createRule)("max-attributes-per-line", {
|
|
|
23
22
|
description: "enforce the maximum number of attributes per line",
|
|
24
23
|
category: "Stylistic Issues",
|
|
25
24
|
recommended: false,
|
|
25
|
+
conflictWithPrettier: true,
|
|
26
26
|
},
|
|
27
27
|
fixable: "whitespace",
|
|
28
28
|
schema: [
|
|
@@ -47,9 +47,8 @@ exports.default = (0, utils_1.createRule)("max-attributes-per-line", {
|
|
|
47
47
|
type: "layout",
|
|
48
48
|
},
|
|
49
49
|
create(context) {
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const singlelineMaximum = (_d = (_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.singleline) !== null && _d !== void 0 ? _d : 1;
|
|
50
|
+
const multilineMaximum = context.options[0]?.multiline ?? 1;
|
|
51
|
+
const singlelineMaximum = context.options[0]?.singleline ?? 1;
|
|
53
52
|
const sourceCode = context.getSourceCode();
|
|
54
53
|
function report(attribute) {
|
|
55
54
|
if (!attribute) {
|
|
@@ -5,14 +5,13 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
6
6
|
const VALUE_SCHEMA = { enum: ["never", "always"] };
|
|
7
7
|
function parseOptions(options) {
|
|
8
|
-
var _a, _b;
|
|
9
8
|
return {
|
|
10
|
-
textExpressions:
|
|
11
|
-
attributesAndProps:
|
|
12
|
-
directiveExpressions:
|
|
9
|
+
textExpressions: options?.textExpressions || "never",
|
|
10
|
+
attributesAndProps: options?.attributesAndProps || "never",
|
|
11
|
+
directiveExpressions: options?.directiveExpressions || "never",
|
|
13
12
|
tags: {
|
|
14
|
-
openingBrace:
|
|
15
|
-
closingBrace:
|
|
13
|
+
openingBrace: options?.tags?.openingBrace || "never",
|
|
14
|
+
closingBrace: options?.tags?.closingBrace || "never",
|
|
16
15
|
},
|
|
17
16
|
};
|
|
18
17
|
}
|
|
@@ -22,6 +21,7 @@ exports.default = (0, utils_1.createRule)("mustache-spacing", {
|
|
|
22
21
|
description: "enforce unified spacing in mustache",
|
|
23
22
|
category: "Stylistic Issues",
|
|
24
23
|
recommended: false,
|
|
24
|
+
conflictWithPrettier: true,
|
|
25
25
|
},
|
|
26
26
|
fixable: "code",
|
|
27
27
|
schema: [
|
|
@@ -22,8 +22,7 @@ exports.default = (0, utils_1.createRule)("no-inner-declarations", {
|
|
|
22
22
|
return (0, eslint_core_1.buildProxyListener)(coreListener, (node) => {
|
|
23
23
|
return (0, eslint_core_1.getProxyNode)(node, {
|
|
24
24
|
get parent() {
|
|
25
|
-
|
|
26
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === "SvelteScriptElement") {
|
|
25
|
+
if (node.parent?.type === "SvelteScriptElement") {
|
|
27
26
|
return node.parent.parent;
|
|
28
27
|
}
|
|
29
28
|
return node.parent;
|
|
@@ -34,11 +34,10 @@ exports.default = (0, utils_1.createRule)("no-unknown-style-directive-property",
|
|
|
34
34
|
type: "problem",
|
|
35
35
|
},
|
|
36
36
|
create(context) {
|
|
37
|
-
var _a, _b, _c, _d;
|
|
38
37
|
const ignoreProperties = [
|
|
39
|
-
...(
|
|
38
|
+
...(context.options[0]?.ignoreProperties ?? []),
|
|
40
39
|
].map(regexp_1.toRegExp);
|
|
41
|
-
const ignorePrefixed =
|
|
40
|
+
const ignorePrefixed = context.options[0]?.ignorePrefixed ?? true;
|
|
42
41
|
const knownProperties = new Set(known_css_properties_1.all);
|
|
43
42
|
function validName(name) {
|
|
44
43
|
return (name.startsWith("--") ||
|
|
@@ -8,6 +8,7 @@ exports.default = (0, utils_1.createRule)("prefer-class-directive", {
|
|
|
8
8
|
description: "require class directives instead of ternary expressions",
|
|
9
9
|
category: "Stylistic Issues",
|
|
10
10
|
recommended: false,
|
|
11
|
+
conflictWithPrettier: false,
|
|
11
12
|
},
|
|
12
13
|
fixable: "code",
|
|
13
14
|
schema: [],
|
|
@@ -39,7 +40,10 @@ exports.default = (0, utils_1.createRule)("prefer-class-directive", {
|
|
|
39
40
|
return false;
|
|
40
41
|
}
|
|
41
42
|
for (const [expr, str] of sub) {
|
|
42
|
-
result.set(
|
|
43
|
+
result.set({
|
|
44
|
+
...key,
|
|
45
|
+
chains: expr,
|
|
46
|
+
}, str);
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
@@ -229,8 +233,9 @@ exports.default = (0, utils_1.createRule)("prefer-class-directive", {
|
|
|
229
233
|
report(node, map, attr);
|
|
230
234
|
}
|
|
231
235
|
return {
|
|
232
|
-
"
|
|
233
|
-
if (node.
|
|
236
|
+
"SvelteStartTag > SvelteAttribute"(node) {
|
|
237
|
+
if (!(0, ast_utils_1.isHTMLElementLike)(node.parent.parent) ||
|
|
238
|
+
node.key.name !== "class") {
|
|
234
239
|
return;
|
|
235
240
|
}
|
|
236
241
|
for (let index = 0; index < node.value.length; index++) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const css_utils_1 = require("../utils/css-utils");
|
|
5
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
6
|
function isStringLiteral(node) {
|
|
6
7
|
return node.type === "Literal" && typeof node.value === "string";
|
|
7
8
|
}
|
|
@@ -11,6 +12,7 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
|
|
|
11
12
|
description: "require style directives instead of style attribute",
|
|
12
13
|
category: "Stylistic Issues",
|
|
13
14
|
recommended: false,
|
|
15
|
+
conflictWithPrettier: false,
|
|
14
16
|
},
|
|
15
17
|
fixable: "code",
|
|
16
18
|
schema: [],
|
|
@@ -140,7 +142,8 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
|
|
|
140
142
|
}
|
|
141
143
|
return {
|
|
142
144
|
"SvelteStartTag > SvelteAttribute"(node) {
|
|
143
|
-
if (node.
|
|
145
|
+
if (!(0, ast_utils_1.isHTMLElementLike)(node.parent.parent) ||
|
|
146
|
+
node.key.name !== "style") {
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
146
149
|
const root = (0, css_utils_1.parseStyleAttributeValue)(node, context);
|
|
@@ -30,8 +30,7 @@ exports.default = (0, utils_1.createRule)("require-optimized-style-attribute", {
|
|
|
30
30
|
});
|
|
31
31
|
},
|
|
32
32
|
SvelteAttribute(node) {
|
|
33
|
-
|
|
34
|
-
if (node.key.name !== "style" || !((_a = node.value) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
33
|
+
if (node.key.name !== "style" || !node.value?.length) {
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
const root = (0, css_utils_1.parseStyleAttributeValue)(node, context);
|
|
@@ -8,6 +8,7 @@ exports.default = (0, utils_1.createRule)("shorthand-attribute", {
|
|
|
8
8
|
description: "enforce use of shorthand syntax in attribute",
|
|
9
9
|
category: "Stylistic Issues",
|
|
10
10
|
recommended: false,
|
|
11
|
+
conflictWithPrettier: true,
|
|
11
12
|
},
|
|
12
13
|
fixable: "code",
|
|
13
14
|
schema: [
|
|
@@ -26,9 +27,8 @@ exports.default = (0, utils_1.createRule)("shorthand-attribute", {
|
|
|
26
27
|
type: "layout",
|
|
27
28
|
},
|
|
28
29
|
create(context) {
|
|
29
|
-
var _a;
|
|
30
30
|
const sourceCode = context.getSourceCode();
|
|
31
|
-
const always =
|
|
31
|
+
const always = context.options[0]?.prefer !== "never";
|
|
32
32
|
return always
|
|
33
33
|
? {
|
|
34
34
|
SvelteAttribute(node) {
|
|
@@ -8,6 +8,7 @@ exports.default = (0, utils_1.createRule)("shorthand-directive", {
|
|
|
8
8
|
description: "enforce use of shorthand syntax in directives",
|
|
9
9
|
category: "Stylistic Issues",
|
|
10
10
|
recommended: false,
|
|
11
|
+
conflictWithPrettier: true,
|
|
11
12
|
},
|
|
12
13
|
fixable: "code",
|
|
13
14
|
schema: [
|
|
@@ -26,9 +27,8 @@ exports.default = (0, utils_1.createRule)("shorthand-directive", {
|
|
|
26
27
|
type: "layout",
|
|
27
28
|
},
|
|
28
29
|
create(context) {
|
|
29
|
-
var _a;
|
|
30
30
|
const sourceCode = context.getSourceCode();
|
|
31
|
-
const always =
|
|
31
|
+
const always = context.options[0]?.prefer !== "never";
|
|
32
32
|
function reportForAlways(node) {
|
|
33
33
|
context.report({
|
|
34
34
|
node,
|
|
@@ -7,6 +7,7 @@ exports.default = (0, utils_1.createRule)("spaced-html-comment", {
|
|
|
7
7
|
description: "enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment",
|
|
8
8
|
category: "Stylistic Issues",
|
|
9
9
|
recommended: false,
|
|
10
|
+
conflictWithPrettier: false,
|
|
10
11
|
},
|
|
11
12
|
fixable: "whitespace",
|
|
12
13
|
schema: [
|
|
@@ -26,7 +27,6 @@ exports.default = (0, utils_1.createRule)("spaced-html-comment", {
|
|
|
26
27
|
const requireSpace = context.options[0] !== "never";
|
|
27
28
|
return {
|
|
28
29
|
SvelteHTMLComment(node) {
|
|
29
|
-
var _a, _b;
|
|
30
30
|
if (!node.value.trim()) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -51,7 +51,7 @@ exports.default = (0, utils_1.createRule)("spaced-html-comment", {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
const beginSpaces =
|
|
54
|
+
const beginSpaces = /^[^\S\n\r]/u.exec(node.value)?.[0];
|
|
55
55
|
if (beginSpaces) {
|
|
56
56
|
context.report({
|
|
57
57
|
node,
|
|
@@ -64,7 +64,7 @@ exports.default = (0, utils_1.createRule)("spaced-html-comment", {
|
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
const endSpaces =
|
|
67
|
+
const endSpaces = /(?<=\S)[^\S\n\r]$/u.exec(node.value)?.[0];
|
|
68
68
|
if (endSpaces) {
|
|
69
69
|
context.report({
|
|
70
70
|
node,
|
package/lib/rules/system.js
CHANGED
|
@@ -15,14 +15,13 @@ exports.default = (0, utils_1.createRule)("system", {
|
|
|
15
15
|
type: "problem",
|
|
16
16
|
},
|
|
17
17
|
create(context) {
|
|
18
|
-
var _a, _b;
|
|
19
18
|
const shared = (0, shared_1.getShared)(context.getFilename());
|
|
20
19
|
if (!shared)
|
|
21
20
|
return {};
|
|
22
21
|
const directives = shared.newCommentDirectives({
|
|
23
22
|
ruleId: "svelte/system",
|
|
24
23
|
});
|
|
25
|
-
const ignoreWarnings =
|
|
24
|
+
const ignoreWarnings = context.settings?.svelte?.ignoreWarnings;
|
|
26
25
|
if (ignoreWarnings && !Array.isArray(ignoreWarnings)) {
|
|
27
26
|
context.report({
|
|
28
27
|
loc: { line: 1, column: 0 },
|