Skip to content

Commit

Permalink
[import-name] Fix microsoft#378
Browse files Browse the repository at this point in the history
- ignore dotted paths `.`, `..`
  • Loading branch information
Igorbek committed Oct 26, 2018
1 parent 30aca14 commit b5e70f6
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 b5e70f6

Please sign in to comment.