Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Fix #493: avoid checking class names for default exports
Browse files Browse the repository at this point in the history
- tweak variable declaration for "assert" to fix atom-typescript compilation
- small indentation fix in tslint-cli.ts
  • Loading branch information
adidahiya committed Jul 12, 2015
1 parent be728b3 commit e64379a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/rules/classNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ const processFile = (file: string) => {
const files = argv._;

for (const file of files) {
processFile(file);
processFile(file);
}
4 changes: 4 additions & 0 deletions test/files/rules/classname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class invalidClassName {
class Another_Invalid_Class_Name {

}

export default class {
// should not fail
}
6 changes: 4 additions & 2 deletions test/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit e64379a

Please sign in to comment.