Skip to content

Commit 48bb4b7

Browse files
authored
fix: update svelte-eslint-parser to 0.22 (#306)
* fix: update svelte-eslint-parser to 0.22 * Create rotten-moons-shop.md
1 parent f46aa89 commit 48bb4b7

File tree

7 files changed

+66
-19
lines changed

7 files changed

+66
-19
lines changed

.changeset/rotten-moons-shop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-svelte": patch
3+
---
4+
5+
fix: update svelte-eslint-parser to 0.22

docs-svelte-kit/src/routes/+layout.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { markdownPath } from "$lib/utils.js"
22
const docs = import.meta.glob("../../../docs/**/*.md")
33

44
export const prerender = true
5+
export const trailingSlash = "always"
56

67
/** @type {import('@sveltejs/kit').Load} */
78
export async function load({ url }) {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"postcss-load-config": "^3.1.4",
7474
"postcss-safe-parser": "^6.0.0",
7575
"sourcemap-codec": "^1.4.8",
76-
"svelte-eslint-parser": "^0.21.0"
76+
"svelte-eslint-parser": "^0.22.0"
7777
},
7878
"devDependencies": {
7979
"@1stg/browserslist-config": "^1.2.3",
@@ -174,7 +174,7 @@
174174
"access": "public"
175175
},
176176
"typeCoverage": {
177-
"atLeast": 98.72,
177+
"atLeast": 99.04,
178178
"cache": true,
179179
"detail": true,
180180
"ignoreAsAssertion": true,

src/rules/shorthand-directive.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export default createRule("shorthand-directive", {
3232

3333
/** Report for always */
3434
function reportForAlways(
35-
node: AST.SvelteDirective | AST.SvelteStyleDirective,
35+
node:
36+
| AST.SvelteBindingDirective
37+
| AST.SvelteClassDirective
38+
| AST.SvelteStyleDirective,
3639
) {
3740
context.report({
3841
node,
@@ -51,7 +54,10 @@ export default createRule("shorthand-directive", {
5154

5255
/** Report for never */
5356
function reportForNever(
54-
node: AST.SvelteDirective | AST.SvelteStyleDirective,
57+
node:
58+
| AST.SvelteBindingDirective
59+
| AST.SvelteClassDirective
60+
| AST.SvelteStyleDirective,
5561
) {
5662
context.report({
5763
node,

src/rules/sort-attributes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default createRule("sort-attributes", {
229229
const k = cacheKeyText.get(node)
230230
if (k != null) return k
231231

232-
const result = getAttributeKeyText(node)
232+
const result = getAttributeKeyText(node, context)
233233
cacheKeyText.set(node, result)
234234
return result
235235
}

src/utils/ast-utils.ts

+49-12
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ export function getAttributeKeyText(
435435
| SvAST.SvelteStyleDirective
436436
| SvAST.SvelteDirective
437437
| SvAST.SvelteSpecialDirective,
438+
context: RuleContext,
438439
): string {
439440
switch (node.type) {
440441
case "SvelteAttribute":
@@ -446,7 +447,7 @@ export function getAttributeKeyText(
446447
return node.kind
447448
case "SvelteDirective": {
448449
const dir = getDirectiveName(node)
449-
return `${dir}:${node.key.name.name}${
450+
return `${dir}:${getSimpleNameFromNode(node.key.name, context)}${
450451
node.key.modifiers.length ? `|${node.key.modifiers.join("|")}` : ""
451452
}`
452453
}
@@ -518,17 +519,7 @@ function getAttributeValueRangeTokens(
518519
* Returns name of SvelteElement
519520
*/
520521
export function getNodeName(node: SvAST.SvelteElement): string {
521-
if (node.name.type === "Identifier" || node.name.type === "SvelteName") {
522-
return node.name.name
523-
}
524-
const memberPath = [node.name.property.name]
525-
let currentObject = node.name.object
526-
while (currentObject.type === "SvelteMemberExpressionName") {
527-
memberPath.unshift(currentObject.property.name)
528-
currentObject = currentObject.object
529-
}
530-
memberPath.unshift(currentObject.name)
531-
return memberPath.join(".")
522+
return getSimpleNameFromNode(node.name)
532523
}
533524

534525
/**
@@ -586,3 +577,49 @@ export function isExpressionIdentifier(
586577

587578
return true
588579
}
580+
581+
function getSimpleNameFromNode(
582+
node:
583+
| SvAST.SvelteName
584+
| SvAST.SvelteMemberExpressionName
585+
| TSESTree.Identifier,
586+
context?: RuleContext,
587+
): string
588+
function getSimpleNameFromNode(
589+
node:
590+
| SvAST.SvelteName
591+
| SvAST.SvelteMemberExpressionName
592+
| TSESTree.PrivateIdentifier
593+
| TSESTree.Expression,
594+
context: RuleContext,
595+
): string
596+
/** Get simple name from give node */
597+
function getSimpleNameFromNode(
598+
node:
599+
| SvAST.SvelteName
600+
| SvAST.SvelteMemberExpressionName
601+
| TSESTree.PrivateIdentifier
602+
| TSESTree.Expression,
603+
context: RuleContext | undefined,
604+
): string {
605+
if (node.type === "Identifier" || node.type === "SvelteName") {
606+
return node.name
607+
}
608+
if (
609+
node.type === "SvelteMemberExpressionName" ||
610+
(node.type === "MemberExpression" && !node.computed)
611+
) {
612+
return `${getSimpleNameFromNode(
613+
node.object,
614+
context!,
615+
)}.${getSimpleNameFromNode(node.property, context!)}`
616+
}
617+
618+
// No nodes other than those listed above are currently expected to be used in names.
619+
620+
if (!context) {
621+
throw new Error("Rule context is required")
622+
}
623+
624+
return context.getSourceCode().getText(node)
625+
}

svelte.config.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const config = {
4747
lib: path.join(dirname, "./docs-svelte-kit/src/lib"),
4848
assets: path.join(dirname, "./docs-svelte-kit/statics"),
4949
},
50-
51-
trailingSlash: "always",
5250
},
5351
}
5452
export default config

0 commit comments

Comments
 (0)