-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: suppress comment not working in flat config. (#719)
- Loading branch information
Showing
6 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
})), | ||
[] | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,7 @@ export default [ | |
}) | ||
.join(',\n ')}, | ||
}, | ||
processor: 'svelte/svelte' | ||
}, | ||
] | ||
`; | ||
|