eslint-plugin-svelte 2.35.1 → 2.36.0-next.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 CHANGED
@@ -25,11 +25,17 @@ It provides many unique check rules using the AST generated by [svelte-eslint-pa
25
25
 
26
26
  ### ❗ Attention
27
27
 
28
+ #### Cannot be used with eslint-plugin-svelte3
29
+
28
30
  The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
29
31
 
30
32
  [svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser
31
33
  [eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3
32
34
 
35
+ #### Experimental support for Svelte v5
36
+
37
+ We are working on support for Svelte v5, but it is still an experimental feature. Please note that rules and features related to Svelte v5 may be changed or removed in minor versions without notice.
38
+
33
39
  <!--DOCS_IGNORE_START-->
34
40
 
35
41
  ## Migration Guide
package/lib/meta.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const name: "eslint-plugin-svelte";
2
- export declare const version: "2.35.1";
2
+ export declare const version: "2.36.0-next.1";
package/lib/meta.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = 'eslint-plugin-svelte';
5
- exports.version = '2.35.1';
5
+ exports.version = '2.36.0-next.1';
@@ -41,6 +41,7 @@ function isBeginningOfElement(node) {
41
41
  node.parent.type === 'SvelteElseBlock' ||
42
42
  node.parent.type === 'SvelteIfBlock' ||
43
43
  node.parent.type === 'SvelteKeyBlock' ||
44
+ node.parent.type === 'SvelteSnippetBlock' ||
44
45
  node.parent.type === 'SvelteStyleElement') {
45
46
  return node.parent.children[0] === node;
46
47
  }
@@ -5,6 +5,7 @@ const ast_1 = require("./ast");
5
5
  const commons_1 = require("./commons");
6
6
  const commons_2 = require("./commons");
7
7
  const commons_3 = require("./commons");
8
+ const eslint_utils_1 = require("@eslint-community/eslint-utils");
8
9
  const PREFORMATTED_ELEMENT_NAMES = ['pre', 'textarea', 'template'];
9
10
  function defineVisitor(context) {
10
11
  const { sourceCode, offsets, options } = context;
@@ -146,6 +147,20 @@ function defineVisitor(context) {
146
147
  offsets.setOffsetToken(declarationToken, 1, openToken);
147
148
  offsets.setOffsetToken(closeToken, 0, openToken);
148
149
  },
150
+ SvelteRenderTag(node) {
151
+ const openToken = sourceCode.getFirstToken(node);
152
+ const renderToken = sourceCode.getTokenAfter(openToken);
153
+ offsets.setOffsetToken(renderToken, 1, openToken);
154
+ const calleeToken = sourceCode.getFirstToken(node.callee);
155
+ offsets.setOffsetToken(calleeToken, 1, renderToken);
156
+ const leftParenToken = sourceCode.getTokenAfter(node.callee, {
157
+ filter: eslint_utils_1.isOpeningParenToken,
158
+ includeComments: false
159
+ });
160
+ const rightParenToken = sourceCode.getTokenBefore(sourceCode.getLastToken(node));
161
+ offsets.setOffsetToken(leftParenToken, 1, calleeToken);
162
+ offsets.setOffsetElementList([node.argument], leftParenToken, rightParenToken, 1);
163
+ },
149
164
  SvelteIfBlock(node) {
150
165
  const [openToken, ...ifTokens] = sourceCode.getFirstTokens(node, {
151
166
  count: node.elseif ? 3 : 2,
@@ -363,6 +378,25 @@ function defineVisitor(context) {
363
378
  offsets.setOffsetToken(endAwaitToken, 1, openCloseTagToken);
364
379
  offsets.setOffsetToken(closeCloseTagToken, 0, openCloseTagToken);
365
380
  },
381
+ SvelteSnippetBlock(node) {
382
+ const [openToken, snippetToken] = sourceCode.getFirstTokens(node, {
383
+ count: 2,
384
+ includeComments: false
385
+ });
386
+ offsets.setOffsetToken(snippetToken, 1, openToken);
387
+ const id = (0, commons_3.getFirstAndLastTokens)(sourceCode, node.id);
388
+ offsets.setOffsetToken(id.firstToken, 1, snippetToken);
389
+ const leftParenToken = sourceCode.getTokenBefore(node.context || sourceCode.getLastToken(node), {
390
+ filter: eslint_utils_1.isOpeningParenToken,
391
+ includeComments: false
392
+ });
393
+ const rightParenToken = sourceCode.getTokenAfter(node.context || leftParenToken, {
394
+ filter: eslint_utils_1.isClosingParenToken,
395
+ includeComments: false
396
+ });
397
+ offsets.setOffsetToken(leftParenToken, 1, id.firstToken);
398
+ offsets.setOffsetElementList([node.context], leftParenToken, rightParenToken, 1);
399
+ },
366
400
  SvelteHTMLComment(_node) {
367
401
  },
368
402
  SvelteName(_node) {
@@ -153,6 +153,10 @@ exports.default = (0, utils_1.createRule)('mustache-spacing', {
153
153
  const mustacheTokens = (0, ast_utils_1.getMustacheTokens)(node, sourceCode);
154
154
  verifyBraces(mustacheTokens.openToken, mustacheTokens.closeToken, options.tags.openingBrace, options.tags.closingBrace, true);
155
155
  },
156
+ SvelteRenderTag(node) {
157
+ const mustacheTokens = (0, ast_utils_1.getMustacheTokens)(node, sourceCode);
158
+ verifyBraces(mustacheTokens.openToken, mustacheTokens.closeToken, options.tags.openingBrace, options.tags.closingBrace, true);
159
+ },
156
160
  SvelteIfBlock(node) {
157
161
  const openBlockOpeningToken = sourceCode.getFirstToken(node);
158
162
  const openBlockClosingToken = sourceCode.getTokenAfter(node.expression, {
@@ -250,6 +254,20 @@ exports.default = (0, utils_1.createRule)('mustache-spacing', {
250
254
  verifyBraces(openBlockOpeningToken, openBlockClosingToken, options.tags.openingBrace, options.tags.closingBrace, Boolean(openBlockClosingToken &&
251
255
  openBlockLast &&
252
256
  openBlockClosingToken === sourceCode.getTokenAfter(openBlockLast)));
257
+ },
258
+ SvelteSnippetBlock(node) {
259
+ const openBlockOpeningToken = sourceCode.getFirstToken(node);
260
+ const openBlockClosingToken = sourceCode.getTokenAfter(node.context || node.id, {
261
+ includeComments: false,
262
+ filter: eslint_utils_1.isClosingBraceToken
263
+ });
264
+ verifyBraces(openBlockOpeningToken, openBlockClosingToken, options.tags.openingBrace, options.tags.closingBrace, true);
265
+ const closeBlockClosingToken = sourceCode.getLastToken(node);
266
+ const closeBlockOpeningToken = sourceCode.getTokenBefore(closeBlockClosingToken, {
267
+ includeComments: false,
268
+ filter: eslint_utils_1.isOpeningBraceToken
269
+ });
270
+ verifyBraces(closeBlockOpeningToken, closeBlockClosingToken, options.tags.openingBrace, options.tags.closingBrace, false);
253
271
  }
254
272
  };
255
273
  }
@@ -27,7 +27,11 @@ exports.default = (0, utils_1.createRule)('valid-compile', {
27
27
  return {};
28
28
  }
29
29
  const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings);
30
- const ignores = ['missing-declaration', 'dynamic-slot-name'];
30
+ const ignores = [
31
+ 'missing-declaration',
32
+ 'dynamic-slot-name',
33
+ 'invalid-slot-name'
34
+ ];
31
35
  function report(warnings) {
32
36
  for (const warn of warnings) {
33
37
  if (warn.code && ignores.includes(warn.code)) {
@@ -187,6 +187,7 @@ export type ASTNodeListener = {
187
187
  SvelteMustacheTag?: (node: AST.SvelteMustacheTag & ASTNodeWithParent) => void;
188
188
  SvelteDebugTag?: (node: AST.SvelteDebugTag & ASTNodeWithParent) => void;
189
189
  SvelteConstTag?: (node: AST.SvelteConstTag & ASTNodeWithParent) => void;
190
+ SvelteRenderTag?: (node: AST.SvelteRenderTag & ASTNodeWithParent) => void;
190
191
  SvelteIfBlock?: (node: AST.SvelteIfBlock & ASTNodeWithParent) => void;
191
192
  SvelteElseBlock?: (node: AST.SvelteElseBlock & ASTNodeWithParent) => void;
192
193
  SvelteEachBlock?: (node: AST.SvelteEachBlock & ASTNodeWithParent) => void;
@@ -195,6 +196,7 @@ export type ASTNodeListener = {
195
196
  SvelteAwaitThenBlock?: (node: AST.SvelteAwaitThenBlock & ASTNodeWithParent) => void;
196
197
  SvelteAwaitCatchBlock?: (node: AST.SvelteAwaitCatchBlock & ASTNodeWithParent) => void;
197
198
  SvelteKeyBlock?: (node: AST.SvelteKeyBlock & ASTNodeWithParent) => void;
199
+ SvelteSnippetBlock?: (node: AST.SvelteSnippetBlock & ASTNodeWithParent) => void;
198
200
  SvelteAttribute?: (node: AST.SvelteAttribute & ASTNodeWithParent) => void;
199
201
  SvelteShorthandAttribute?: (node: AST.SvelteShorthandAttribute & ASTNodeWithParent) => void;
200
202
  SvelteSpreadAttribute?: (node: AST.SvelteSpreadAttribute & ASTNodeWithParent) => void;
@@ -378,6 +380,7 @@ export type SvelteNodeListener = {
378
380
  SvelteMustacheTag?: (node: AST.SvelteMustacheTag & ASTNodeWithParent) => void;
379
381
  SvelteDebugTag?: (node: AST.SvelteDebugTag & ASTNodeWithParent) => void;
380
382
  SvelteConstTag?: (node: AST.SvelteConstTag & ASTNodeWithParent) => void;
383
+ SvelteRenderTag?: (node: AST.SvelteRenderTag & ASTNodeWithParent) => void;
381
384
  SvelteIfBlock?: (node: AST.SvelteIfBlock & ASTNodeWithParent) => void;
382
385
  SvelteElseBlock?: (node: AST.SvelteElseBlock & ASTNodeWithParent) => void;
383
386
  SvelteEachBlock?: (node: AST.SvelteEachBlock & ASTNodeWithParent) => void;
@@ -386,6 +389,7 @@ export type SvelteNodeListener = {
386
389
  SvelteAwaitThenBlock?: (node: AST.SvelteAwaitThenBlock & ASTNodeWithParent) => void;
387
390
  SvelteAwaitCatchBlock?: (node: AST.SvelteAwaitCatchBlock & ASTNodeWithParent) => void;
388
391
  SvelteKeyBlock?: (node: AST.SvelteKeyBlock & ASTNodeWithParent) => void;
392
+ SvelteSnippetBlock?: (node: AST.SvelteSnippetBlock & ASTNodeWithParent) => void;
389
393
  SvelteAttribute?: (node: AST.SvelteAttribute & ASTNodeWithParent) => void;
390
394
  SvelteShorthandAttribute?: (node: AST.SvelteShorthandAttribute & ASTNodeWithParent) => void;
391
395
  SvelteSpreadAttribute?: (node: AST.SvelteSpreadAttribute & ASTNodeWithParent) => void;
@@ -40,11 +40,11 @@ export type QuoteAndRange = {
40
40
  lastToken: SvAST.Token | SvAST.Comment;
41
41
  };
42
42
  export declare function getAttributeValueQuoteAndRange(attr: SvAST.SvelteAttribute | SvAST.SvelteDirective | SvAST.SvelteStyleDirective | SvAST.SvelteSpecialDirective, sourceCode: SourceCode): QuoteAndRange | null;
43
- export declare function getMustacheTokens(node: SvAST.SvelteMustacheTag | SvAST.SvelteShorthandAttribute | SvAST.SvelteSpreadAttribute | SvAST.SvelteDebugTag, sourceCode: SourceCode): {
43
+ export declare function getMustacheTokens(node: SvAST.SvelteMustacheTag | SvAST.SvelteShorthandAttribute | SvAST.SvelteSpreadAttribute | SvAST.SvelteDebugTag | SvAST.SvelteRenderTag, sourceCode: SourceCode): {
44
44
  openToken: SvAST.Token;
45
45
  closeToken: SvAST.Token;
46
46
  };
47
- export declare function getMustacheTokens(node: SvAST.SvelteDirective | SvAST.SvelteSpecialDirective | SvAST.SvelteMustacheTag | SvAST.SvelteShorthandAttribute | SvAST.SvelteSpreadAttribute | SvAST.SvelteDebugTag, sourceCode: SourceCode): {
47
+ export declare function getMustacheTokens(node: SvAST.SvelteDirective | SvAST.SvelteSpecialDirective | SvAST.SvelteMustacheTag | SvAST.SvelteShorthandAttribute | SvAST.SvelteSpreadAttribute | SvAST.SvelteDebugTag | SvAST.SvelteRenderTag, sourceCode: SourceCode): {
48
48
  openToken: SvAST.Token;
49
49
  closeToken: SvAST.Token;
50
50
  } | null;
@@ -270,10 +270,7 @@ function getAttributeValueQuoteAndRange(attr, sourceCode) {
270
270
  }
271
271
  exports.getAttributeValueQuoteAndRange = getAttributeValueQuoteAndRange;
272
272
  function getMustacheTokens(node, sourceCode) {
273
- if (node.type === 'SvelteMustacheTag' ||
274
- node.type === 'SvelteShorthandAttribute' ||
275
- node.type === 'SvelteSpreadAttribute' ||
276
- node.type === 'SvelteDebugTag') {
273
+ if (isWrappedInBraces(node)) {
277
274
  const openToken = sourceCode.getFirstToken(node);
278
275
  const closeToken = sourceCode.getLastToken(node);
279
276
  return {
@@ -309,6 +306,13 @@ function getMustacheTokens(node, sourceCode) {
309
306
  };
310
307
  }
311
308
  exports.getMustacheTokens = getMustacheTokens;
309
+ function isWrappedInBraces(node) {
310
+ return (node.type === 'SvelteMustacheTag' ||
311
+ node.type === 'SvelteShorthandAttribute' ||
312
+ node.type === 'SvelteSpreadAttribute' ||
313
+ node.type === 'SvelteDebugTag' ||
314
+ node.type === 'SvelteRenderTag');
315
+ }
312
316
  function getAttributeKeyText(node, context) {
313
317
  switch (node.type) {
314
318
  case 'SvelteAttribute':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-svelte",
3
- "version": "2.35.1",
3
+ "version": "2.36.0-next.1",
4
4
  "description": "ESLint plugin for Svelte using AST",
5
5
  "repository": "git+https://github.com/sveltejs/eslint-plugin-svelte.git",
6
6
  "homepage": "https://sveltejs.github.io/eslint-plugin-svelte",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "peerDependencies": {
29
29
  "eslint": "^7.0.0 || ^8.0.0-0",
30
- "svelte": "^3.37.0 || ^4.0.0"
30
+ "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.8"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "svelte": {
@@ -46,7 +46,7 @@
46
46
  "postcss-safe-parser": "^6.0.0",
47
47
  "postcss-selector-parser": "^6.0.11",
48
48
  "semver": "^7.5.3",
49
- "svelte-eslint-parser": ">=0.33.0 <1.0.0"
49
+ "svelte-eslint-parser": ">=0.34.0-next.2 <1.0.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@1stg/browserslist-config": "^1.2.3",
@@ -133,7 +133,7 @@
133
133
  "stylelint": "^15.0.0",
134
134
  "stylelint-config-standard": "^34.0.0",
135
135
  "stylus": "^0.62.0",
136
- "svelte": "^4.0.0",
136
+ "svelte": "^5.0.0-next.8",
137
137
  "svelte-adapter-ghpages": "0.1.0",
138
138
  "svelte-i18n": "^4.0.0",
139
139
  "tslib": "^2.5.0",