-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrslintConfig.ts
More file actions
49 lines (41 loc) · 1.57 KB
/
Copy pathrslintConfig.ts
File metadata and controls
49 lines (41 loc) · 1.57 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
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { loadRstackConfig, type LoadedRstackConfig } from './config.ts';
import type { RslintConfig } from '@rslint/core';
// Expose the loaded config so `rs check` can pass it to fmt instead of loading
// and executing the Rstack config a second time.
export const loadedConfig: LoadedRstackConfig = await loadRstackConfig();
const { configs } = loadedConfig;
const lintDefinition = configs.lint ?? [];
let lintConfig: RslintConfig;
// TODO: support function in Rslint core
if (typeof lintDefinition === 'function') {
lintConfig = await lintDefinition();
} else {
lintConfig = lintDefinition;
}
const basePath = process.cwd();
const lintEntries = lintConfig.flat();
// Rslint resolves entries without a basePath from the explicit config file.
// Rstack's explicit config is this internal module, so preserve the historical
// behavior of resolving user-authored paths from the invocation directory.
const resolvedLintConfig: RslintConfig = lintEntries.map((entry) => ({
basePath,
...entry,
}));
const hasExplicitProject = lintEntries.some(
(entry) => entry.languageOptions?.parserOptions?.project !== undefined,
);
// Rslint's implicit tsconfig lookup also follows the internal config directory.
// Preserve the CWD lookup without overriding user projects.
if (!hasExplicitProject && existsSync(join(basePath, 'tsconfig.json'))) {
resolvedLintConfig.push({
basePath,
languageOptions: {
parserOptions: {
project: ['./tsconfig.json'],
},
},
});
}
export default resolvedLintConfig;