eslint-plugin-svelte 2.1.0 → 2.3.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.
Files changed (47) hide show
  1. package/README.md +36 -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/prefer-class-directive.js +8 -3
  25. package/lib/rules/prefer-style-directive.js +4 -12
  26. package/lib/rules/require-optimized-style-attribute.js +1 -2
  27. package/lib/rules/shorthand-attribute.js +2 -2
  28. package/lib/rules/shorthand-directive.js +2 -2
  29. package/lib/rules/spaced-html-comment.js +3 -3
  30. package/lib/rules/system.js +1 -2
  31. package/lib/rules/valid-compile.js +1 -2
  32. package/lib/shared/comment-directives.js +2 -3
  33. package/lib/shared/index.js +2 -3
  34. package/lib/shared/svelte-compile-warns/index.js +22 -17
  35. package/lib/shared/svelte-compile-warns/transform/babel.js +1 -2
  36. package/lib/shared/svelte-compile-warns/transform/load-module.js +9 -21
  37. package/lib/shared/svelte-compile-warns/transform/postcss.js +8 -6
  38. package/lib/shared/svelte-compile-warns/transform/typescript.js +1 -1
  39. package/lib/types.d.ts +8 -2
  40. package/lib/utils/ast-utils.d.ts +5 -0
  41. package/lib/utils/ast-utils.js +15 -1
  42. package/lib/utils/css-utils/style-attribute.js +12 -8
  43. package/lib/utils/css-utils/utils.js +1 -2
  44. package/lib/utils/eslint-core.js +1 -2
  45. package/lib/utils/index.js +9 -1
  46. package/lib/utils/rules.js +4 -0
  47. package/package.json +18 -12
@@ -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 (!isHTMLElement(node.parent.parent) || node.key.name !== "style") {
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);
@@ -149,16 +152,5 @@ exports.default = (0, utils_1.createRule)("prefer-style-directive", {
149
152
  }
150
153
  },
151
154
  };
152
- function isHTMLElement(node) {
153
- if (node.type === "SvelteElement") {
154
- if (node.kind === "html") {
155
- return true;
156
- }
157
- if (node.kind === "special") {
158
- return node.name.name === "svelte:element";
159
- }
160
- }
161
- return false;
162
- }
163
155
  },
164
156
  });
