From e64379abc2e53905082fa64b272a426df1a88e11 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sat, 11 Jul 2015 15:51:11 -0400 Subject: [PATCH] Fix #493: avoid checking class names for default exports - tweak variable declaration for "assert" to fix atom-typescript compilation - small indentation fix in tslint-cli.ts --- src/rules/classNameRule.ts | 11 +++++++---- src/tslint-cli.ts | 2 +- test/files/rules/classname.test.ts | 4 ++++ test/references.ts | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/rules/classNameRule.ts b/src/rules/classNameRule.ts index ca2d011495b..8cb87557f85 100644 --- a/src/rules/classNameRule.ts +++ b/src/rules/classNameRule.ts @@ -24,9 +24,12 @@ export class Rule extends Lint.Rules.AbstractRule { class NameWalker extends Lint.RuleWalker { public visitClassDeclaration(node: ts.ClassDeclaration) { - const className = node.name.getText(); - if (!this.isPascalCased(className)) { - this.addFailureAt(node.name.getStart(), node.name.getWidth()); + // classes declared as default exports will be unnamed + if (node.name != null) { + const className = node.name.getText(); + if (!this.isPascalCased(className)) { + this.addFailureAt(node.name.getStart(), node.name.getWidth()); + } } super.visitClassDeclaration(node); @@ -41,7 +44,7 @@ class NameWalker extends Lint.RuleWalker { super.visitInterfaceDeclaration(node); } - private isPascalCased(name: string): boolean { + private isPascalCased(name: string) { if (name.length <= 0) { return true; } diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 006bf293150..d4cc217ae5b 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -174,5 +174,5 @@ const processFile = (file: string) => { const files = argv._; for (const file of files) { - processFile(file); + processFile(file); } diff --git a/test/files/rules/classname.test.ts b/test/files/rules/classname.test.ts index 9fda87f4082..0a2eae5a0e6 100644 --- a/test/files/rules/classname.test.ts +++ b/test/files/rules/classname.test.ts @@ -9,3 +9,7 @@ class invalidClassName { class Another_Invalid_Class_Name { } + +export default class { + // should not fail +} diff --git a/test/references.ts b/test/references.ts index 91ba175a4b6..b620de263e4 100644 --- a/test/references.ts +++ b/test/references.ts @@ -14,5 +14,7 @@ * limitations under the License. */ -// attach chai.assert to the global object -global.assert = require("chai").assert; +/* tslint:disable:no-var-keyword */ +var assert: Chai.Assert = require("chai").assert; +global.assert = assert; +/* tslint:enable:no-var-keyword */