eslint-plugin-svelte 2.1.1 → 2.3.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.
Files changed (46) hide show
  1. package/README.md +7 -2
  2. package/lib/configs/prettier.d.ts +15 -0
  3. package/lib/configs/prettier.js +21 -0
  4. package/lib/index.d.ts +14 -0
  5. package/lib/index.js +2 -0
  6. package/lib/rules/button-has-type.js +6 -2
  7. package/lib/rules/first-attribute-linebreak.js +3 -3
  8. package/lib/rules/html-closing-bracket-spacing.d.ts +2 -0
  9. package/lib/rules/html-closing-bracket-spacing.js +92 -0
  10. package/lib/rules/html-quotes.js +4 -4
  11. package/lib/rules/indent-helpers/commons.d.ts +1 -0
  12. package/lib/rules/indent-helpers/es.js +4 -1
  13. package/lib/rules/indent-helpers/index.js +22 -4
  14. package/lib/rules/indent-helpers/offset-context.js +2 -4
  15. package/lib/rules/indent-helpers/svelte.js +1 -1
  16. package/lib/rules/indent-helpers/ts.js +7 -2
  17. package/lib/rules/indent.js +2 -0
  18. package/lib/rules/max-attributes-per-line.js +4 -5
  19. package/lib/rules/mustache-spacing.js +6 -6
  20. package/lib/rules/no-inner-declarations.js +1 -2
  21. package/lib/rules/no-spaces-around-equal-signs-in-attribute.d.ts +2 -0
  22. package/lib/rules/no-spaces-around-equal-signs-in-attribute.js +49 -0
  23. package/lib/rules/no-unknown-style-directive-property.js +2 -3
  24. package/lib/rules/no-unused-svelte-ignore.js +3 -0
  25. package/lib/rules/prefer-class-directive.js +5 -1
  26. package/lib/rules/prefer-style-directive.js +1 -0
  27. package/lib/rules/require-optimized-style-attribute.js +1 -2
  28. package/lib/rules/shorthand-attribute.js +2 -2
  29. package/lib/rules/shorthand-directive.js +2 -2
  30. package/lib/rules/spaced-html-comment.js +3 -3
  31. package/lib/rules/system.js +1 -2
  32. package/lib/rules/valid-compile.js +1 -2
  33. package/lib/shared/comment-directives.js +2 -3
  34. package/lib/shared/index.js +2 -3
  35. package/lib/shared/svelte-compile-warns/index.js +22 -17
  36. package/lib/shared/svelte-compile-warns/transform/babel.js +1 -2
  37. package/lib/shared/svelte-compile-warns/transform/load-module.js +9 -21
  38. package/lib/shared/svelte-compile-warns/transform/postcss.js +8 -6
  39. package/lib/shared/svelte-compile-warns/transform/typescript.js +1 -1
  40. package/lib/types.d.ts +8 -2
  41. package/lib/utils/css-utils/style-attribute.js +12 -8
  42. package/lib/utils/css-utils/utils.js +1 -2
  43. package/lib/utils/eslint-core.js +1 -2
  44. package/lib/utils/index.js +9 -1
  45. package/lib/utils/rules.js +4 -0
  46. package/package.json +18 -11
package/README.md CHANGED
@@ -35,7 +35,7 @@ The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with t
35
35
 
36
36
  ## Migration Guide
37
37
 