@@ -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);
@@ -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 = ((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.prefer) !== "never";
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 = ((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.prefer) !== "never";
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 = (_a = /^[^\S\n\r]/u.exec(node.value)) === null || _a === void 0 ? void 0 : _a[0];
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 = (_b = /(?<=\S)[^\S\n\r]$/u.exec(node.value)) === null || _b === void 0 ? void 0 : _b[0];
67
+ const endSpaces = /(?<=\S)[^\S\n\r]$/u.exec(node.value)?.[0];
68
68
  if (endSpaces) {
69
69
  context.report({
70
70
  node,
@@ -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 = (_b = (_a = context.settings) === null || _a === void 0 ? void 0 : _a.svelte) === null || _b === void 0 ? void 0 : _b.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 },
@@ -22,11 +22,10 @@ exports.default = (0, utils_1.createRule)("valid-compile", {
22
22
  type: "problem",
23
23
  },
24
24
  create(context) {
25
- var _a;
26
25
  if (!context.parserServices.isSvelte) {
27
26
  return {};
28
27
  }
29
- const ignoreWarnings = Boolean((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.ignoreWarnings);
28
+ const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings);
30
29
  const ignores = ["missing-declaration", "dynamic-slot-name"];
31
30
  function report(warnings) {
32
31
  for (const warn of warnings) {
@@ -8,7 +8,7 @@ class CommentDirectives {
8
8
  this.lineDisableDirectives = new Map();
9
9
  this.blockDirectives = new Map();
10
10
  this.ruleId = options.ruleId;
11
- this.reportUnusedDisableDirectives = Boolean(options === null || options === void 0 ? void 0 : options.reportUnusedDisableDirectives);
11
+ this.reportUnusedDisableDirectives = Boolean(options?.reportUnusedDisableDirectives);
12
12
  }
13
13
  filterMessages(messages) {
14
14
  const { lineDisableDirectives, blockDirectives, reportUnusedDisableDirectives, } = this;
@@ -61,12 +61,11 @@ class CommentDirectives {
61
61
  }
62
62
  return filteredMessages;
63
63
  function isEnable(message) {
64
- var _a;
65
64
  if (!message.ruleId) {
66
65
  return true;
67
66
  }
68
67
  for (const disableLines of getFromRule(lineDisableDirectives, message.ruleId)) {
69
- for (const disableLine of (_a = disableLines.get(message.line)) !== null && _a !== void 0 ? _a : []) {
68
+ for (const disableLine of disableLines.get(message.line) ?? []) {
70
69
  if (!disableLine.rule(message.ruleId)) {
71
70
  continue;
72
71
  }
@@ -21,11 +21,10 @@ exports.beginShared = beginShared;
21
21
  function terminateShared(filename) {
22
22
  const result = sharedMap.get(filename);
23
23
  sharedMap.delete(filename);
24
- return result !== null && result !== void 0 ? result : null;
24
+ return result ?? null;
25
25
  }
26
26
  exports.terminateShared = terminateShared;
27
27
  function getShared(filename) {
28
- var _a;
29
- return (_a = sharedMap.get(filename)) !== null && _a !== void 0 ? _a : null;
28
+ return sharedMap.get(filename) ?? null;
30
29
  }
31
30
  exports.getShared = getShared;
@@ -91,7 +91,11 @@ function getSvelteCompileWarningsWithoutCache(context) {
91
91
  transformResults.push(...transformScripts(context));
92
92
  if (!transformResults.length) {
93
93
  const warnings = getWarningsFromCode(text);
94
- return Object.assign(Object.assign({}, processIgnore(warnings.warnings, warnings.kind, stripStyleElements, ignoreComments, context)), { kind: warnings.kind, stripStyleElements });
94
+ return {
95
+ ...processIgnore(warnings.warnings, warnings.kind, stripStyleElements, ignoreComments, context),
96
+ kind: warnings.kind,
97
+ stripStyleElements,
98
+ };
95
99
  }
96
100
  class RemapContext {
97
101
  constructor() {
@@ -131,20 +135,20 @@ function getSvelteCompileWarningsWithoutCache(context) {
131
135
  this.mapIndexes.push({
132
136
  range: [codeStart, this.code.length],
133
137
  remap: (index) => {
134
- outputLocs = outputLocs !== null && outputLocs !== void 0 ? outputLocs : new lines_and_columns_1.LinesAndColumns(outputText);
135
- inputLocs = inputLocs !== null && inputLocs !== void 0 ? inputLocs : new lines_and_columns_1.LinesAndColumns(inputText);
138
+ outputLocs = outputLocs ?? new lines_and_columns_1.LinesAndColumns(outputText);
139
+ inputLocs = inputLocs ?? new lines_and_columns_1.LinesAndColumns(inputText);
136
140
  const outputCodePos = outputLocs.getLocFromIndex(index - codeStart);
137
141
  const inputCodePos = remapPosition(outputCodePos);
138
142
  return inputLocs.getIndexFromLoc(inputCodePos) + start;
139
143
  },
140
144
  });
141
145
  function remapPosition(pos) {
142
- decoded = decoded !== null && decoded !== void 0 ? decoded : (0, sourcemap_codec_1.decode)(output.mappings);
146
+ decoded = decoded ?? (0, sourcemap_codec_1.decode)(output.mappings);
143
147
  const lineMaps = decoded[pos.line - 1];
144
- if (!(lineMaps === null || lineMaps === void 0 ? void 0 : lineMaps.length)) {
148
+ if (!lineMaps?.length) {
145
149
  for (let line = pos.line - 1; line >= 0; line--) {
146
150
  const prevLineMaps = decoded[line];
147
- if (prevLineMaps === null || prevLineMaps === void 0 ? void 0 : prevLineMaps.length) {
151
+ if (prevLineMaps?.length) {
148
152
  const [, , sourceCodeLine, sourceCodeColumn] = prevLineMaps[prevLineMaps.length - 1];
149
153
  return {
150
154
  line: sourceCodeLine + 1,
@@ -172,9 +176,8 @@ function getSvelteCompileWarningsWithoutCache(context) {
172
176
  }
173
177
  }
174
178
  remapLocs(points) {
175
- var _a;
176
179
  const mapIndexes = this.mapIndexes;
177
- const locs = (this.locs = (_a = this.locs) !== null && _a !== void 0 ? _a : new lines_and_columns_1.LinesAndColumns(this.code));
180
+ const locs = (this.locs = this.locs ?? new lines_and_columns_1.LinesAndColumns(this.code));
178
181
  let start = undefined;
179
182
  let end = undefined;
180
183
  if (points.start) {
@@ -229,7 +232,11 @@ function getSvelteCompileWarningsWithoutCache(context) {
229
232
  },
230
233
  });
231
234
  }
232
- return Object.assign(Object.assign({}, processIgnore(warnings, baseWarnings.kind, stripStyleElements, ignoreComments, context)), { kind: baseWarnings.kind, stripStyleElements });
235
+ return {
236
+ ...processIgnore(warnings, baseWarnings.kind, stripStyleElements, ignoreComments, context),
237
+ kind: baseWarnings.kind,
238
+ stripStyleElements,
239
+ };
233
240
  }
234
241
  function* extractStyleElementsWithLangOtherThanCSS(context) {
235
242
  const sourceCode = context.getSourceCode();
@@ -376,18 +383,17 @@ function processIgnore(warnings, kind, stripStyleElements, ignoreComments, conte
376
383
  if (start != null && end != null) {
377
384
  return Math.floor(start + (end - start) / 2);
378
385
  }
379
- return start !== null && start !== void 0 ? start : end;
386
+ return start ?? end;
380
387
  }
381
388
  }
382
389
  function isUseTypeScript(context) {
383
- var _a;
384
390
  if (context.parserServices.esTreeNodeToTSNodeMap)
385
391
  return true;
386
392
  const sourceCode = context.getSourceCode();
387
393
  const root = sourceCode.ast;
388
394
  for (const node of root.body) {
389
395
  if (node.type === "SvelteScriptElement") {
390
- const lang = (_a = (0, ast_utils_1.getLangValue)(node)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
396
+ const lang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase();
391
397
  if (lang === "ts" || lang === "typescript") {
392
398
  return true;
393
399
  }
@@ -396,8 +402,7 @@ function isUseTypeScript(context) {
396
402
  return false;
397
403
  }
398
404
  function isUseBabel(context) {
399
- var _a, _b, _c;
400
- const parser = (_a = context.parserOptions) === null || _a === void 0 ? void 0 : _a.parser;
405
+ const parser = context.parserOptions?.parser;
401
406
  if (!parser) {
402
407
  return false;
403
408
  }
@@ -406,7 +411,7 @@ function isUseBabel(context) {
406
411
  let scriptLang = "js";
407
412
  for (const node of root.body) {
408
413
  if (node.type === "SvelteScriptElement") {
409
- const lang = (_b = (0, ast_utils_1.getLangValue)(node)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
414
+ const lang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase();
410
415
  if (lang === "ts" || lang === "typescript") {
411
416
  scriptLang = lang;
412
417
  break;
@@ -426,10 +431,10 @@ function isUseBabel(context) {
426
431
  const pkgPath = path_1.default.join(targetPath, "package.json");
427
432
  if (fs_1.default.existsSync(pkgPath)) {
428
433
  try {
429
- return (((_c = JSON.parse(fs_1.default.readFileSync(pkgPath, "utf-8"))) === null || _c === void 0 ? void 0 : _c.name) ===
434
+ return (JSON.parse(fs_1.default.readFileSync(pkgPath, "utf-8"))?.name ===
430
435
  "@babel/eslint-parser");
431
436
  }
432
- catch (_d) {
437
+ catch {
433
438
  return false;
434
439
  }
435
440
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasBabel = exports.transform = void 0;
4
4
  const load_module_1 = require("./load-module");
5
5
  function transform(node, context) {
6
- var _a, _b;
7
6
  const babel = loadBabel(context);
8
7
  if (!babel) {
9
8
  return null;
@@ -23,7 +22,7 @@ function transform(node, context) {
23
22
  minified: false,
24
23
  ast: false,
25
24
  code: true,
26
- cwd: (_b = (_a = context.getCwd) === null || _a === void 0 ? void 0 : _a.call(context)) !== null && _b !== void 0 ? _b : process.cwd(),
25
+ cwd: context.getCwd?.() ?? process.cwd(),
27
26
  });
28
27
  if (!output) {
29
28
  return null;
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -41,7 +32,6 @@ const path_1 = __importDefault(require("path"));
41
32
  const cache = new WeakMap();
42
33
  const cache4b = new Map();
43
34
  function loadModule(context, name) {
44
- var _a, _b;
45
35
  const key = context.getSourceCode().ast;
46
36
  let modules = cache.get(key);
47
37
  if (!modules) {
@@ -52,23 +42,21 @@ function loadModule(context, name) {
52
42
  if (mod)
53
43
  return mod;
54
44
  try {
55
- const cwd = (_b = (_a = context.getCwd) === null || _a === void 0 ? void 0 : _a.call(context)) !== null && _b !== void 0 ? _b : process.cwd();
45
+ const cwd = context.getCwd?.() ?? process.cwd();
56
46
  const relativeTo = path_1.default.join(cwd, "__placeholder__.js");
57
47
  return (modules[name] = module_1.default.createRequire(relativeTo)(name));
58
48
  }
59
- catch (_c) {
49
+ catch {
60
50
  return null;
61
51
  }
62
52
  }
63
53
  exports.loadModule = loadModule;
64
- function loadModulesForBrowser() {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const [sass, typescript] = yield Promise.all([
67
- Promise.resolve().then(() => __importStar(require("sass"))),
68
- Promise.resolve().then(() => __importStar(require("typescript"))),
69
- ]);
70
- cache4b.set("sass", sass);
71
- cache4b.set("typescript", typescript);
72
- });
54
+ async function loadModulesForBrowser() {
55
+ const [sass, typescript] = await Promise.all([
56
+ Promise.resolve().then(() => __importStar(require("sass"))),
57
+ Promise.resolve().then(() => __importStar(require("typescript"))),
58
+ ]);
59
+ cache4b.set("sass", sass);
60
+ cache4b.set("typescript", typescript);
73
61
  }
74
62
  exports.loadModulesForBrowser = loadModulesForBrowser;
@@ -7,8 +7,7 @@ exports.transform = void 0;
7
7
  const postcss_1 = __importDefault(require("postcss"));
8
8
  const postcss_load_config_1 = __importDefault(require("postcss-load-config"));
9
9
  function transform(node, context) {
10
- var _a, _b, _c, _d, _e;
11
- const postcssConfig = (_c = (_b = (_a = context.settings) === null || _a === void 0 ? void 0 : _a.svelte) === null || _b === void 0 ? void 0 : _b.compileOptions) === null || _c === void 0 ? void 0 : _c.postcss;
10
+ const postcssConfig = context.settings?.svelte?.compileOptions?.postcss;
12
11
  if (postcssConfig === false) {
13
12
  return null;
14
13
  }
@@ -22,14 +21,17 @@ function transform(node, context) {
22
21
  const code = context.getSourceCode().text.slice(...inputRange);
23
22
  const filename = `${context.getFilename()}.css`;
24
23
  try {
25
- const configFilePath = postcssConfig === null || postcssConfig === void 0 ? void 0 : postcssConfig.configFilePath;
24
+ const configFilePath = postcssConfig?.configFilePath;
26
25
  const config = postcss_load_config_1.default.sync({
27
- cwd: (_e = (_d = context.getCwd) === null || _d === void 0 ? void 0 : _d.call(context)) !== null && _e !== void 0 ? _e : process.cwd(),
26
+ cwd: context.getCwd?.() ?? process.cwd(),
28
27
  from: filename,
29
28
  }, typeof configFilePath === "string" ? configFilePath : undefined);
30
- const result = (0, postcss_1.default)(config.plugins).process(code, Object.assign(Object.assign({}, config.options), { map: {
29
+ const result = (0, postcss_1.default)(config.plugins).process(code, {
30
+ ...config.options,
31
+ map: {
31
32
  inline: false,
32
- } }));
33
+ },
34
+ });
33
35
  return {
34
36
  inputRange,
35
37
  output: result.content,
@@ -30,7 +30,7 @@ function transform(node, context) {
30
30
  mappings: JSON.parse(output.sourceMapText).mappings,
31
31
  };
32
32
  }
33
- catch (_a) {
33
+ catch {
34
34
  return null;
35
35
  }
36
36
  }
package/lib/types.d.ts CHANGED
@@ -27,6 +27,7 @@ export interface RuleMetaData {
27
27
  ruleId: string;
28
28
  ruleName: string;
29
29
  default?: "error" | "warn";
30
+ conflictWithPrettier?: boolean;
30
31
  };
31
32
  messages: {
32
33
  [messageId: string]: string;
@@ -44,11 +45,16 @@ export interface PartialRuleModule {
44
45
  export interface PartialRuleMetaData {
45
46
  docs: {
46
47
  description: string;
47
- category: RuleCategory;
48
48
  recommended: boolean | "base";
49
49
  extensionRule?: string;
50
50
  default?: "error" | "warn";
51
- };
51
+ } & ({
52
+ category: Exclude<RuleCategory, "Stylistic Issues">;
53
+ conflictWithPrettier?: boolean;
54
+ } | {
55
+ category: "Stylistic Issues";
56
+ conflictWithPrettier: boolean;
57
+ });
52
58
  messages: {
53
59
  [messageId: string]: string;
54
60
  };
@@ -5,6 +5,11 @@ import type { Scope } from "eslint";
5
5
  export declare function equalTokens(left: ASTNode, right: ASTNode, sourceCode: SourceCode): boolean;
6
6
  export declare function getStringIfConstant(node: ESTree.Expression): string | null;
7
7
  export declare function needParentheses(node: ESTree.Expression, kind: "not" | "logical"): boolean;
8
+ export declare function isHTMLElementLike(node: SvAST.SvelteElement | SvAST.SvelteScriptElement | SvAST.SvelteStyleElement): node is SvAST.SvelteHTMLElement | (SvAST.SvelteSpecialElement & {
9
+ name: SvAST.SvelteName & {
10
+ name: "svelte:element";
11
+ };
12
+ });
8
13
  export declare function findAttribute<N extends string>(node: SvAST.SvelteElement | SvAST.SvelteScriptElement | SvAST.SvelteStyleElement | SvAST.SvelteStartTag, name: N): (SvAST.SvelteAttribute & {
9
14
  key: SvAST.SvelteAttribute["key"] & {
10
15
  name: N;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getMustacheTokens = exports.getAttributeValueQuoteAndRange = exports.getScope = exports.findVariable = exports.getLangValue = exports.getStaticAttributeValue = exports.findBindDirective = exports.findShorthandAttribute = exports.findAttribute = exports.needParentheses = exports.getStringIfConstant = exports.equalTokens = void 0;
26
+ exports.getMustacheTokens = exports.getAttributeValueQuoteAndRange = exports.getScope = exports.findVariable = exports.getLangValue = exports.getStaticAttributeValue = exports.findBindDirective = exports.findShorthandAttribute = exports.findAttribute = exports.isHTMLElementLike = exports.needParentheses = exports.getStringIfConstant = exports.equalTokens = void 0;
27
27
  const eslintUtils = __importStar(require("eslint-utils"));
28
28
  function equalTokens(left, right, sourceCode) {
29
29
  const tokensL = sourceCode.getTokens(left);
@@ -95,6 +95,20 @@ function needParentheses(node, kind) {
95
95
  return false;
96
96
  }
97
97
  exports.needParentheses = needParentheses;
98
+ function isHTMLElementLike(node) {
99
+ if (node.type !== "SvelteElement") {
100
+ return false;
101
+ }
102
+ switch (node.kind) {
103
+ case "html":
104
+ return true;
105
+ case "special":
106
+ return node.name.name === "svelte:element";
107
+ default:
108
+ return false;
109
+ }
110
+ }
111
+ exports.isHTMLElementLike = isHTMLElementLike;
98
112
  function findAttribute(node, name) {
99
113
  const startTag = node.type === "SvelteStartTag" ? node : node.startTag;
100
114
  for (const attr of startTag.attributes) {
@@ -13,18 +13,17 @@ function safeParseCss(css) {
13
13
  parser.parse();
14
14
  return parser.root;
15
15
  }
16
- catch (_a) {
16
+ catch {
17
17
  return null;
18
18
  }
19
19
  }
20
20
  const cache = new WeakMap();
21
21
  function parseStyleAttributeValue(node, context) {
22
- var _a;
23
22
  if (cache.has(node)) {
24
23
  return cache.get(node) || null;
25
24
  }
26
25
  cache.set(node, null);
27
- if (!((_a = node.value) === null || _a === void 0 ? void 0 : _a.length)) {
26
+ if (!node.value?.length) {
28
27
  return null;
29
28
  }
30
29
  const startOffset = node.value[0].range[0];
@@ -92,7 +91,7 @@ function convertRoot(root, interpolations, getRange, ctx) {
92
91
  if (range) {
93
92
  return range;
94
93
  }
95
- return range !== null && range !== void 0 ? range : (range = getRange(tagOrExpr));
94
+ return range ?? (range = getRange(tagOrExpr));
96
95
  }
97
96
  return {
98
97
  type: "inline",
@@ -132,7 +131,10 @@ function convertRoot(root, interpolations, getRange, ctx) {
132
131
  if (!root) {
133
132
  return null;
134
133
  }
135
- converted = convertRoot(root, [], () => [0, 0], Object.assign(Object.assign({}, ctx), { startOffset: node.range[0] + 1 }));
134
+ converted = convertRoot(root, [], () => [0, 0], {
135
+ ...ctx,
136
+ startOffset: node.range[0] + 1,
137
+ });
136
138
  }
137
139
  else if (node.type === "TemplateLiteral") {
138
140
  const root = safeParseCss(sourceCode.getText(node).slice(1, -1));
@@ -145,7 +147,10 @@ function convertRoot(root, interpolations, getRange, ctx) {
145
147
  node.quasis[index].range[1] - 2,
146
148
  node.quasis[index + 1].range[0] + 1,
147
149
  ];
148
- }, Object.assign(Object.assign({}, ctx), { startOffset: node.range[0] + 1 }));
150
+ }, {
151
+ ...ctx,
152
+ startOffset: node.range[0] + 1,
153
+ });
149
154
  }
150
155
  else {
151
156
  return null;
@@ -175,14 +180,13 @@ function convertRoot(root, interpolations, getRange, ctx) {
175
180
  }
176
181
  }
177
182
  function convertChild(node, ctx) {
178
- var _a;
179
183
  const range = convertRange(node, ctx);
180
184
  if (node.type === "decl") {
181
185
  const propRange = [range[0], range[0] + node.prop.length];
182
186
  const declValueStartIndex = propRange[1] + (node.raws.between || "").length;
183
187
  const valueRange = [
184
188
  declValueStartIndex,
185
- declValueStartIndex + (((_a = node.raws.value) === null || _a === void 0 ? void 0 : _a.value) || node.value).length,
189
+ declValueStartIndex + (node.raws.value?.value || node.value).length,
186
190
  ];
187
191
  const prop = {
188
192
  name: node.prop,
@@ -6,8 +6,7 @@ function hasVendorPrefix(prop) {
6
6
  }
7
7
  exports.hasVendorPrefix = hasVendorPrefix;
8
8
  function getVendorPrefix(prop) {
9
- var _a;
10
- return ((_a = /^-\w+-/u.exec(prop)) === null || _a === void 0 ? void 0 : _a[0]) || "";
9
+ return /^-\w+-/u.exec(prop)?.[0] || "";
11
10
  }
12
11
  exports.getVendorPrefix = getVendorPrefix;
13
12
  function stripVendorPrefix(prop) {
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCoreRule = exports.buildProxyListener = exports.getProxyNode = exports.defineWrapperListener = void 0;
4
4
  const eslint_1 = require("eslint");
5
5
  function defineWrapperListener(coreRule, context, proxyOptions) {
6
- var _a, _b;
7
6
  const listener = coreRule.create(context);
8
- const svelteListener = (_b = (_a = proxyOptions.createListenerProxy) === null || _a === void 0 ? void 0 : _a.call(proxyOptions, listener)) !== null && _b !== void 0 ? _b : listener;
7
+ const svelteListener = proxyOptions.createListenerProxy?.(listener) ?? listener;
9
8
  return svelteListener;
10
9
  }
11
10
  exports.defineWrapperListener = defineWrapperListener;
@@ -3,7 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRule = void 0;
4
4
  function createRule(ruleName, rule) {
5
5
  return {
6
- meta: Object.assign(Object.assign({}, rule.meta), { docs: Object.assign(Object.assign({}, rule.meta.docs), { url: `https://ota-meshi.github.io/eslint-plugin-svelte/rules/${ruleName}/`, ruleId: `svelte/${ruleName}`, ruleName }) }),
6
+ meta: {
7
+ ...rule.meta,
8
+ docs: {
9
+ ...rule.meta.docs,
10
+ url: `https://ota-meshi.github.io/eslint-plugin-svelte/rules/${ruleName}/`,
11
+ ruleId: `svelte/${ruleName}`,
12
+ ruleName,
13
+ },
14
+ },
7
15
  create: rule.create,
8
16
  };
9
17
  }
@@ -7,6 +7,7 @@ exports.rules = void 0;
7
7
  const button_has_type_1 = __importDefault(require("../rules/button-has-type"));
8
8
  const comment_directive_1 = __importDefault(require("../rules/comment-directive"));
9
9
  const first_attribute_linebreak_1 = __importDefault(require("../rules/first-attribute-linebreak"));
10
+ const html_closing_bracket_spacing_1 = __importDefault(require("../rules/html-closing-bracket-spacing"));
10
11
  const html_quotes_1 = __importDefault(require("../rules/html-quotes"));
11
12
  const indent_1 = __importDefault(require("../rules/indent"));
12
13
  const max_attributes_per_line_1 = __importDefault(require("../rules/max-attributes-per-line"));
@@ -20,6 +21,7 @@ const no_inner_declarations_1 = __importDefault(require("../rules/no-inner-decla
20
21
  const no_not_function_handler_1 = __importDefault(require("../rules/no-not-function-handler"));
21
22
  const no_object_in_text_mustaches_1 = __importDefault(require("../rules/no-object-in-text-mustaches"));
22
23
  const no_shorthand_style_property_overrides_1 = __importDefault(require("../rules/no-shorthand-style-property-overrides"));
24
+ const no_spaces_around_equal_signs_in_attribute_1 = __importDefault(require("../rules/no-spaces-around-equal-signs-in-attribute"));
23
25
  const no_target_blank_1 = __importDefault(require("../rules/no-target-blank"));
24
26
  const no_unknown_style_directive_property_1 = __importDefault(require("../rules/no-unknown-style-directive-property"));
25
27
  const no_unused_svelte_ignore_1 = __importDefault(require("../rules/no-unused-svelte-ignore"));
@@ -36,6 +38,7 @@ exports.rules = [
36
38
  button_has_type_1.default,
37
39
  comment_directive_1.default,
38
40
  first_attribute_linebreak_1.default,
41
+ html_closing_bracket_spacing_1.default,
39
42
  html_quotes_1.default,
40
43
  indent_1.default,
41
44
  max_attributes_per_line_1.default,
@@ -49,6 +52,7 @@ exports.rules = [
49
52
  no_not_function_handler_1.default,
50
53
  no_object_in_text_mustaches_1.default,
51
54
  no_shorthand_style_property_overrides_1.default,
55
+ no_spaces_around_equal_signs_in_attribute_1.default,
52
56
  no_target_blank_1.default,
53
57
  no_unknown_style_directive_property_1.default,
54
58
  no_unused_svelte_ignore_1.default,