Skip to content

fix: update svelte-eslint-parser to 0.22 #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-moons-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": patch
---

fix: update svelte-eslint-parser to 0.22
1 change: 1 addition & 0 deletions docs-svelte-kit/src/routes/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { markdownPath } from "$lib/utils.js"
const docs = import.meta.glob("../../../docs/**/*.md")

export const prerender = true
export const trailingSlash = "always"

/** @type {import('@sveltejs/kit').Load} */
export async function load({ url }) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"postcss-load-config": "^3.1.4",
"postcss-safe-parser": "^6.0.0",
"sourcemap-codec": "^1.4.8",
"svelte-eslint-parser": "^0.21.0"
"svelte-eslint-parser": "^0.22.0"
},
"devDependencies": {
"@1stg/browserslist-config": "^1.2.3",
Expand Down Expand Up @@ -174,7 +174,7 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 98.72,
"atLeast": 99.04,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
Expand Down
10 changes: 8 additions & 2 deletions src/rules/shorthand-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default createRule("shorthand-directive", {

/** Report for always */
function reportForAlways(
node: AST.SvelteDirective | AST.SvelteStyleDirective,
node:
| AST.SvelteBindingDirective
| AST.SvelteClassDirective
| AST.SvelteStyleDirective,
) {
context.report({
node,
Expand All @@ -51,7 +54,10 @@ export default createRule("shorthand-directive", {

/** Report for never */
function reportForNever(
node: AST.SvelteDirective | AST.SvelteStyleDirective,
node:
| AST.SvelteBindingDirective
| AST.SvelteClassDirective
| AST.SvelteStyleDirective,
) {
context.report({
node,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/sort-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default createRule("sort-attributes", {
const k = cacheKeyText.get(node)
if (k != null) return k

const result = getAttributeKeyText(node)
const result = getAttributeKeyText(node, context)
cacheKeyText.set(node, result)
return result
}
Expand Down
61 changes: 49 additions & 12 deletions src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export function getAttributeKeyText(
| SvAST.SvelteStyleDirective
| SvAST.SvelteDirective
| SvAST.SvelteSpecialDirective,
context: RuleContext,
): string {
switch (node.type) {
case "SvelteAttribute":
Expand All @@ -446,7 +447,7 @@ export function getAttributeKeyText(
return node.kind
case "SvelteDirective": {
const dir = getDirectiveName(node)
return `${dir}:${node.key.name.name}${
return `${dir}:${getSimpleNameFromNode(node.key.name, context)}${
node.key.modifiers.length ? `|${node.key.modifiers.join("|")}` : ""
}`
}
Expand Down Expand Up @@ -518,17 +519,7 @@ function getAttributeValueRangeTokens(
* Returns name of SvelteElement
*/
export function getNodeName(node: SvAST.SvelteElement): string {
if (node.name.type === "Identifier" || node.name.type === "SvelteName") {
return node.name.name
}
const memberPath = [node.name.property.name]
let currentObject = node.name.object
while (currentObject.type === "SvelteMemberExpressionName") {
memberPath.unshift(currentObject.property.name)
currentObject = currentObject.object
}
memberPath.unshift(currentObject.name)
return memberPath.join(".")
return getSimpleNameFromNode(node.name)
}

/**
Expand Down Expand Up @@ -586,3 +577,49 @@ export function isExpressionIdentifier(

return true
}

function getSimpleNameFromNode(
node:
| SvAST.SvelteName
| SvAST.SvelteMemberExpressionName
| TSESTree.Identifier,
context?: RuleContext,
): string
function getSimpleNameFromNode(
node:
| SvAST.SvelteName
| SvAST.SvelteMemberExpressionName
| TSESTree.PrivateIdentifier
| TSESTree.Expression,
context: RuleContext,
): string
/** Get simple name from give node */
function getSimpleNameFromNode(
node:
| SvAST.SvelteName
| SvAST.SvelteMemberExpressionName
| TSESTree.PrivateIdentifier
| TSESTree.Expression,
context: RuleContext | undefined,
): string {
if (node.type === "Identifier" || node.type === "SvelteName") {
return node.name
}
if (
node.type === "SvelteMemberExpressionName" ||
(node.type === "MemberExpression" && !node.computed)
) {
return `${getSimpleNameFromNode(
node.object,
context!,
)}.${getSimpleNameFromNode(node.property, context!)}`
}

// No nodes other than those listed above are currently expected to be used in names.

if (!context) {
throw new Error("Rule context is required")
}

return context.getSourceCode().getText(node)
}
2 changes: 0 additions & 2 deletions svelte.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const config = {
lib: path.join(dirname, "./docs-svelte-kit/src/lib"),
assets: path.join(dirname, "./docs-svelte-kit/statics"),
},

trailingSlash: "always",
},
}
export default config