@@ -18,7 +18,6 @@ const Task = require('../ember-cli/lib/models/task');
18
18
export interface CliLintConfig {
19
19
files ?: ( string | string [ ] ) ;
20
20
project ?: string ;
21
- projectOnly ?: boolean ;
22
21
tslintConfig ?: string ;
23
22
exclude ?: ( string | string [ ] ) ;
24
23
}
@@ -77,8 +76,7 @@ export default Task.extend({
77
76
let lastDirectory ;
78
77
let configLoad ;
79
78
for ( const file of files ) {
80
- // The linter retrieves the SourceFile TS node directly if a program is used
81
- const fileContents = program ? undefined : getFileContents ( file ) ;
79
+ const contents = getFileContents ( file , config , program ) ;
82
80
83
81
// Only check for a new tslint config if path changes
84
82
const currentDirectory = path . dirname ( file ) ;
@@ -87,7 +85,7 @@ export default Task.extend({
87
85
lastDirectory = currentDirectory ;
88
86
}
89
87
90
- linter . lint ( file , fileContents , configLoad . results ) ;
88
+ linter . lint ( file , contents , configLoad . results ) ;
91
89
}
92
90
93
91
return linter . getResult ( ) ;
@@ -173,11 +171,25 @@ function getFilesToLint(
173
171
return programFiles ;
174
172
}
175
173
176
- function getFileContents ( file : string ) : string {
174
+ function getFileContents (
175
+ file : string ,
176
+ config : CliLintConfig ,
177
+ program ?: ts . Program ,
178
+ ) : string | undefined {
179
+ // The linter retrieves the SourceFile TS node directly if a program is used
180
+ if ( program ) {
181
+ if ( program . getSourceFile ( file ) == undefined ) {
182
+ const message = `File '${ file } ' is not part of the TypeScript project '${ config . project } '.` ;
183
+ throw new SilentError ( chalk . red ( message ) ) ;
184
+ }
185
+
186
+ return undefined ;
187
+ }
188
+
177
189
// NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
178
190
try {
179
191
return stripBom ( fs . readFileSync ( file , 'utf-8' ) ) ;
180
192
} catch ( e ) {
181
- throw new SilentError ( `Could not read file " ${ file } " .` ) ;
193
+ throw new SilentError ( `Could not read file ' ${ file } ' .` ) ;
182
194
}
183
195
}
0 commit comments