@@ -10,7 +10,7 @@ import { shim } from "./compat-shim";
10
10
import { defaultConfig } from "./config"
11
11
import type { ConfigSchema } from "./config"
12
12
import type { emit } from 'node:cluster' ;
13
- import type * as Tslint from "tslint" ;
13
+ import * as Tslint from "tslint" ;
14
14
import type * as Ts from "typescript" ;
15
15
import type { JobMessage , ConfigMessage } from "./workerHelper"
16
16
import { RuleFailure } from 'tslint' ;
@@ -141,6 +141,41 @@ function getSeverity(failure: RuleFailure) {
141
141
return [ 'info' , 'warning' , 'error' ] . includes ( severity ) ? severity : 'warning' ;
142
142
}
143
143
144
+ function loadTslintConfig ( Linter : typeof Tslint . Linter , filePath : string ) {
145
+ let configurationPath : string | undefined
146
+ let configuration : Tslint . Configuration . IConfigurationFile | undefined
147
+ if ( typeof Linter . findConfiguration === "function" ) {
148
+ const { path, results } = Linter . findConfiguration ( null , filePath )
149
+ configurationPath = path
150
+ configuration = results
151
+ } else {
152
+ configurationPath = Linter . findConfigurationPath ( null , filePath ) ;
153
+ configuration = Linter . loadConfigurationFromPath ( configurationPath ) ;
154
+ }
155
+ // Load extends using `require` - this is a bug in Tslint
156
+ let configExtends = configuration ?. extends ?? [ ]
157
+ if ( configurationPath !== undefined && configExtends !== undefined && configExtends . length === 0 ) {
158
+ try {
159
+ const configurationJson = Tslint . Configuration . readConfigurationFile ?.( configurationPath )
160
+ const extendsJson = configurationJson . extends
161
+ if ( typeof extendsJson === "string" ) {
162
+ configExtends = [ ...configExtends , extendsJson ]
163
+ } else if ( extendsJson !== undefined ) {
164
+ configExtends = [ ...configExtends , ...extendsJson ]
165
+ }
166
+ } catch { /* ignore error */ }
167
+ }
168
+ return {
169
+ configurationPath,
170
+ configuration : configuration !== undefined
171
+ ? {
172
+ ...configuration ,
173
+ extends : configExtends
174
+ }
175
+ : configuration
176
+ }
177
+ }
178
+
144
179
/**
145
180
* Lint the provided TypeScript content
146
181
* @param content {string} The content of the TypeScript file
@@ -159,10 +194,9 @@ async function lint(content: string, filePath: string | undefined, options: Tsli
159
194
if ( ! Linter ) {
160
195
throw new Error ( `tslint was not found for ${ filePath } ` )
161
196
}
162
- const configurationPath = Linter . findConfigurationPath ( null , filePath ) ;
163
- const configuration = Linter . loadConfigurationFromPath ( configurationPath ) ;
197
+ const { configurationPath, configuration } = loadTslintConfig ( Linter , filePath )
164
198
165
- let { rulesDirectory } = configuration ;
199
+ let rulesDirectory = configuration ?. rulesDirectory ;
166
200
if ( rulesDirectory && configurationPath ) {
167
201
const configurationDir = path . dirname ( configurationPath ) ;
168
202
if ( ! Array . isArray ( rulesDirectory ) ) {
0 commit comments