-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add prefer option to prefer-class-directive (#690)
- Loading branch information
Showing
10 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-svelte": minor | ||
--- | ||
|
||
Added prefer option to prefer-class-directive rule ('always' or 'empty'). The default is now 'empty' which is a slight relaxation of the rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/prefer-class-directive/invalid/_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": [{ "prefer": "always" }] | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/fixtures/rules/prefer-class-directive/invalid/empty/test01-errors.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- message: Unexpected class using the ternary operator. | ||
line: 6 | ||
column: 15 | ||
suggestions: null | ||
- message: Unexpected class using the ternary operator. | ||
line: 7 | ||
column: 18 | ||
suggestions: null | ||
- message: Unexpected class using the ternary operator. | ||
line: 8 | ||
column: 17 | ||
suggestions: null | ||
- message: Unexpected class using the ternary operator. | ||
line: 10 | ||
column: 20 | ||
suggestions: null | ||
- message: Unexpected class using the ternary operator. | ||
line: 11 | ||
column: 20 | ||
suggestions: null |
13 changes: 13 additions & 0 deletions
13
tests/fixtures/rules/prefer-class-directive/invalid/empty/test01-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
let selected = 'foo'; | ||
let children = 1; | ||
</script> | ||
|
||
<button class={selected ? 'selected' : ''}>foo</button> | ||
<button class="a {selected ? 'selected' : ''} b">foo</button> | ||
<button class="a{selected ? ' selected ' : ' '}b">foo</button> | ||
|
||
<div class="d-flex {children > 1 ? 'gap-3' : ''}">foo</div> | ||
<div class="d-flex {children === 1 ? '' : 'gap-3'}">foo</div> | ||
|
||
<!-- test01-input.svelte --> |
13 changes: 13 additions & 0 deletions
13
tests/fixtures/rules/prefer-class-directive/invalid/empty/test01-output.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
let selected = 'foo'; | ||
let children = 1; | ||
</script> | ||
|
||
<button class:selected={selected}>foo</button> | ||
<button class="a b" class:selected={selected}>foo</button> | ||
<button class="a b" class:selected={selected}>foo</button> | ||
|
||
<div class="d-flex" class:gap-3={children > 1}>foo</div> | ||
<div class="d-flex" class:gap-3={children !== 1}>foo</div> | ||
|
||
<!-- test01-input.svelte --> |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/prefer-class-directive/valid/_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": [{ "prefer": "always" }] | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/prefer-class-directive/valid/empty/_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": [{ "prefer": "empty" }] | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/fixtures/rules/prefer-class-directive/valid/empty/ignore-test05-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
let a = true; | ||
let a7 = 7; | ||
let danger = false; | ||
</script> | ||
|
||
<button class={a ? 'a' : 'b'}>foo</button> | ||
<button class={!a ? 'b' : 'a'}>foo</button> | ||
<button class={a7 === 7 ? 'a' : 'b'}>foo</button> | ||
<button class="btn {danger ? 'btn-danger' : 'btn-primary'}">foo</button> |