Skip to content

Commit

Permalink
fix: update svelte-eslint-parser to 0.22 (#306)
Browse files Browse the repository at this point in the history
* fix: update svelte-eslint-parser to 0.22

* Create rotten-moons-shop.md
  • Loading branch information
ota-meshi committed Nov 25, 2022
1 parent f46aa89 commit 48bb4b7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 19 deletions.
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

0 comments on commit 48bb4b7

Please sign in to comment.