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

Commit

Permalink
Update behaviour for external modules
Browse files Browse the repository at this point in the history
  • Loading branch information
berickson1 committed Sep 6, 2017
1 parent 23a59e8 commit 8d3b03a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/orderedImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const TRANSFORMS = new Map<string, Transform>([
["lowercase-last", (x) => x],
["full-path", (x) => x],
["module-name", (x) => {
if (!(ts as any as {isExternalModuleNameRelative(m: string): boolean}).isExternalModuleNameRelative(x)) {
return x;
}

const splitIndex = x.lastIndexOf("/");
if (splitIndex === -1) {
return x;
Expand Down Expand Up @@ -147,8 +151,8 @@ function parseOptions(ruleArguments: any[]): Options {
} = optionSet === undefined ? {} : optionSet;
return {
importSourcesOrderTransform: TRANSFORMS.get(sources)!,
namedImportsOrderTransform: TRANSFORMS.get(named)!,
moduleSourcePath: TRANSFORMS.get(path)!,
namedImportsOrderTransform: TRANSFORMS.get(named)!,
};
}

Expand Down
5 changes: 5 additions & 0 deletions test/rules/ordered-imports/module-source-path/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ import c = require('./baz/c');
import a from '../../foo/a';
import b from './bar/b';
import c = require('./baz/c');

// contains scoped import
import a from 'foo/a';
import b = require('foo/b');
import c from 'foo/c';
6 changes: 6 additions & 0 deletions test/rules/ordered-imports/module-source-path/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ import c = require('./baz/c');
import a from '../../foo/a';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]
import b from './bar/b';

// contains scoped import
import b = require('foo/b');
import a from 'foo/a';
~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]
import c from 'foo/c';

0 comments on commit 8d3b03a

Please sign in to comment.