11import { findRawConfiguration } from "./findRawConfiguration" ;
22import { findReportedConfiguration } from "./findReportedConfiguration" ;
33import { Exec } from "../adapters/exec" ;
4- import { OriginalConfigurations } from "./findOriginalConfigurations" ;
54import { SansDependencies } from "../binding" ;
65import { importer } from "./importer" ;
6+ import { isDefined } from "../utils" ;
77
88export type TSLintConfiguration = {
99 extends ?: string [ ] ;
10- rulesDirectory : string [ ] ;
10+ rulesDirectory ? : string [ ] ;
1111 rules : TSLintConfigurationRules ;
1212} ;
1313
1414export type TSLintConfigurationRules = Record < string , any > ;
1515
16- const defaultTSLintConfiguration = {
17- extends : [ ] ,
18- rulesDirectory : [ ] ,
19- rules : { } ,
20- } ;
21-
2216export type FindTSLintConfigurationDependencies = {
2317 exec : Exec ;
2418 importer : SansDependencies < typeof importer > ;
@@ -27,12 +21,10 @@ export type FindTSLintConfigurationDependencies = {
2721export const findTSLintConfiguration = async (
2822 dependencies : FindTSLintConfigurationDependencies ,
2923 config : string | undefined ,
30- ) : Promise < OriginalConfigurations < TSLintConfiguration > | Error > => {
24+ ) => {
3125 const filePath = config || "./tslint.json" ;
3226 const [ rawConfiguration , reportedConfiguration ] = await Promise . all ( [
33- findRawConfiguration < Partial < TSLintConfiguration > > ( dependencies . importer , filePath , {
34- extends : [ ] ,
35- } ) ,
27+ findRawConfiguration < Partial < TSLintConfiguration > > ( dependencies . importer , filePath ) ,
3628 findReportedConfiguration < TSLintConfiguration > (
3729 dependencies . exec ,
3830 "tslint --print-config" ,
@@ -52,15 +44,23 @@ export const findTSLintConfiguration = async (
5244 return rawConfiguration ;
5345 }
5446
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+
5560 return {
5661 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,
6464 } ,
6565 raw : rawConfiguration ,
6666 } ;
0 commit comments