Skip to content

Commit b9a2fe2

Browse files
committed
feat(no-inline-styles): added handling of transitions
1 parent 0cb6543 commit b9a2fe2

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

docs/rules/no-inline-styles.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This rule reports all attributes and directives that would compile to inline sty
2323
<script>
2424
/* eslint svelte/no-inline-styles: "error" */
2525
26+
import { fade } from 'svelte/transition';
27+
2628
export let classTwo;
2729
export let blockDisplay;
2830
</script>
@@ -36,6 +38,8 @@ This rule reports all attributes and directives that would compile to inline sty
3638
<span style="display: block;">Hello World!</span>
3739
3840
<span style:display={blockDisplay ? 'block' : 'inline'}>Hello World!</span>
41+
42+
<span transition:fade>Hello World!</span>
3943
```
4044

4145
</ESLintCodeBlock>
@@ -44,7 +48,12 @@ This rule reports all attributes and directives that would compile to inline sty
4448

4549
```json
4650
{
47-
"svelte/no-inline-styles": ["error", {}]
51+
"svelte/no-inline-styles": [
52+
"error",
53+
{
54+
"allowTransitions": false
55+
}
56+
]
4857
}
4958
```
5059

src/rules/no-inline-styles.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ export default createRule('no-inline-styles', {
77
category: 'Best Practices',
88
recommended: false
99
},
10-
schema: [],
10+
schema: [
11+
{
12+
type: 'object',
13+
properties: {
14+
allowTransitions: {
15+
type: 'boolean'
16+
}
17+
},
18+
additionalProperties: false
19+
}
20+
],
1121
messages: {
1222
hasStyleAttribute: 'Found disallowed style attribute.',
13-
hasStyleDirective: 'Found disallowed style directive.'
23+
hasStyleDirective: 'Found disallowed style directive.',
24+
hasTransition: 'Found disallowed transition.'
1425
},
1526
type: 'suggestion'
1627
},
1728
create(context) {
29+
const allowTransitions: boolean = context.options[0]?.allowTransitions ?? false;
1830
return {
1931
SvelteElement(node) {
2032
if (node.kind !== 'html') {
@@ -27,6 +39,13 @@ export default createRule('no-inline-styles', {
2739
if (attribute.type === 'SvelteAttribute' && attribute.key.name === 'style') {
2840
context.report({ loc: attribute.loc, messageId: 'hasStyleAttribute' });
2941
}
42+
if (
43+
!allowTransitions &&
44+
attribute.type === 'SvelteDirective' &&
45+
attribute.kind === 'Transition'
46+
) {
47+
context.report({ loc: attribute.loc, messageId: 'hasTransition' });
48+
}
3049
}
3150
}
3251
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- message: Found disallowed transition.
2+
line: 5
3+
column: 7
4+
suggestions: null
5+
- message: Found disallowed transition.
6+
line: 7
7+
column: 7
8+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import { fade, fly } from 'svelte/transition';
3+
</script>
4+
5+
<span transition:fade>Hello World!</span>
6+
7+
<span transition:fly={{ y: 200, duration: 2000 }}>Hello World!</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"options": [
3+
{
4+
"allowTransitions": true
5+
}
6+
]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import { fade, fly } from 'svelte/transition';
3+
</script>
4+
5+
<span transition:fade>Hello World!</span>
6+
7+
<span transition:fly={{ y: 200, duration: 2000 }}>Hello World!</span>

0 commit comments

Comments
 (0)