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

Commit

Permalink
Small code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Nov 3, 2016
1 parent a5cdd8c commit 350e614
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export function getBindingElementVariableDeclaration(node: ts.BindingElement): t
}

/**
* Returns true if some ancestor of `node` satisfies `predicate`, including `node` itself.
* @returns true if some ancestor of `node` satisfies `predicate`, including `node` itself.
*/
export function someAncestor(node: ts.Node, predicate: (n: ts.Node)=>boolean): boolean {
export function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean): boolean {
return predicate(node) || (node.parent && someAncestor(node.parent, predicate));
}

Expand All @@ -135,7 +135,7 @@ export function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean
}

/**
* Returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path.
* @returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path.
*/
export function isNestedModuleDeclaration(decl: ts.ModuleDeclaration) {
// in a declaration expression like 'module a.b.c' - 'a' is the top level module declaration node and 'b' and 'c'
Expand Down
18 changes: 13 additions & 5 deletions src/rules/noNamespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ class NoNamespaceWalker extends Lint.RuleWalker {
public visitSourceFile(node: ts.SourceFile) {
// Ignore all .d.ts files by returning and not walking their ASTs.
// .d.ts declarations do not have the Ambient flag set, but are still declarations.
if (this.hasOption("allow-declarations") && node.fileName.match(/\.d\.ts$/)) { return; }
if (this.hasOption("allow-declarations") && node.fileName.match(/\.d\.ts$/)) {
return;
}
this.walkChildren(node);
}

public visitModuleDeclaration(decl: ts.ModuleDeclaration) {
super.visitModuleDeclaration(decl);

// declare module 'foo' {} is an external module, not a namespace.
if (decl.name.kind === ts.SyntaxKind.StringLiteral) { return; }
if (Lint.someAncestor(decl, (n) => Lint.isNodeFlagSet(n, ts.NodeFlags.Ambient)) &&
this.hasOption("allow-declarations")) {
if (decl.name.kind === ts.SyntaxKind.StringLiteral) {
return;
}
if (this.hasOption("allow-declarations")
&& Lint.someAncestor(decl, (n) => Lint.isNodeFlagSet(n, ts.NodeFlags.Ambient))) {
return;
}
if (Lint.isNestedModuleDeclaration(decl)) {
return;
}
if (Lint.isNestedModuleDeclaration(decl)) { return; }

this.addFailure(this.createFailure(decl.getStart(), decl.getWidth(), Rule.FAILURE_STRING));
}
}

0 comments on commit 350e614

Please sign in to comment.