Skip to content

Commit fb3a173

Browse files
authored
Fix false positives for system rule (#16)
1 parent 531c5e6 commit fb3a173

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/rules/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default createRule("system", {
2222

2323
const ignoreWarnings =
2424
context.settings?.["@ota-meshi/svelte"]?.ignoreWarnings
25-
if (!Array.isArray(ignoreWarnings)) {
25+
if (ignoreWarnings && !Array.isArray(ignoreWarnings)) {
2626
context.report({
2727
loc: { line: 1, column: 0 },
2828
message:
@@ -31,7 +31,7 @@ export default createRule("system", {
3131
return {}
3232
}
3333
const ignoreTests: ((ruleId: string) => boolean)[] = []
34-
for (const ignoreWarning of ignoreWarnings) {
34+
for (const ignoreWarning of ignoreWarnings || []) {
3535
if (typeof ignoreWarning !== "string") {
3636
context.report({
3737
loc: { line: 1, column: 0 },

tests/src/settings/ignore-warnings.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,38 @@ describe("ignore-warnings", () => {
125125
],
126126
)
127127
})
128+
129+
it("without settings", async () => {
130+
const code = `
131+
{@html a+b}
132+
{@debug a}
133+
<script>
134+
a+b;
135+
</script>
136+
`
137+
138+
const linter = new eslint.ESLint({
139+
plugins: {
140+
"@ota-meshi/svelte": plugin,
141+
},
142+
baseConfig: {
143+
parser: require.resolve("svelte-eslint-parser"),
144+
parserOptions: {
145+
ecmaVersion: 2020,
146+
},
147+
plugins: ["@ota-meshi/svelte"],
148+
rules: {
149+
"@ota-meshi/svelte/system": "error",
150+
},
151+
},
152+
useEslintrc: false,
153+
})
154+
const result = await linter.lintText(code, { filePath: "test.svelte" })
155+
const messages = result[0].messages
156+
157+
assert.deepStrictEqual(
158+
messages.map((m) => ({ ruleId: m.ruleId, line: m.line })),
159+
[],
160+
)
161+
})
128162
})

0 commit comments

Comments
 (0)