-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathrecommended.ts
58 lines (53 loc) · 1.54 KB
/
recommended.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import assert from 'assert';
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 () => {
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`;
const linter = new LegacyESLint({
plugins: {
svelte: plugin as never
},
baseConfig: {
parserOptions: {
ecmaVersion: 2020
},
extends: ['plugin:svelte/recommended']
},
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: 1
}
]
);
});
it('`all` 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}`;
const linter = new ESLint({
overrideConfigFile: true as never,
overrideConfig: plugin.configs['flat/recommended'] 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: 1
}
]
);
});
});