Skip to content

Commit dfeab92

Browse files
committed
feat(consistent-selector-style): enabled support for partial style
1 parent 5e7504d commit dfeab92

File tree

12 files changed

+250
-2
lines changed

12 files changed

+250
-2
lines changed

packages/eslint-plugin-svelte/src/rule-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ type SvelteCommentDirective = []|[{
395395
// ----- svelte/consistent-selector-style -----
396396
type SvelteConsistentSelectorStyle = []|[{
397397

398-
style?: [("class" | "id" | "type"), ("class" | "id" | "type"), ("class" | "id" | "type")]
398+
style?: []|[("class" | "id" | "type")]|[("class" | "id" | "type"), ("class" | "id" | "type")]|[("class" | "id" | "type"), ("class" | "id" | "type"), ("class" | "id" | "type")]
399399
}]
400400
// ----- svelte/first-attribute-linebreak -----
401401
type SvelteFirstAttributeLinebreak = []|[{

packages/eslint-plugin-svelte/src/rules/consistent-selector-style.ts

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default createRule('consistent-selector-style', {
3838
items: {
3939
enum: ['class', 'id', 'type']
4040
},
41-
minItems: 3, // TODO: Allow fewer items
4241
maxItems: 3,
4342
uniqueItems: true
4443
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"options": [{ "style": ["type", "id"] }]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<a class="link">Click me!</a>
2+
3+
<a class="link">Click me two!</a>
4+
5+
<a>Click me three!</a>
6+
7+
<b class="bold">Text 1</b>
8+
9+
<b class="bold">Text 2</b>
10+
11+
<b data-key="val">Text 3</b>
12+
13+
<style>
14+
.link {
15+
color: red;
16+
}
17+
18+
.bold {
19+
color: red;
20+
}
21+
22+
.link:active {
23+
color: red;
24+
}
25+
26+
.link + .bold {
27+
color: red;
28+
}
29+
30+
.bold[data-key="val"] {
31+
color: red;
32+
}
33+
34+
.bold::before {
35+
color: red;
36+
}
37+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<a id="link">Click me!</a>
2+
3+
<a>Click me too!</a>
4+
5+
<b id="bold">Text 1</b>
6+
7+
<b data-key="val">Text 2</b>
8+
9+
<style>
10+
#link {
11+
color: red;
12+
}
13+
14+
#bold {
15+
color: red;
16+
}
17+
18+
#link:active {
19+
color: red;
20+
}
21+
22+
#link + #bold {
23+
color: red;
24+
}
25+
26+
#bold[data-key="val"] {
27+
color: red;
28+
}
29+
30+
#bold::before {
31+
color: red;
32+
}
33+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<a>Click me!</a>
2+
3+
<b>Text 1</b>
4+
5+
<style lang="scss">
6+
a {
7+
color: red;
8+
}
9+
10+
b {
11+
color: red;
12+
}
13+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<a>Click me!</a>
2+
3+
<a>Click me two!</a>
4+
5+
<b>Text 1</b>
6+
7+
<b>Text 2</b>
8+
9+
<b data-key="val">Text 2</b>
10+
11+
<style>
12+
a {
13+
color: red;
14+
}
15+
16+
b {
17+
color: red;
18+
}
19+
20+
a:active {
21+
color: red;
22+
}
23+
24+
a + b {
25+
color: red;
26+
}
27+
28+
b[data-key="val"] {
29+
color: red;
30+
}
31+
32+
b::before {
33+
color: red;
34+
}
35+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"options": [{ "style": ["type"] }]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<a class="link">Click me!</a>
2+
3+
<a class="link">Click me two!</a>
4+
5+
<a>Click me three!</a>
6+
7+
<a class="unique">Click me three!</a>
8+
9+
<b class="bold">Text 1</b>
10+
11+
<b class="bold">Text 2</b>
12+
13+
<b data-key="val">Text 3</b>
14+
15+
<style>
16+
.link {
17+
color: red;
18+
}
19+
20+
.bold {
21+
color: red;
22+
}
23+
24+
.link:active {
25+
color: red;
26+
}
27+
28+
.link + .bold {
29+
color: red;
30+
}
31+
32+
.bold[data-key="val"] {
33+
color: red;
34+
}
35+
36+
.bold::before {
37+
color: red;
38+
}
39+
40+
.unique {
41+
color: red;
42+
}
43+
44+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<a id="link">Click me!</a>
2+
3+
<a>Click me too!</a>
4+
5+
<b id="bold">Text 1</b>
6+
7+
<b data-key="val">Text 2</b>
8+
9+
<style>
10+
#link {
11+
color: red;
12+
}
13+
14+
#bold {
15+
color: red;
16+
}
17+
18+
#link:active {
19+
color: red;
20+
}
21+
22+
#link + #bold {
23+
color: red;
24+
}
25+
26+
#bold[data-key="val"] {
27+
color: red;
28+
}
29+
30+
#bold::before {
31+
color: red;
32+
}
33+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<a>Click me!</a>
2+
3+
<b>Text 1</b>
4+
5+
<style lang="scss">
6+
a {
7+
color: red;
8+
}
9+
10+
b {
11+
color: red;
12+
}
13+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<a>Click me!</a>
2+
3+
<a>Click me two!</a>
4+
5+
<b>Text 1</b>
6+
7+
<b>Text 2</b>
8+
9+
<b data-key="val">Text 2</b>
10+
11+
<style>
12+
a {
13+
color: red;
14+
}
15+
16+
b {
17+
color: red;
18+
}
19+
20+
a:active {
21+
color: red;
22+
}
23+
24+
a + b {
25+
color: red;
26+
}
27+
28+
b[data-key="val"] {
29+
color: red;
30+
}
31+
32+
b::before {
33+
color: red;
34+
}
35+
</style>

0 commit comments

Comments
 (0)