Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fix #525 - safe/consistent .tsx file type checks #526

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/noFunctionExpressionRule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';

import { AstUtils } from './utils/AstUtils';
import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker';
import {ExtendedMetadata} from './utils/ExtendedMetadata';

Expand Down Expand Up @@ -37,7 +38,8 @@ class NoFunctionExpressionRuleWalker extends ErrorTolerantWalker {

constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) {
super(sourceFile, options);
if (sourceFile.fileName.endsWith('tsx')) {

if (AstUtils.getLanguageVariant(sourceFile) === ts.LanguageVariant.JSX) {
this.allowGenericFunctionExpression = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/preferTypeCastRule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';

import { AstUtils } from './utils/AstUtils';
import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker';
import {ExtendedMetadata} from './utils/ExtendedMetadata';

Expand Down Expand Up @@ -34,7 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule {

class PreferTypeCastRuleWalker extends ErrorTolerantWalker {
protected visitSourceFile(node: ts.SourceFile): void {
if (/.*\.tsx/.test(node.fileName) === false) {
if (AstUtils.getLanguageVariant(node) === ts.LanguageVariant.Standard) {
super.visitSourceFile(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/AstUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as ts from 'typescript';
export module AstUtils {

export function getLanguageVariant(node: ts.SourceFile): ts.LanguageVariant {
if (/.*\.tsx/i.test(node.fileName)) {
if (node.fileName.endsWith('.tsx')) {
return ts.LanguageVariant.JSX;
} else {
return ts.LanguageVariant.Standard;
Expand Down