Skip to content

Commit b5e70f6

Browse files
committed
[import-name] Fix microsoft#378
- ignore dotted paths `.`, `..`
1 parent 30aca14 commit b5e70f6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/importNameRule.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class ImportNameRuleWalker extends Lint.RuleWalker {
151151

152152
private validateImport(node: ts.ImportEqualsDeclaration | ts.ImportDeclaration, importedName: string, moduleName: string): void {
153153
let expectedImportedName = moduleName.replace(/.*\//, ''); // chop off the path
154+
if (expectedImportedName === '' || expectedImportedName === '.' || expectedImportedName === '..') {
155+
return;
156+
}
154157
expectedImportedName = this.makeCamelCase(expectedImportedName);
155158
if (this.isImportNameValid(importedName, expectedImportedName, moduleName, node) === false) {
156159
const message: string = `Misnamed import. Import should be named '${expectedImportedName}' but found '${importedName}'`;

src/tests/ImportNameRuleTests.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,26 @@ describe('importNameRule', () : void => {
220220
}
221221
]);
222222
});
223+
224+
it('should pass on index path modules', () => {
225+
const script = `
226+
import AnyName = require('.');
227+
import AnyName = require('..');
228+
import AnyName = require('./');
229+
import AnyName = require('../');
230+
`;
231+
232+
TestHelper.assertViolations(ruleName, script, [ ]);
233+
});
234+
235+
it('should pass on index path ES6 modules', () => {
236+
const script = `
237+
import AnyName from '.';
238+
import AnyName from '..';
239+
import AnyName from './';
240+
import AnyName from '../';
241+
`;
242+
243+
TestHelper.assertViolations(ruleName, script, [ ]);
244+
});
223245
});

0 commit comments

Comments
 (0)