Skip to content

Commit 785a3d8

Browse files
authored
fix: false positives for style tag in no-raw-text (#15)
* fix: false positives for style tag in no-raw-text * Create hungry-news-hug.md * fix
1 parent d1c194b commit 785a3d8

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/hungry-news-hug.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@intlify/eslint-plugin-svelte": patch
3+
---
4+
5+
fix: false positives for style tag in no-raw-text

lib/rules/no-raw-text.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ function create(context: RuleContext): RuleListener {
185185
return false
186186
}
187187

188+
if (element.type === 'SvelteStyleElement') {
189+
return true
190+
}
191+
188192
return config.ignoreNodes.includes(
189193
sourceCode.text.slice(...element.name.range!)
190194
)
@@ -194,6 +198,7 @@ function create(context: RuleContext): RuleListener {
194198
| SvAST.SvelteText['parent']
195199
| SvAST.SvelteMustacheTag['parent']
196200
| SvAST.SvelteElement
201+
| SvAST.SvelteSpecialElement
197202
| SvAST.SvelteAwaitBlock
198203
| SvAST.SvelteElseBlockElseIf = node.parent
199204
while (
@@ -208,7 +213,10 @@ function create(context: RuleContext): RuleListener {
208213
) {
209214
target = target.parent
210215
}
211-
if (target.type === 'SvelteElement') {
216+
if (
217+
target.type === 'SvelteElement' ||
218+
target.type === 'SvelteStyleElement'
219+
) {
212220
return target
213221
}
214222
return null

tests/lib/rules/no-raw-text.ts

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ tester.run('no-raw-text', rule as never, {
5454
{ $_('root level translation') }
5555
`,
5656
options: []
57+
},
58+
{
59+
code: `
60+
<style>
61+
h1 {
62+
background: blue;
63+
}
64+
</style>`
5765
}
5866
],
5967

0 commit comments

Comments
 (0)