-
Notifications
You must be signed in to change notification settings - Fork 885
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error for files not in the project is also thrown for non-existant files
How do you get to this state? By supplying a nonexistent filepath in "files"
in tsconfig.json?
does not match the behavior without --project because glob simply ignores files that don't exist. -> throw an error there, too?
Yeah, I think I'd prefer this approach. Sounds like a serious misconfiguration of the linter if this happens.
src/runner.ts
Outdated
files = files.map((f) => path.resolve(f)); | ||
filesFound = filterFiles(program.getSourceFiles().map((f) => f.fileName), files, true); | ||
for (const file of files) { | ||
if (!glob.hasMagic(file)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little tricky; can you leave some comments to make this easier to follow? how do special characters in the pattern affect the logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given a project that only includes index.ts
.
If you run tslint -p . '*.js' '*.ts'
you only lint index.ts
. *.js
doesn't match anything but is ignored because it's a glob pattern ("has magic").
On the other hand if you run tslint -p . index.ts test/index.ts
you get an error because test/index.ts
is not in the project. That's because it doesn't have magic. With the current implementation it doesn't even matter if the file exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense; I meant to say -- can you leave a code comment
I think a changelog entry would be useful too, especially for the #2208 fix. Also we could mention potential performance improvements since we're not doing redundant file reads? |
You can still pass arbitrary file names as arguments to the CLI. For a project that contains only |
RE: throwing error on non-existant files |
yeah, that seems reasonable 👍 |
@adidahiya updated the PR description to add changelog entries, added warnings for non-existent files with and without |
PR checklist
fs.readFileSync
call #2584, Misleading error for file not in project #2208Overview of change:
Consistently uses absolute paths when dealing with
ts.Program
.Don't use
glob
to find files, look them up ints.Program
instead.Don't read files from disk, because they are already available as
ts.SourceFile
.Fixes: #2584
Provide a better error message if a specified file is not part of the project.
Fixes: #2208
Is there anything you'd like reviewers to focus on?
Linter
should get a new methodlintFile
orlintSourceFile
. That can be done afterwards.CHANGELOG.md entry:
[bugfix] better error message for files not contained in the project
[enhancement] avoid duplicate IO when using
--project
option[deprecation] Linting non-existent files outputs a warning. This will be an error in TSLint 6.