1
1
import { findRawConfiguration } from "./findRawConfiguration" ;
2
2
import { findReportedConfiguration } from "./findReportedConfiguration" ;
3
3
import { Exec } from "../adapters/exec" ;
4
- import { OriginalConfigurations } from "./findOriginalConfigurations" ;
5
4
import { SansDependencies } from "../binding" ;
6
5
import { importer } from "./importer" ;
6
+ import { isDefined } from "../utils" ;
7
7
8
8
export type TSLintConfiguration = {
9
9
extends ?: string [ ] ;
10
- rulesDirectory : string [ ] ;
10
+ rulesDirectory ? : string [ ] ;
11
11
rules : TSLintConfigurationRules ;
12
12
} ;
13
13
14
14
export type TSLintConfigurationRules = Record < string , any > ;
15
15
16
- const defaultTSLintConfiguration = {
17
- extends : [ ] ,
18
- rulesDirectory : [ ] ,
19
- rules : { } ,
20
- } ;
21
-
22
16
export type FindTSLintConfigurationDependencies = {
23
17
exec : Exec ;
24
18
importer : SansDependencies < typeof importer > ;
@@ -27,12 +21,10 @@ export type FindTSLintConfigurationDependencies = {
27
21
export const findTSLintConfiguration = async (
28
22
dependencies : FindTSLintConfigurationDependencies ,
29
23
config : string | undefined ,
30
- ) : Promise < OriginalConfigurations < TSLintConfiguration > | Error > => {
24
+ ) => {
31
25
const filePath = config || "./tslint.json" ;
32
26
const [ rawConfiguration , reportedConfiguration ] = await Promise . all ( [
33
- findRawConfiguration < Partial < TSLintConfiguration > > ( dependencies . importer , filePath , {
34
- extends : [ ] ,
35
- } ) ,
27
+ findRawConfiguration < Partial < TSLintConfiguration > > ( dependencies . importer , filePath ) ,
36
28
findReportedConfiguration < TSLintConfiguration > (
37
29
dependencies . exec ,
38
30
"tslint --print-config" ,
@@ -52,15 +44,23 @@ export const findTSLintConfiguration = async (
52
44
return rawConfiguration ;
53
45
}
54
46
47
+ const extensions = Array . from (
48
+ new Set (
49
+ [ [ rawConfiguration . extends ] , [ reportedConfiguration . extends ] ]
50
+ . flat ( Infinity )
51
+ . filter ( isDefined ) ,
52
+ ) ,
53
+ ) ;
54
+
55
+ const rules = {
56
+ ...rawConfiguration . rules ,
57
+ ...reportedConfiguration . rules ,
58
+ } ;
59
+
55
60
return {
56
61
full : {
57
- ...defaultTSLintConfiguration ,
58
- ...rawConfiguration ,
59
- extends : Array . from (
60
- new Set (
61
- [ [ rawConfiguration . extends ] , [ reportedConfiguration . extends ] ] . flat ( Infinity ) ,
62
- ) ,
63
- ) ,
62
+ ...( extensions . length !== 0 && { extends : extensions } ) ,
63
+ rules,
64
64
} ,
65
65
raw : rawConfiguration ,
66
66
} ;
0 commit comments