|
| 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('`all` config', () => { |
| 7 | + it('legacy `all` config should work. ', async () => { |
| 8 | + const code = `<script>const a = 1, b = 2;</script>{@html a+b}`; |
| 9 | + |
| 10 | + const linter = new LegacyESLint({ |
| 11 | + plugins: { |
| 12 | + svelte: plugin as never |
| 13 | + }, |
| 14 | + baseConfig: { |
| 15 | + parserOptions: { |
| 16 | + ecmaVersion: 2020 |
| 17 | + }, |
| 18 | + extends: ['plugin:svelte/recommended'] |
| 19 | + }, |
| 20 | + useEslintrc: false |
| 21 | + }); |
| 22 | + const result = await linter.lintText(code, { filePath: 'test.svelte' }); |
| 23 | + const messages = result[0].messages; |
| 24 | + |
| 25 | + assert.deepStrictEqual( |
| 26 | + messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })), |
| 27 | + [ |
| 28 | + { |
| 29 | + ruleId: 'svelte/no-at-html-tags', |
| 30 | + message: '`{@html}` can lead to XSS attack.', |
| 31 | + line: 1 |
| 32 | + } |
| 33 | + ] |
| 34 | + ); |
| 35 | + }); |
| 36 | + it('`all` config should work. ', async () => { |
| 37 | + if (semver.satisfies(ESLint.version, '<8.0.0')) return; |
| 38 | + const code = `<script>const a = 1, b = 2;</script>{@html a+b}`; |
| 39 | + |
| 40 | + const linter = new ESLint({ |
| 41 | + overrideConfigFile: true as never, |
| 42 | + overrideConfig: plugin.configs['flat/recommended'] as never |
| 43 | + }); |
| 44 | + const result = await linter.lintText(code, { filePath: 'test.svelte' }); |
| 45 | + const messages = result[0].messages; |
| 46 | + |
| 47 | + assert.deepStrictEqual( |
| 48 | + messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })), |
| 49 | + [ |
| 50 | + { |
| 51 | + ruleId: 'svelte/no-at-html-tags', |
| 52 | + message: '`{@html}` can lead to XSS attack.', |
| 53 | + line: 1 |
| 54 | + } |
| 55 | + ] |
| 56 | + ); |
| 57 | + }); |
| 58 | +}); |
0 commit comments