Skip to content

Commit

Permalink
fix: false positives for style tag in no-raw-text (#15)
Browse files Browse the repository at this point in the history
* fix: false positives for style tag in no-raw-text

* Create hungry-news-hug.md

* fix
  • Loading branch information
ota-meshi committed Apr 1, 2024
1 parent d1c194b commit 785a3d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hungry-news-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-svelte": patch
---

fix: false positives for style tag in no-raw-text
10 changes: 9 additions & 1 deletion lib/rules/no-raw-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ function create(context: RuleContext): RuleListener {
return false
}

if (element.type === 'SvelteStyleElement') {
return true
}

return config.ignoreNodes.includes(
sourceCode.text.slice(...element.name.range!)
)
Expand All @@ -194,6 +198,7 @@ function create(context: RuleContext): RuleListener {
| SvAST.SvelteText['parent']
| SvAST.SvelteMustacheTag['parent']
| SvAST.SvelteElement
| SvAST.SvelteSpecialElement
| SvAST.SvelteAwaitBlock
| SvAST.SvelteElseBlockElseIf = node.parent
while (
Expand All @@ -208,7 +213,10 @@ function create(context: RuleContext): RuleListener {
) {
target = target.parent
}
if (target.type === 'SvelteElement') {
if (
target.type === 'SvelteElement' ||
target.type === 'SvelteStyleElement'
) {
return target
}
return null
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-raw-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ tester.run('no-raw-text', rule as never, {
{ $_('root level translation') }
`,
options: []
},
{
code: `
<style>
h1 {
background: blue;
}
</style>`
}
],

Expand Down

0 comments on commit 785a3d8

Please sign in to comment.