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

Commit

Permalink
[import-name] Fix #378 (#591)
Browse files Browse the repository at this point in the history
- ignore dotted paths `.`, `..`
  • Loading branch information
Igorbek authored and Josh Goldberg committed Oct 26, 2018
1 parent 30aca14 commit 603820f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/importNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class ImportNameRuleWalker extends Lint.RuleWalker {

private validateImport(node: ts.ImportEqualsDeclaration | ts.ImportDeclaration, importedName: string, moduleName: string): void {
let expectedImportedName = moduleName.replace(/.*\//, ''); // chop off the path
if (expectedImportedName === '' || expectedImportedName === '.' || expectedImportedName === '..') {
return;
}
expectedImportedName = this.makeCamelCase(expectedImportedName);
if (this.isImportNameValid(importedName, expectedImportedName, moduleName, node) === false) {
const message: string = `Misnamed import. Import should be named '${expectedImportedName}' but found '${importedName}'`;
Expand Down
22 changes: 22 additions & 0 deletions src/tests/ImportNameRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,26 @@ describe('importNameRule', () : void => {
}
]);
});

it('should pass on index path modules', () => {
const script = `
import AnyName = require('.');
import AnyName = require('..');
import AnyName = require('./');
import AnyName = require('../');
`;

TestHelper.assertViolations(ruleName, script, [ ]);
});

it('should pass on index path ES6 modules', () => {
const script = `
import AnyName from '.';
import AnyName from '..';
import AnyName from './';
import AnyName from '../';
`;

TestHelper.assertViolations(ruleName, script, [ ]);
});
});

0 comments on commit 603820f

Please sign in to comment.