Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Fix bug in single type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltingMosaic committed Mar 17, 2017
1 parent 1a45c08 commit 3d57149
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/sortImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class RuleWalker extends Lint.RuleWalker {
sortValue: aliasMatch[1]
};
} else {
const singleMatch = /\bimport\s+({?([^,{}\*]+?)}?)\s*from\s+[\'"](?:[^"\']+)["\']/g.exec(nodeText);
const singleMatch = /\bimport\s+(?:{?([^,{}\*]+?)}?)\s*from\s+[\'"](?:[^"\']+)["\']/g.exec(nodeText);
const multipleMatch = /\bimport\s*{?\s*([^{}\'",]+?)\s*,(?:\s*.+\s*,\s*)*\s*.+\s*}?\s*from\s+[\'"](?:[^"\']+)["\']/g.exec(nodeText);
const noneMatch = /\bimport\s+[\'"]([^"\']+)["\']/g.exec(nodeText);
const allMatch = /\bimport\s+\*\s+as\s+(.+)\s+from\s+[\'"](?:[^"\']+)["\']/g.exec(nodeText);
Expand Down
19 changes: 19 additions & 0 deletions src/test/rules/sortImportsRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,23 @@ ruleTester.addTestGroup('alias', 'should pass alias tests', [
}
]);

ruleTester.addTestGroup('substring', 'imports that are a subset of other imports should come first', [
dedent`
import {Foo} from 'bar';
import {Fooz} from 'buz';`,
{
code: dedent`
import {Fooz} from 'buz';,
import {Foo} from 'bar';
`,
errors: expecting([[ALPHA_ORDER_ERROR('Foo', 'Fooz'), 2, 0, 24]])
},
dedent`
import 'foo';
import 'fooz'`,
dedent`
import {Foo, Gar} from 'a';
import {Fooz, Garz} from 'b';`
]);

ruleTester.runTests();

0 comments on commit 3d57149

Please sign in to comment.