@@ -18,7 +18,6 @@ const Task = require('../ember-cli/lib/models/task');
1818export interface CliLintConfig {
1919 files ?: ( string | string [ ] ) ;
2020 project ?: string ;
21- projectOnly ?: boolean ;
2221 tslintConfig ?: string ;
2322 exclude ?: ( string | string [ ] ) ;
2423}
@@ -77,8 +76,7 @@ export default Task.extend({
7776 let lastDirectory ;
7877 let configLoad ;
7978 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 ) ;
8280
8381 // Only check for a new tslint config if path changes
8482 const currentDirectory = path . dirname ( file ) ;
@@ -87,7 +85,7 @@ export default Task.extend({
8785 lastDirectory = currentDirectory ;
8886 }
8987
90- linter . lint ( file , fileContents , configLoad . results ) ;
88+ linter . lint ( file , contents , configLoad . results ) ;
9189 }
9290
9391 return linter . getResult ( ) ;
@@ -173,11 +171,25 @@ function getFilesToLint(
173171 return programFiles ;
174172}
175173
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+
177189 // NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
178190 try {
179191 return stripBom ( fs . readFileSync ( file , 'utf-8' ) ) ;
180192 } catch ( e ) {
181- throw new SilentError ( `Could not read file " ${ file } " .` ) ;
193+ throw new SilentError ( `Could not read file ' ${ file } ' .` ) ;
182194 }
183195}
0 commit comments