Skip to content

fix: suppress comment not working in flat config. #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-pillows-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": patch
---

fix: suppress comment not working in flat config.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"rimraf": "^5.0.5",
"sass": "^1.71.1",
"source-map-js": "^1.0.2",
"stylelint": "^16.2.1",
"stylelint": "~16.2.1",
"stylelint-config-standard": "^36.0.0",
"stylus": "^0.63.0",
"svelte": "^5.0.0-next.73",
Expand Down
3 changes: 2 additions & 1 deletion src/configs/flat/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default [
// eslint-plugin-svelte rules
'svelte/comment-directive': 'error',
'svelte/system': 'error'
}
},
processor: 'svelte/svelte'
}
];
85 changes: 85 additions & 0 deletions tests/src/configs/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import assert from 'assert';
import semver from 'semver';
import plugin from '../../../src/index';
import { LegacyESLint, ESLint } from '../../utils/eslint-compat';

describe('`base` config', () => {
it('legacy `base` config should work. ', async () => {
const code = `<script>const a = 1, b = 2;</script>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html a+b}
{@html a+b}`;

const linter = new LegacyESLint({
plugins: {
svelte: plugin as never
},
baseConfig: {
parserOptions: {
ecmaVersion: 2020
},
extends: ['plugin:svelte/base'],
rules: {
'svelte/no-at-html-tags': 'error'
}
},
useEslintrc: false
});
const result = await linter.lintText(code, { filePath: 'test.svelte' });
const messages = result[0].messages;

assert.deepStrictEqual(
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })),
[
{
ruleId: 'svelte/no-at-html-tags',
message: '`{@html}` can lead to XSS attack.',
line: 4
}
]
);
});
it('`base` config should work. ', async () => {
if (semver.satisfies(ESLint.version, '<8.0.0')) return;
const code = `<script>const a = 1, b = 2;</script>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html a+b}
{@html a+b}`;
const linter = new ESLint({
overrideConfigFile: true as never,
overrideConfig: [
...plugin.configs['flat/base'],
{
rules: {
'svelte/no-at-html-tags': 'error'
}
}
] as never
});
const result = await linter.lintText(code, { filePath: 'test.svelte' });
const messages = result[0].messages;

assert.deepStrictEqual(
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })),
[
{
ruleId: 'svelte/no-at-html-tags',
message: '`{@html}` can lead to XSS attack.',
line: 4
}
]
);

const resultWithJs = await linter.lintText(';', { filePath: 'test.js' });
const messagesWithJs = resultWithJs[0].messages;

assert.deepStrictEqual(
messagesWithJs.map((m) => ({
ruleId: m.ruleId,
line: m.line,
message: m.message
})),
[]
);
});
});
6 changes: 3 additions & 3 deletions tests/src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import semver from 'semver';
import plugin from '../../../src/index';
import { LegacyESLint, ESLint } from '../../utils/eslint-compat';

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

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

Expand Down
1 change: 1 addition & 0 deletions tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default [
})
.join(',\n ')},
},
processor: 'svelte/svelte'
},
]
`;
Expand Down
Loading