4.4.22.3.0-dev.20170215tsconfig.json
{ "files": ["src/a.ts"] }
tslint.json
{ "rules": { "semicolon": true } }
src/a.ts, src/b.ts
(blank)
tslint --project tsconfig.json --type-check src/b.ts fails with Invalid source file: src/b.ts. Ensure that the files supplied to lint have a .ts, .tsx, .js or .jsx extension.tslint --project tsconfig.json --type-check src/c.ts succeeds.src/b.ts, it should fail with an error about the file not being in the project.src/c.ts, it should fail with an error about the file not existing.This just tripped me up. I agree, that error message is a problem.
I had an exclude in my tsconfig.json that was inadvertantly matching too many files. If the error message had said "not processing test because it's excluded in tsconfig.json", I would have fixed it in 10 seconds.
But, since tslint appeared to be complaining about the file's extension, I spent quite a while barking up the wrong trees.
5.7.02.3.4linter-tslintI have a configuration with two tsconfig.json, one for src (next to the package.json), and one for test (inside test):
- src/
- test/
- tsconfig.json # extends ../tsconfig.json, overrides includes/excludes
- package.json
- tsconfig.json # main config with compilerOptions
It's very annoying because Atom linter pops up every error that happens within linters, and this error happens on each keystroke/save for tslint via linter-tslint.
[Linter] Error running TSLint Error:
Invalid source file: /Users/__CENSORED__/test/__CENSORED__.ts.
Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.

tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": [ "ES2017" ],
"module": "commonjs",
"outDir": "./lib",
"sourceMap": true,
"listFiles": false,
"listEmittedFiles": false,
"pretty": true,
"traceResolution": false,
"declaration": true,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"strictNullChecks": true,
"downlevelIteration": true,
"typeRoots": [
"./node_modules/@my-company/ts-build-tools/node_modules/@types",
"./node_modules/@types"
]
},
"include": [
"./src/**/*.ts",
"./typings/**/*.d.ts",
"./node_modules/@my-company/ts-build-tools/shared/typings/**/*.d.ts"
],
"exclude": [
"./node_modules"
]
}
test/tsconfig.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../lib/test"
},
"include": [
"../test/**/*.ts",
"../typings/**/*.d.ts",
"../node_modules/@my-company/ts-build-tools/shared/typings/**/*.d.ts"
],
"exclude": [
"../node_modules"
]
}
I've investigated this issue on my configuration and discovered that tslint findConfigurationPath fails to pick up the proper tsconfig.json that sits right next to the linted file.
As I've debugged within Atom, I had to use a hacky technique to get the intermediate program state out: I've hijacked the compiled tslint JS code right in node_modules like this, having the exception message with the necessary data (plain console prints nothing in that environment):
// convert to dir if it's a file or doesn't exist
var useDirName = false;
var inputFilePathBeforeDirname = inputFilePath;
try {
var stats = fs.statSync(inputFilePath);
if (stats.isFile()) {
useDirName = true;
}
}
catch (e) {
// throws if file doesn't exist
useDirName = true;
}
if (useDirName) {
inputFilePath = path.dirname(inputFilePath);
}
// search for tslint.json from input file location
var configFilePath = findup(exports.CONFIG_FILENAME, inputFilePath);
throw new error_1.FatalError(JSON.stringify({
useDirName: useDirName,
inputFilePathBeforeDirname: inputFilePathBeforeDirname,
inputFilePath: inputFilePath,
configFilePath: configFilePath,
}, null, 2));
I got the following (sorry for censored paths, but they don't change the error):
{
"useDirName": true,
"inputFilePathBeforeDirname": "/Users/__PROJECTDIR__/test/__TESTFILE__.ts",
"inputFilePath": "/Users/__PROJECTDIR__/test",
"configFilePath": "/Users/__PROJECTDIR__/tslint.json"
}
Looks like findup doesn't look into the passed-in directory path (/Users/__PROJECTDIR__/test), starts by going up first (/Users/__PROJECTDIR__).
Oh wow, I didn't notice that it looks for tslint.json, not tsconfig.json, and uses that path to point the compiler to the tsconfig.json.
From findup findFile:
{
"cwd": "/Users/__PROJECTDIR__/test",
"filename": "tslint.json",
"pathjoin": "/Users/__PROJECTDIR__/test/tslint.json",
"fsexistsSync": false
}
So to work that error around I have to put an extra test/tslint.json next to my test/tsconfig.json...
Yes, adding test/tslint.json, and the error no longer appears, linter works on my test files. 馃帀
{
"extends": "../tslint.json"
}
Most helpful comment
This just tripped me up. I agree, that error message is a problem.
I had an exclude in my tsconfig.json that was inadvertantly matching too many files. If the error message had said "not processing test because it's excluded in tsconfig.json", I would have fixed it in 10 seconds.
But, since tslint appeared to be complaining about the file's extension, I spent quite a while barking up the wrong trees.