-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathbase.ts
85 lines (79 loc) · 2.07 KB
/
base.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
})),
[]
);
});
});