38
- To migrate from `eslint-plugin-svelte` v1, or `@ota-meshi/eslint-plugin-svelte`, please refer to the [migration guide](https://ota-meshi.github.io/eslint-plugin-svelte/migration/).
38
+ To migrate from `eslint-plugin-svelte` v1, or [`@ota-meshi/eslint-plugin-svelte`](https://www.npmjs.com/package/@ota-meshi/eslint-plugin-svelte), please refer to the [migration guide](https://ota-meshi.github.io/eslint-plugin-svelte/migration/).
39
39
 
40
40
  ## :book: Documentation
41
41
 
@@ -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
 
@@ -291,10 +292,12 @@ These rules relate to style guidelines, and are therefore quite subjective:
291
292
  | Rule ID | Description | |
292
293
  |:--------|:------------|:---|
293
294
  | [svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
295
+ | [svelte/html-closing-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-closing-bracket-spacing/) | require or disallow a space before tag's closing brackets | :wrench: |
294
296
  | [svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes/) | enforce quotes style of HTML attributes | :wrench: |
295
297
  | [svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent/) | enforce consistent indentation | :wrench: |
296
298
  | [svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line/) | enforce the maximum number of attributes per line | :wrench: |
297
299
  | [svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing/) | enforce unified spacing in mustache | :wrench: |
300
+ | [svelte/no-spaces-around-equal-signs-in-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-spaces-around-equal-signs-in-attribute/) | disallow spaces around equal signs in attribute | :wrench: |
298
301
  | [svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive/) | require class directives instead of ternary expressions | :wrench: |
299
302
  | [svelte/prefer-style-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-style-directive/) | require style directives instead of style attribute | :wrench: |
300
303
  | [svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute/) | enforce use of shorthand syntax in attribute | :wrench: |
@@ -333,7 +336,9 @@ Please use GitHub's Issues/PRs.
333
336
 
334
337
  - `yarn test` runs tests.
335
338
  - `yarn cover` runs tests and measures coverage.
339
+ - `yarn new [new-rule-name]` generate the files needed to implement the new rule.
336
340
  - `yarn update` runs in order to update readme and recommended configuration.
341
+ - `yarn docs:watch` launch the document site in development mode.
337
342
 
338
343
  ### Test the Rule
339
344
 
@@ -360,7 +365,7 @@ If you want to test only one rule, run the following command (for `indent` rule)
360
365
  yarn test -g indent
361
366
  ```
362
367
 
363
- Take https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha as reference for details.
368
+ Take <https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha> as reference for details.
364
369
 
365
370
  If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
366
371
  (Note that `{"only": true}` must be removed before making a pull request.)
@@ -0,0 +1,15 @@
1
+ declare const _default: {
2
+ extends: string[];
3
+ rules: {
4
+ "svelte/first-attribute-linebreak": string;
5
+ "svelte/html-closing-bracket-spacing": string;
6
+ "svelte/html-quotes": string;
7
+ "svelte/indent": string;
8
+ "svelte/max-attributes-per-line": string;
9
+ "svelte/mustache-spacing": string;
10
+ "svelte/no-spaces-around-equal-signs-in-attribute": string;
11
+ "svelte/shorthand-attribute": string;
12
+ "svelte/shorthand-directive": string;
13
+ };
14
+ };
15
+ export = _default;
@@ -0,0 +1,21 @@
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-closing-bracket-spacing": "off",
13
+ "svelte/html-quotes": "off",
14
+ "svelte/indent": "off",
15
+ "svelte/max-attributes-per-line": "off",
16
+ "svelte/mustache-spacing": "off",
17
+ "svelte/no-spaces-around-equal-signs-in-attribute": "off",
18
+ "svelte/shorthand-attribute": "off",
19
+ "svelte/shorthand-directive": "off",
20
+ },
21
+ };
package/lib/index.d.ts CHANGED
@@ -33,6 +33,20 @@ 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-closing-bracket-spacing": string;
41
+ "svelte/html-quotes": string;
42
+ "svelte/indent": string;
43
+ "svelte/max-attributes-per-line": string;
44
+ "svelte/mustache-spacing": string;
45
+ "svelte/no-spaces-around-equal-signs-in-attribute": string;
46
+ "svelte/shorthand-attribute": string;
47
+ "svelte/shorthand-directive": string;
48
+ };
49
+ };
36
50
  };
37
51
  rules: {
38
52
  [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
- var _a;
39
- const configuration = Object.assign({ button: true, submit: true, reset: true }, ((_a = context.options[0]) !== null && _a !== void 0 ? _a : {}));
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
  }
@@ -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
- var _a, _b;
30
- const multiline = ((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.multiline) || "below";
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({
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ exports.default = (0, utils_1.createRule)("html-closing-bracket-spacing", {
5
+ meta: {
6
+ docs: {
7
+ description: "require or disallow a space before tag's closing brackets",
8
+ category: "Stylistic Issues",
9
+ conflictWithPrettier: true,
10
+ recommended: false,
11
+ },
12
+ schema: [
13
+ {
14
+ type: "object",
15
+ properties: {
16
+ startTag: {
17
+ enum: ["always", "never", "ignore"],
18
+ },
19
+ endTag: {
20
+ enum: ["always", "never", "ignore"],
21
+ },
22
+ selfClosingTag: {
23
+ enum: ["always", "never", "ignore"],
24
+ },
25
+ },
26
+ additionalProperties: false,
27
+ },
28
+ ],
29
+ messages: {
30
+ expectedSpace: "Expected space before '>', but not found.",
31
+ unexpectedSpace: "Expected no space before '>', but found.",
32
+ },
33
+ fixable: "whitespace",
34
+ type: "layout",
35
+ },
36
+ create(ctx) {
37
+ const options = {
38
+ startTag: "never",
39
+ endTag: "never",
40
+ selfClosingTag: "always",
41
+ ...ctx.options[0],
42
+ };
43
+ const src = ctx.getSourceCode();
44
+ function containsNewline(string) {
45
+ return string.includes("\n");
46
+ }
47
+ function report(node, shouldHave) {
48
+ const tagSrc = src.getText(node);
49
+ const match = /(\s*)\/?>$/.exec(tagSrc);
50
+ const end = node.range[1];
51
+ const start = node.range[1] - match[0].length;
52
+ const loc = {
53
+ start: src.getLocFromIndex(start),
54
+ end: src.getLocFromIndex(end),
55
+ };
56
+ ctx.report({
57
+ loc,
58
+ messageId: shouldHave ? "expectedSpace" : "unexpectedSpace",
59
+ *fix(fixer) {
60
+ if (shouldHave) {
61
+ yield fixer.insertTextBeforeRange([start, end], " ");
62
+ }
63
+ else {
64
+ const spaces = match[1];
65
+ yield fixer.removeRange([start, start + spaces.length]);
66
+ }
67
+ },
68
+ });
69
+ }
70
+ return {
71
+ "SvelteStartTag, SvelteEndTag"(node) {
72
+ const tagType = node.type === "SvelteEndTag"
73
+ ? "endTag"
74
+ : node.selfClosing
75
+ ? "selfClosingTag"
76
+ : "startTag";
77
+ if (options[tagType] === "ignore")
78
+ return;
79
+ const tagSrc = src.getText(node);
80
+ const match = /(\s*)\/?>$/.exec(tagSrc);
81
+ if (containsNewline(match[1]))
82
+ return;
83
+ if (options[tagType] === "always" && !match[1]) {
84
+ report(node, true);
85
+ }
86
+ else if (options[tagType] === "never" && match[1]) {
87
+ report(node, false);
88
+ }
89
+ },
90
+ };
91
+ },
92
+ });
@@ -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 = (_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.prefer) !== null && _b !== void 0 ? _b : "double";
51
- const dynamicQuote = ((_d = (_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.dynamic) === null || _d === void 0 ? void 0 : _d.quoted)
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((_f = (_e = context.options[0]) === null || _e === void 0 ? void 0 : _e.dynamic) === null || _f === void 0 ? void 0 : _f.avoidInvalidUnquotedInHTML);
54
+ const avoidInvalidUnquotedInHTML = Boolean(context.options[0]?.dynamic?.avoidInvalidUnquotedInHTML);
55
55
  function canBeUnquotedInHTML(text) {
56
56
  return !/[\s"'<=>`]/u.test(text);
57
57
  }
@@ -9,6 +9,7 @@ export declare type MaybeNode = {
9
9
  };
10
10
  export declare type IndentOptions = {
11
11
  indentChar: " " | "\t";
12
+ indentScript: boolean;
12
13
  indentSize: number;
13
14
  switchCase: number;
14
15
  alignAttributesVertically: boolean;
@@ -729,7 +729,10 @@ function defineVisitor(context) {
729
729
  },
730
730
  };
731
731
  const v = visitor;
732
- return Object.assign(Object.assign({}, v), commonVisitor);
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 = Object.assign({ indentChar: " ", indentSize: 2, switchCase: 1, alignAttributesVertically: false, ignoredNodes: [] }, defaultOptions);
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 = Object.assign(Object.assign(Object.assign({}, ES.defineVisitor(indentContext)), SV.defineVisitor(indentContext)), TS.defineVisitor(indentContext));
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(Object.assign(Object.assign({}, nodesVisitor), { "*:exit"(node) {
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 = (_a = this.ignoreRanges.get(range[0])) !== null && _a !== void 0 ? _a : 0;
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 = (_a = offsetInfo.expectedIndent) !== null && _a !== void 0 ? _a : 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[(decorators === null || decorators === void 0 ? void 0 : decorators.length) - 1]);
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 Object.assign(Object.assign(Object.assign(Object.assign({}, v), commonsVisitor), extendsESVisitor), deprecatedVisitor);
733
+ return {
734
+ ...v,
735
+ ...commonsVisitor,
736
+ ...extendsESVisitor,
737
+ ...deprecatedVisitor,
738
+ };
734
739
  }
735
740
  exports.defineVisitor = defineVisitor;
@@ -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 (((_b = (_a = group[0]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.loc.end.line) === attr.loc.start.line) {
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
- var _a, _b, _c, _d;
51
- const multilineMaximum = (_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.multiline) !== null && _b !== void 0 ? _b : 1;
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: (options === null || options === void 0 ? void 0 : options.textExpressions) || "never",
11
- attributesAndProps: (options === null || options === void 0 ? void 0 : options.attributesAndProps) || "never",
12
- directiveExpressions: (options === null || options === void 0 ? void 0 : options.directiveExpressions) || "never",
9
+ textExpressions: options?.textExpressions || "never",
10
+ attributesAndProps: options?.attributesAndProps || "never",
11
+ directiveExpressions: options?.directiveExpressions || "never",
13
12
  tags: {
14
- openingBrace: ((_a = options === null || options === void 0 ? void 0 : options.tags) === null || _a === void 0 ? void 0 : _a.openingBrace) || "never",
15
- closingBrace: ((_b = options === null || options === void 0 ? void 0 : options.tags) === null || _b === void 0 ? void 0 : _b.closingBrace) || "never",
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
- var _a;
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;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ exports.default = (0, utils_1.createRule)("no-spaces-around-equal-signs-in-attribute", {
5
+ meta: {
6
+ docs: {
7
+ description: "disallow spaces around equal signs in attribute",
8
+ category: "Stylistic Issues",
9
+ recommended: false,
10
+ conflictWithPrettier: true,
11
+ },
12
+ schema: {},
13
+ fixable: "whitespace",
14
+ messages: {
15
+ noSpaces: "Unexpected spaces found around equal signs.",
16
+ },
17
+ type: "layout",
18
+ },
19
+ create(ctx) {
20
+ const source = ctx.getSourceCode();
21
+ function getAttrEq(node) {
22
+ const keyRange = node.key.range;
23
+ const eqSource = /^[\s=]*/u.exec(source.text.slice(keyRange[1], node.range[1]))[0];
24
+ const valueStart = keyRange[1] + eqSource.length;
25
+ return [eqSource, [keyRange[1], valueStart]];
26
+ }
27
+ function containsWhitespace(string) {
28
+ return /\s/u.test(string);
29
+ }
30
+ return {
31
+ "SvelteAttribute, SvelteDirective, SvelteStyleDirective, SvelteSpecialDirective"(node) {
32
+ const [eqSource, range] = getAttrEq(node);
33
+ if (!containsWhitespace(eqSource))
34
+ return;
35
+ const loc = {
36
+ start: source.getLocFromIndex(range[0]),
37
+ end: source.getLocFromIndex(range[1]),
38
+ };
39
+ ctx.report({
40
+ loc,
41
+ messageId: "noSpaces",
42
+ *fix(fixer) {
43
+ yield fixer.replaceTextRange(range, "=");
44
+ },
45
+ });
46
+ },
47
+ };
48
+ },
49
+ });
@@ -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
- ...((_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.ignoreProperties) !== null && _b !== void 0 ? _b : []),
38
+ ...(context.options[0]?.ignoreProperties ?? []),
40
39
  ].map(regexp_1.toRegExp);
41
- const ignorePrefixed = (_d = (_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.ignorePrefixed) !== null && _d !== void 0 ? _d : true;
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("--") ||
@@ -18,6 +18,9 @@ exports.default = (0, utils_1.createRule)("no-unused-svelte-ignore", {
18
18
  type: "suggestion",
19
19
  },
20
20
  create(context) {
21
+ if (!context.parserServices.isSvelte) {
22
+ return {};
23
+ }
21
24
  const sourceCode = context.getSourceCode();
22
25
  const ignoreComments = [];
23
26
  for (const item of (0, ignore_comment_1.getSvelteIgnoreItems)(context)) {
@@ -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(Object.assign(Object.assign({}, key), { chains: expr }), str);
43
+ result.set({
44
+ ...key,
45
+ chains: expr,
46
+ }, str);
43
47
  }
44
48
  }
45
49
  else {
@@ -12,6 +12,7 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
12
12
  description: "require style directives instead of style attribute",
13
13
  category: "Stylistic Issues",
14
14
  recommended: false,
15
+ conflictWithPrettier: false,
15
16
  },
16
17
  fixable: "code",
17
18
  schema: [],
@@ -30,8 +30,7 @@ exports.default = (0, utils_1.createRule)("require-optimized-style-attribute", {
30
30
  });
31
31
  },
32
32
  SvelteAttribute(node) {
33
- var _a;
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);