-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.test.ts
More file actions
58 lines (52 loc) · 1.6 KB
/
main.test.ts
File metadata and controls
58 lines (52 loc) · 1.6 KB
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 {describe, it, expect} from 'vitest';
import {ESLint, type Linter} from 'eslint';
import jsoncParser from 'jsonc-eslint-parser';
import json from '@eslint/json';
import plugin from './main.js';
describe('main plugin', () => {
it('should run against JSON files using jsonc-eslint-parser', async () => {
const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: [
{
files: ['**/*.json'],
languageOptions: {
parser: jsoncParser
}
},
plugin.configs!.recommended as Linter.Config
]
});
const results = await eslint.lintText(
JSON.stringify({name: 'test', version: '1.0.0'}, null, 2),
{filePath: 'package.json'}
);
expect(results).toBeDefined();
expect(results).toHaveLength(1);
expect(results[0]!.messages).toHaveLength(0);
expect(results[0]!.filePath).toContain('package.json');
});
it('should run against JSON files using @eslint/json', async () => {
const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: [
{
files: ['**/*.json'],
plugins: {
json
},
language: 'json/json'
},
plugin.configs!.recommended as Linter.Config
]
});
const results = await eslint.lintText(
JSON.stringify({name: 'test', version: '1.0.0'}, null, 2),
{filePath: 'package.json'}
);
expect(results).toBeDefined();
expect(results).toHaveLength(1);
expect(results[0]!.messages).toHaveLength(0);
expect(results[0]!.filePath).toContain('package.json');
});
});