Skip to content

Commit f15f13a

Browse files
authored
Support for svelte v3.46.1 (#93)
1 parent 39281e9 commit f15f13a

13 files changed

+242
-12
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"debug": "^4.3.1",
5757
"eslint-utils": "^3.0.0",
5858
"sourcemap-codec": "^1.4.8",
59-
"svelte-eslint-parser": "^0.10.0"
59+
"svelte-eslint-parser": "^0.11.0"
6060
},
6161
"peerDependencies": {
6262
"eslint": "^7.0.0 || ^8.0.0-0",
@@ -118,7 +118,7 @@
118118
"semver": "^7.3.5",
119119
"stylelint": "^14.0.0",
120120
"stylelint-config-standard": "^24.0.0",
121-
"svelte": "^3.37.0",
121+
"svelte": "^3.46.1",
122122
"svelte-adapter-ghpages": "0.0.2",
123123
"ts-node": "^10.0.0",
124124
"typescript": "^4.5.2",

src/rules/html-quotes.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ export default createRule("html-quotes", {
148148
}
149149

150150
/** Verify for standard attribute */
151-
function verifyForValues(attr: AST.SvelteAttribute) {
151+
function verifyForValues(
152+
attr: AST.SvelteAttribute | AST.SvelteStyleDirective,
153+
) {
152154
const quoteAndRange = getAttributeValueQuoteAndRange(attr, sourceCode)
153155
verifyQuote(preferQuote, quoteAndRange)
154156
}
155157

156158
/** Verify for dynamic attribute */
157159
function verifyForDynamicMustacheTag(
158-
attr: AST.SvelteAttribute,
159-
valueNode: AST.SvelteMustacheTag & {
160-
kind: "text"
161-
},
160+
attr: AST.SvelteAttribute | AST.SvelteStyleDirective,
161+
valueNode: AST.SvelteMustacheTagText,
162162
) {
163163
const quoteAndRange = getAttributeValueQuoteAndRange(attr, sourceCode)
164164
const text = sourceCode.text.slice(...valueNode.range)
@@ -192,7 +192,9 @@ export default createRule("html-quotes", {
192192
}
193193

194194
return {
195-
SvelteAttribute(node) {
195+
"SvelteAttribute, SvelteStyleDirective"(
196+
node: AST.SvelteAttribute | AST.SvelteStyleDirective,
197+
) {
196198
if (
197199
node.value.length === 1 &&
198200
node.value[0].type === "SvelteMustacheTag"

src/rules/indent-helpers/svelte.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
8787
node:
8888
| AST.SvelteAttribute
8989
| AST.SvelteDirective
90+
| AST.SvelteStyleDirective
9091
| AST.SvelteSpecialDirective,
9192
) {
9293
const keyToken = sourceCode.getFirstToken(node)
@@ -102,7 +103,11 @@ export function defineVisitor(context: IndentContext): NodeListener {
102103
) {
103104
offsets.setOffsetToken(valueStartToken, 1, keyToken)
104105

105-
const values = node.type === "SvelteAttribute" ? node.value : []
106+
const values =
107+
node.type === "SvelteAttribute" ||
108+
node.type === "SvelteStyleDirective"
109+
? node.value
110+
: []
106111
// process quoted
107112
let processedValues = false
108113
if (valueStartToken.type === "Punctuator") {
@@ -134,6 +139,9 @@ export function defineVisitor(context: IndentContext): NodeListener {
134139
SvelteDirective(node: AST.SvelteDirective) {
135140
visitor.SvelteAttribute(node)
136141
},
142+
SvelteStyleDirective(node: AST.SvelteStyleDirective) {
143+
visitor.SvelteAttribute(node)
144+
},
137145
SvelteSpecialDirective(node: AST.SvelteSpecialDirective) {
138146
visitor.SvelteAttribute(node)
139147
},

src/rules/max-attributes-per-line.ts

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default createRule("max-attributes-per-line", {
7272
attribute.type === "SvelteAttribute" ||
7373
attribute.type === "SvelteShorthandAttribute" ||
7474
attribute.type === "SvelteDirective" ||
75+
attribute.type === "SvelteStyleDirective" ||
7576
attribute.type === "SvelteSpecialDirective"
7677
) {
7778
name = sourceCode.text.slice(...attribute.key.range!)

src/rules/mustache-spacing.ts

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ export default createRule("mustache-spacing", {
193193
let option: OptionValue
194194
if (node.parent.type === "SvelteAttribute") {
195195
option = options.attributesAndProps
196+
} else if (node.parent.type === "SvelteStyleDirective") {
197+
option = options.directiveExpressions
196198
} else {
197199
option = options.textExpressions
198200
}

src/rules/no-useless-mustaches.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ export default createRule("no-useless-mustaches", {
126126

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

129-
if (node.parent.type === "SvelteAttribute") {
129+
if (
130+
node.parent.type === "SvelteAttribute" ||
131+
node.parent.type === "SvelteStyleDirective"
132+
) {
130133
const div = sourceCode.text.slice(
131134
node.parent.key.range[1],
132135
node.parent.value[0].range[0],

src/utils/ast-utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ export function getAttributeValueQuoteAndRange(
239239
attr:
240240
| SvAST.SvelteAttribute
241241
| SvAST.SvelteDirective
242+
| SvAST.SvelteStyleDirective
242243
| SvAST.SvelteSpecialDirective,
243244
sourceCode: SourceCode,
244245
): QuoteAndRange | null {
@@ -372,10 +373,11 @@ function getAttributeValueRangeTokens(
372373
attr:
373374
| SvAST.SvelteAttribute
374375
| SvAST.SvelteDirective
376+
| SvAST.SvelteStyleDirective
375377
| SvAST.SvelteSpecialDirective,
376378
sourceCode: SourceCode,
377379
) {
378-
if (attr.type === "SvelteAttribute") {
380+
if (attr.type === "SvelteAttribute" || attr.type === "SvelteStyleDirective") {
379381
if (!attr.value.length) {
380382
return null
381383
}

tests/fixtures/rules/html-quotes/invalid/test01-errors.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
},
2222
{
2323
"message": "Unexpected to be enclosed by any quotes.",
24-
"line": 16,
24+
"line": 14,
25+
"column": 20
26+
},
27+
{
28+
"message": "Unexpected to be enclosed by any quotes.",
29+
"line": 18,
2530
"column": 10
2631
}
2732
]

tests/fixtures/rules/html-quotes/invalid/test01-input.svelte

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<input type="text" bind:value />
1111
<!-- prettier-ignore -->
1212
<input type='text' bind:value="{value}" />
13+
<!-- prettier-ignore -->
14+
<input style:color="{value}" />
1315

1416
<img {src} alt="{name} dances." />
1517
<!-- prettier-ignore -->

tests/fixtures/rules/html-quotes/invalid/test01-output.svelte

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<input type="text" bind:value />
1111
<!-- prettier-ignore -->
1212
<input type="text" bind:value={value} />
13+
<!-- prettier-ignore -->
14+
<input style:color={value} />
1315

1416
<img {src} alt="{name} dances." />
1517
<!-- prettier-ignore -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[
2+
{
3+
"message": "Expected indentation of 2 spaces but found 0 spaces.",
4+
"line": 8,
5+
"column": 1
6+
},
7+
{
8+
"message": "Expected indentation of 2 spaces but found 0 spaces.",
9+
"line": 13,
10+
"column": 1
11+
},
12+
{
13+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
14+
"line": 14,
15+
"column": 1
16+
},
17+
{
18+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
19+
"line": 15,
20+
"column": 1
21+
},
22+
{
23+
"message": "Expected indentation of 6 spaces but found 0 spaces.",
24+
"line": 16,
25+
"column": 1
26+
},
27+
{
28+
"message": "Expected indentation of 8 spaces but found 0 spaces.",
29+
"line": 17,
30+
"column": 1
31+
},
32+
{
33+
"message": "Expected indentation of 6 spaces but found 0 spaces.",
34+
"line": 18,
35+
"column": 1
36+
},
37+
{
38+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
39+
"line": 19,
40+
"column": 1
41+
},
42+
{
43+
"message": "Expected indentation of 2 spaces but found 0 spaces.",
44+
"line": 24,
45+
"column": 1
46+
},
47+
{
48+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
49+
"line": 25,
50+
"column": 1
51+
},
52+
{
53+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
54+
"line": 26,
55+
"column": 1
56+
},
57+
{
58+
"message": "Expected indentation of 6 spaces but found 0 spaces.",
59+
"line": 27,
60+
"column": 1
61+
},
62+
{
63+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
64+
"line": 28,
65+
"column": 1
66+
},
67+
{
68+
"message": "Expected indentation of 2 spaces but found 0 spaces.",
69+
"line": 33,
70+
"column": 1
71+
},
72+
{
73+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
74+
"line": 34,
75+
"column": 1
76+
},
77+
{
78+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
79+
"line": 35,
80+
"column": 1
81+
},
82+
{
83+
"message": "Expected indentation of 2 spaces but found 0 spaces.",
84+
"line": 40,
85+
"column": 1
86+
},
87+
{
88+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
89+
"line": 41,
90+
"column": 1
91+
},
92+
{
93+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
94+
"line": 42,
95+
"column": 1
96+
},
97+
{
98+
"message": "Expected indentation of 6 spaces but found 0 spaces.",
99+
"line": 43,
100+
"column": 1
101+
},
102+
{
103+
"message": "Expected indentation of 4 spaces but found 0 spaces.",
104+
"line": 44,
105+
"column": 1
106+
}
107+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- prettier-ignore -->
2+
<script>
3+
let color = 'red'
4+
</script>
5+
6+
<!-- prettier-ignore -->
7+
<div
8+
style:color
9+
>
10+
</div>
11+
<!-- prettier-ignore -->
12+
<div
13+
style:color
14+
=
15+
"
16+
r{
17+
color
18+
}
19+
"
20+
>
21+
</div>
22+
<!-- prettier-ignore -->
23+
<div
24+
style:color
25+
=
26+
{
27+
color
28+
}
29+
>
30+
</div>
31+
<!-- prettier-ignore -->
32+
<div
33+
style:color
34+
=
35+
red
36+
>
37+
</div>
38+
<!-- prettier-ignore -->
39+
<div
40+
style:color
41+
=
42+
"
43+
red
44+
"
45+
>
46+
</div>
47+
48+
<!--tests/fixtures/rules/indent/invalid/style-directive01-input.svelte-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!-- prettier-ignore -->
2+
<script>
3+
let color = 'red'
4+
</script>
5+
6+
<!-- prettier-ignore -->
7+
<div
8+
style:color
9+
>
10+
</div>
11+
<!-- prettier-ignore -->
12+
<div
13+
style:color
14+
=
15+
"
16+
r{
17+
color
18+
}
19+
"
20+
>
21+
</div>
22+
<!-- prettier-ignore -->
23+
<div
24+
style:color
25+
=
26+
{
27+
color
28+
}
29+
>
30+
</div>
31+
<!-- prettier-ignore -->
32+
<div
33+
style:color
34+
=
35+
red
36+
>
37+
</div>
38+
<!-- prettier-ignore -->
39+
<div
40+
style:color
41+
=
42+
"
43+
red
44+
"
45+
>
46+
</div>
47+
48+
<!--tests/fixtures/rules/indent/invalid/style-directive01-input.svelte-->

0 commit comments

Comments
 (0)