Skip to content

Support for svelte v3.46.1 #93

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 1 commit into from
Jan 13, 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"debug": "^4.3.1",
"eslint-utils": "^3.0.0",
"sourcemap-codec": "^1.4.8",
"svelte-eslint-parser": "^0.10.0"
"svelte-eslint-parser": "^0.11.0"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0-0",
Expand Down Expand Up @@ -118,7 +118,7 @@
"semver": "^7.3.5",
"stylelint": "^14.0.0",
"stylelint-config-standard": "^24.0.0",
"svelte": "^3.37.0",
"svelte": "^3.46.1",
"svelte-adapter-ghpages": "0.0.2",
"ts-node": "^10.0.0",
"typescript": "^4.5.2",
Expand Down
14 changes: 8 additions & 6 deletions src/rules/html-quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ export default createRule("html-quotes", {
}

/** Verify for standard attribute */
function verifyForValues(attr: AST.SvelteAttribute) {
function verifyForValues(
attr: AST.SvelteAttribute | AST.SvelteStyleDirective,
) {
const quoteAndRange = getAttributeValueQuoteAndRange(attr, sourceCode)
verifyQuote(preferQuote, quoteAndRange)
}

/** Verify for dynamic attribute */
function verifyForDynamicMustacheTag(
attr: AST.SvelteAttribute,
valueNode: AST.SvelteMustacheTag & {
kind: "text"
},
attr: AST.SvelteAttribute | AST.SvelteStyleDirective,
valueNode: AST.SvelteMustacheTagText,
) {
const quoteAndRange = getAttributeValueQuoteAndRange(attr, sourceCode)
const text = sourceCode.text.slice(...valueNode.range)
Expand Down Expand Up @@ -192,7 +192,9 @@ export default createRule("html-quotes", {
}

return {
SvelteAttribute(node) {
"SvelteAttribute, SvelteStyleDirective"(
node: AST.SvelteAttribute | AST.SvelteStyleDirective,
) {
if (
node.value.length === 1 &&
node.value[0].type === "SvelteMustacheTag"
Expand Down
10 changes: 9 additions & 1 deletion src/rules/indent-helpers/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
node:
| AST.SvelteAttribute
| AST.SvelteDirective
| AST.SvelteStyleDirective
| AST.SvelteSpecialDirective,
) {
const keyToken = sourceCode.getFirstToken(node)
Expand All @@ -102,7 +103,11 @@ export function defineVisitor(context: IndentContext): NodeListener {
) {
offsets.setOffsetToken(valueStartToken, 1, keyToken)

const values = node.type === "SvelteAttribute" ? node.value : []
const values =
node.type === "SvelteAttribute" ||
node.type === "SvelteStyleDirective"
? node.value
: []
// process quoted
let processedValues = false
if (valueStartToken.type === "Punctuator") {
Expand Down Expand Up @@ -134,6 +139,9 @@ export function defineVisitor(context: IndentContext): NodeListener {
SvelteDirective(node: AST.SvelteDirective) {
visitor.SvelteAttribute(node)
},
SvelteStyleDirective(node: AST.SvelteStyleDirective) {
visitor.SvelteAttribute(node)
},
SvelteSpecialDirective(node: AST.SvelteSpecialDirective) {
visitor.SvelteAttribute(node)
},
Expand Down
1 change: 1 addition & 0 deletions src/rules/max-attributes-per-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default createRule("max-attributes-per-line", {
attribute.type === "SvelteAttribute" ||
attribute.type === "SvelteShorthandAttribute" ||
attribute.type === "SvelteDirective" ||
attribute.type === "SvelteStyleDirective" ||
attribute.type === "SvelteSpecialDirective"
) {
name = sourceCode.text.slice(...attribute.key.range!)
Expand Down
2 changes: 2 additions & 0 deletions src/rules/mustache-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export default createRule("mustache-spacing", {
let option: OptionValue
if (node.parent.type === "SvelteAttribute") {
option = options.attributesAndProps
} else if (node.parent.type === "SvelteStyleDirective") {
option = options.directiveExpressions
} else {
option = options.textExpressions
}
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-useless-mustaches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export default createRule("no-useless-mustaches", {

const unescaped = text.replace(/\\([\s\S])/g, "$1")

if (node.parent.type === "SvelteAttribute") {
if (
node.parent.type === "SvelteAttribute" ||
node.parent.type === "SvelteStyleDirective"
) {
const div = sourceCode.text.slice(
node.parent.key.range[1],
node.parent.value[0].range[0],
Expand Down
4 changes: 3 additions & 1 deletion src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export function getAttributeValueQuoteAndRange(
attr:
| SvAST.SvelteAttribute
| SvAST.SvelteDirective
| SvAST.SvelteStyleDirective
| SvAST.SvelteSpecialDirective,
sourceCode: SourceCode,
): QuoteAndRange | null {
Expand Down Expand Up @@ -372,10 +373,11 @@ function getAttributeValueRangeTokens(
attr:
| SvAST.SvelteAttribute
| SvAST.SvelteDirective
| SvAST.SvelteStyleDirective
| SvAST.SvelteSpecialDirective,
sourceCode: SourceCode,
) {
if (attr.type === "SvelteAttribute") {
if (attr.type === "SvelteAttribute" || attr.type === "SvelteStyleDirective") {
if (!attr.value.length) {
return null
}
Expand Down
7 changes: 6 additions & 1 deletion tests/fixtures/rules/html-quotes/invalid/test01-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
},
{
"message": "Unexpected to be enclosed by any quotes.",
"line": 16,
"line": 14,
"column": 20
},
{
"message": "Unexpected to be enclosed by any quotes.",
"line": 18,
"column": 10
}
]
2 changes: 2 additions & 0 deletions tests/fixtures/rules/html-quotes/invalid/test01-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<input type="text" bind:value />
<!-- prettier-ignore -->
<input type='text' bind:value="{value}" />
<!-- prettier-ignore -->
<input style:color="{value}" />

<img {src} alt="{name} dances." />
<!-- prettier-ignore -->
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/rules/html-quotes/invalid/test01-output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<input type="text" bind:value />
<!-- prettier-ignore -->
<input type="text" bind:value={value} />
<!-- prettier-ignore -->
<input style:color={value} />

<img {src} alt="{name} dances." />
<!-- prettier-ignore -->
Expand Down
107 changes: 107 additions & 0 deletions tests/fixtures/rules/indent/invalid/style-directive01-errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 8,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 13,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 14,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 15,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 16,
"column": 1
},
{
"message": "Expected indentation of 8 spaces but found 0 spaces.",
"line": 17,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 18,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 19,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 24,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 25,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 26,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 27,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 28,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 33,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 34,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 35,
"column": 1
},
{
"message": "Expected indentation of 2 spaces but found 0 spaces.",
"line": 40,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 41,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 42,
"column": 1
},
{
"message": "Expected indentation of 6 spaces but found 0 spaces.",
"line": 43,
"column": 1
},
{
"message": "Expected indentation of 4 spaces but found 0 spaces.",
"line": 44,
"column": 1
}
]
48 changes: 48 additions & 0 deletions tests/fixtures/rules/indent/invalid/style-directive01-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- prettier-ignore -->
<script>
let color = 'red'
</script>

<!-- prettier-ignore -->
<div
style:color
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
"
r{
color
}
"
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
{
color
}
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
red
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
"
red
"
>
</div>

<!--tests/fixtures/rules/indent/invalid/style-directive01-input.svelte-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- prettier-ignore -->
<script>
let color = 'red'
</script>

<!-- prettier-ignore -->
<div
style:color
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
"
r{
color
}
"
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
{
color
}
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
red
>
</div>
<!-- prettier-ignore -->
<div
style:color
=
"
red
"
>
</div>

<!--tests/fixtures/rules/indent/invalid/style-directive01-input.svelte-->