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

Commit

Permalink
Add support for ES6 bare imports
Browse files Browse the repository at this point in the history
Fixes #451

This affects the following rules:

- `no-unused-variable`
- `no-use-before-declare`
- `whitespace` (it was already handled here, but I added a regression test)
  • Loading branch information
adidahiya committed Jun 26, 2015
1 parent 7e4806a commit 5398f44
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
const importClause = node.importClause;

// named imports & namespace imports handled by other walker methods
if (importClause.name != null) {
// importClause will be null for bare imports
if (importClause != null && importClause.name != null) {
const variableIdentifier = importClause.name;
this.validateReferencesForVariable(variableIdentifier.text, variableIdentifier.getStart());
}
Expand Down
13 changes: 6 additions & 7 deletions src/rules/noUseBeforeDeclareRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ class NoUseBeforeDeclareWalker extends Lint.ScopeAwareRuleWalker<VisitedVariable
}

public visitImportDeclaration(node: ts.ImportDeclaration) {
if (node.importClause != null) {
const importClause = node.importClause;
const importClause = node.importClause;

// named imports & namespace imports handled by other walker methods
if (importClause.name != null) {
const variableIdentifier = importClause.name;
this.validateUsageForVariable(variableIdentifier.text, variableIdentifier.getStart());
}
// named imports & namespace imports handled by other walker methods
// importClause will be null for bare imports
if (importClause != null && importClause.name != null) {
const variableIdentifier = importClause.name;
this.validateUsageForVariable(variableIdentifier.text, variableIdentifier.getStart());
}

super.visitImportDeclaration(node);
Expand Down
2 changes: 2 additions & 0 deletions test/files/rules/nounusedvariable-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ import defaultExport, { namedExport } from "libD"; // failure on 'defaultExport'
bar.someFunc();
baz();
namedExport();

import "jquery";
1 change: 1 addition & 0 deletions test/files/rules/nousebeforedeclare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ import { default as foo1 } from "lib";
import foo2 from "lib";
import _, { map, foldl } from "underscore";
import * as foo3 from "lib";
import "lib";
1 change: 1 addition & 0 deletions test/files/rules/whitespace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ export function each(obj, iterator, context) {
}

export {each as forEach};
import "libE";

0 comments on commit 5398f44

Please sign in to comment.