forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (43 loc) · 1.55 KB
/
index.js
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
/*
NOTE - this file intentionally uses deep `/use-at-your-own-risk` imports into our packages.
This is so that esbuild can properly tree-shake and only include the necessary code.
This saves us having to mock unnecessary things and reduces our bundle size.
*/
// @ts-check
import eslintJs from '@eslint/js';
import * as plugin from '@typescript-eslint/eslint-plugin';
import { analyze } from '@typescript-eslint/scope-manager';
import {
astConverter,
getScriptKind,
} from '@typescript-eslint/typescript-estree/use-at-your-own-risk';
import { visitorKeys } from '@typescript-eslint/visitor-keys';
import { Linter } from 'eslint';
import esquery from 'esquery';
// don't change exports to export *
exports.getScriptKind = getScriptKind;
exports.analyze = analyze;
exports.visitorKeys = visitorKeys;
exports.astConverter = astConverter;
exports.esquery = esquery;
exports.createLinter = function () {
const linter = new Linter({ configType: 'eslintrc' });
for (const name in plugin.rules) {
linter.defineRule(`@typescript-eslint/${name}`, plugin.rules[name]);
}
return linter;
};
/** @type {Record<string, unknown>} */
const configs = {};
for (const [name, value] of Object.entries(eslintJs.configs)) {
configs[`eslint:${name}`] = value;
}
for (const [name, value] of Object.entries(plugin.configs)) {
if (value.extends && Array.isArray(value.extends)) {
value.extends = value.extends.map(name =>
name.replace(/^\.\/configs\//, 'plugin:@typescript-eslint/'),
);
}
configs[`plugin:@typescript-eslint/${name}`] = value;
}
exports.configs = configs;