Skip to content

Commit eaf5e6a

Browse files
authored
fix: suppress comment not working in flat config. (#719)
1 parent 25c2a7d commit eaf5e6a

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

.changeset/eighty-pillows-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-svelte": patch
3+
---
4+
5+
fix: suppress comment not working in flat config.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"rimraf": "^5.0.5",
164164
"sass": "^1.71.1",
165165
"source-map-js": "^1.0.2",
166-
"stylelint": "^16.2.1",
166+
"stylelint": "~16.2.1",
167167
"stylelint-config-standard": "^36.0.0",
168168
"stylus": "^0.63.0",
169169
"svelte": "^5.0.0-next.73",

src/configs/flat/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default [
2727
// eslint-plugin-svelte rules
2828
'svelte/comment-directive': 'error',
2929
'svelte/system': 'error'
30-
}
30+
},
31+
processor: 'svelte/svelte'
3132
}
3233
];

tests/src/configs/base.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import assert from 'assert';
2+
import semver from 'semver';
3+
import plugin from '../../../src/index';
4+
import { LegacyESLint, ESLint } from '../../utils/eslint-compat';
5+
6+
describe('`base` config', () => {
7+
it('legacy `base` config should work. ', async () => {
8+
const code = `<script>const a = 1, b = 2;</script>
9+
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
10+
{@html a+b}
11+
{@html a+b}`;
12+
13+
const linter = new LegacyESLint({
14+
plugins: {
15+
svelte: plugin as never
16+
},
17+
baseConfig: {
18+
parserOptions: {
19+
ecmaVersion: 2020
20+
},
21+
extends: ['plugin:svelte/base'],
22+
rules: {
23+
'svelte/no-at-html-tags': 'error'
24+
}
25+
},
26+
useEslintrc: false
27+
});
28+
const result = await linter.lintText(code, { filePath: 'test.svelte' });
29+
const messages = result[0].messages;
30+
31+
assert.deepStrictEqual(
32+
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })),
33+
[
34+
{
35+
ruleId: 'svelte/no-at-html-tags',
36+
message: '`{@html}` can lead to XSS attack.',
37+
line: 4
38+
}
39+
]
40+
);
41+
});
42+
it('`base` config should work. ', async () => {
43+
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
44+
const code = `<script>const a = 1, b = 2;</script>
45+
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
46+
{@html a+b}
47+
{@html a+b}`;
48+
const linter = new ESLint({
49+
overrideConfigFile: true as never,
50+
overrideConfig: [
51+
...plugin.configs['flat/base'],
52+
{
53+
rules: {
54+
'svelte/no-at-html-tags': 'error'
55+
}
56+
}
57+
] as never
58+
});
59+
const result = await linter.lintText(code, { filePath: 'test.svelte' });
60+
const messages = result[0].messages;
61+
62+
assert.deepStrictEqual(
63+
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })),
64+
[
65+
{
66+
ruleId: 'svelte/no-at-html-tags',
67+
message: '`{@html}` can lead to XSS attack.',
68+
line: 4
69+
}
70+
]
71+
);
72+
73+
const resultWithJs = await linter.lintText(';', { filePath: 'test.js' });
74+
const messagesWithJs = resultWithJs[0].messages;
75+
76+
assert.deepStrictEqual(
77+
messagesWithJs.map((m) => ({
78+
ruleId: m.ruleId,
79+
line: m.line,
80+
message: m.message
81+
})),
82+
[]
83+
);
84+
});
85+
});

tests/src/configs/recommended.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import semver from 'semver';
33
import plugin from '../../../src/index';
44
import { LegacyESLint, ESLint } from '../../utils/eslint-compat';
55

6-
describe('`all` config', () => {
7-
it('legacy `all` config should work. ', async () => {
6+
describe('`recommended` config', () => {
7+
it('legacy `recommended` config should work. ', async () => {
88
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`;
99

1010
const linter = new LegacyESLint({
@@ -33,7 +33,7 @@ describe('`all` config', () => {
3333
]
3434
);
3535
});
36-
it('`all` config should work. ', async () => {
36+
it('`recommended` config should work. ', async () => {
3737
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
3838
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`;
3939

tools/update-rulesets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export default [
139139
})
140140
.join(',\n ')},
141141
},
142+
processor: 'svelte/svelte'
142143
},
143144
]
144145
`;

0 commit comments

Comments
 (0)