Skip to content

Stop error checking script blocks#19228

Merged
billti merged 1 commit into
release-2.5from
dev/billti/fixScriptKindsTypeChecked
Oct 16, 2017
Merged

Stop error checking script blocks#19228
billti merged 1 commit into
release-2.5from
dev/billti/fixScriptKindsTypeChecked

Conversation

@billti
Copy link
Copy Markdown
Member

@billti billti commented Oct 16, 2017

Set the script kind as provided by the editor for the extra file extensions in the 'configure' command.

Without this, the ScriptKind was being left undefined, and later ensureScriptKind was defaulting it to TypeScript - which means it was getting type checked by default.

CC @mhegazy @amcasey

Comment thread src/compiler/core.ts
export function getAnyExtensionFromPath(path: string): string | undefined {
const baseFileName = getBaseFileName(path);
const extensionIndex = baseFileName.lastIndexOf(".");
if (extensionIndex >= 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the file extension of something like .gitconfig? If we decide that it has no file extension (because that's not really what dot means in that position) we just have to change >= to >.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I always think of those as files with just an extension. Not sure it matters in this case (e.g. if you have a file named .html, you probably want it treated as an HTML file.

Comment thread src/compiler/program.ts

// By default, only type-check .ts, .tsx, and 'External' files (external files are added by plugins)
const includeBindAndCheckDiagnostics = sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX ||
sourceFile.scriptKind === ScriptKind.External || isCheckJsEnabledForFile(sourceFile, options);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As an aside, I get confused every time I see a reference to "external" source files. It sounds like they relate to external projects. Maybe "plugin" or "extension" would be clearer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, that is an aside ;-)

For this quick & urgent fix, I don't intend to do a large refactoring across both managed and script side where this terminology is used. Maybe a suggestion for later though.

if (extraFileExtensions) {
const fileExtension = getAnyExtensionFromPath(fileName);
if (fileExtension) {
some(extraFileExtensions, info => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be more natural to write this with find?

Comment thread src/compiler/types.ts
export interface JsFileExtensionInfo {
extension: string;
isMixedContent: boolean;
scriptKind?: ScriptKind;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is populated by passing a ScriptInfo as a JsFileExtensionInfo. If that's the case, is this actually optional? Is the question mark just there in case a consumer has created their own implementation of the interface (i.e. for back compat)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I misunderstood - it's passed by the client.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For back-compat reasons for this late fix, I've tried to make the changes as benign as possible, rather than requiring extra fields. I may look for areas when porting to master where changes can be more explicit in changing expectations.

Comment thread src/compiler/program.ts

// By default, only type-check .ts, .tsx, and 'External' files (external files are added by plugins)
const includeBindAndCheckDiagnostics = sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX ||
sourceFile.scriptKind === ScriptKind.External || isCheckJsEnabledForFile(sourceFile, options);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does something about our parsing prevent checkJsDirective from being set for non-JS files (e.g. for JSON files)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wouldn't that fall through to the isCheckJsEnabledForFile(sourceFile, options) at the end of the OR clauses if so?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, wouldn't that be bad?

Copy link
Copy Markdown
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

LGTM. My only actual concern is that we might need to check for a JS script kind before/while calling isCheckJsEnabledForFile.

@billti billti merged commit 6d19326 into release-2.5 Oct 16, 2017
@billti billti deleted the dev/billti/fixScriptKindsTypeChecked branch October 16, 2017 21:59
billti added a commit that referenced this pull request Oct 18, 2017
billti added a commit that referenced this pull request Oct 18, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants