Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Handle non-existent files and custom file extensions #53

Merged
merged 8 commits into from
Dec 27, 2018

Conversation

uniqueiniquity
Copy link
Contributor

This PR addresses two main issues brought up in #50 when using the --project flag.

  • If the file being parsed doesn't actually exist, the source file will not be found in the program generated from the tsconfig and the default, incomplete project will be returned.
  • If the file being parsed has a non-traditional file extension (such as .vue), the source file will not be found in the program generated from the tsconfig and the default, incomplete project will be used.
    While these two issues have the same general root cause (i.e. we build programs from the provided tsconfig(s) and then expect the file being parsed to be part of one of them), we address them separately.

For the former issue, we allow for a non-existent file to be used by parsing the compiler options out of a single tsconfig and building a program with that single, non-existent file and those compiler options. My intent was that this should be primarily used for test cases, which may provide code to be parsed instead of the contents of an actual file.

For the latter, we allow for a new string array option extraFileExtensions. This is then passed to the TypeScript API so that it will additionally include files with the provided file extensions when resolving the root files of a given program from a tsconfig. Unfortunately, this implementation uses an undocumented extension point in the TS API, so I will be making a change to TypeScript so this behavior is officially supported moving forward.

@uniqueiniquity
Copy link
Contributor Author

@JamesHenry @armano2

src/node-utils.ts Outdated Show resolved Hide resolved
@uniqueiniquity
Copy link
Contributor Author

Also addresses concerns mentioned in eslint/typescript-eslint-parser#568

@armano2
Copy link
Contributor

armano2 commented Dec 26, 2018

@uniqueiniquity i tested it and seems to work, but can you add test scenario when you do not read file at all, but provide it as code with not existing filename?

@uniqueiniquity
Copy link
Contributor Author

@armano2 thanks for taking a look. I intended 'non-existent file tests' to test that scenario, since the filename I provided is <input>. Would you like me to add one with a not existing filename that looks more like a real filename?

@armano2
Copy link
Contributor

armano2 commented Dec 26, 2018

.... i'm gettin blind i didn't see this test xd

Copy link
Owner

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @uniqueiniquity!

@JamesHenry JamesHenry merged commit 3be357e into JamesHenry:master Dec 27, 2018
@JamesHenry
Copy link
Owner

🎉 This PR is included in version 7.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants