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

Commit

Permalink
Update import groups default to use \\. based relative path matching
Browse files Browse the repository at this point in the history
  • Loading branch information
abierbaum committed Aug 31, 2018
1 parent c92e44c commit ebc0fa3
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/rules/orderedImportsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Rule extends Lint.Rules.AbstractRule {
there is also a simplified form where you only pass a list of patterns and
the order is given by the position in the list
["^@pkga", "^[.][.]"]
["^@pkga", "^\\.\\."]
The first rule in the list to match a given import is the group that is used.
If no rule in matched then the import will be put in an \`unmatched\` group
Expand Down Expand Up @@ -238,8 +238,8 @@ function parseOptions(ruleArguments: any[]): Options {
const optionSet = (ruleArguments as JsonOptions[])[0];

const defaultGroups: JsonGroupOption[] = [
{ name: "parent directories", match: "^[.][.]", order: 20 },
{ name: "current directory", match: "^[.]", order: 30 },
{ name: "parent directories", match: "^\\.\\.", order: 20 },
{ name: "current directory", match: "^\\.", order: 30 },
{ name: "libraries", match: ".*", order: 10 }
];

Expand Down Expand Up @@ -432,7 +432,7 @@ class Walker extends Lint.AbstractWalker<Options> {
.sort((a, b) => a.order - b.order)
.map(g => g.name)
.join(", ");
const msg = `${Rule.IMPORT_SOURCES_NOT_GROUPED_PREFIX} ${groupsMsg}.`;
const msg = `${Rule.IMPORT_SOURCES_NOT_GROUPED_PREFIX} ${groupsMsg} .`;

this.addFailureAtNode(decl.node, msg, this.getGroupOrderReplacements());
};
Expand Down
2 changes: 1 addition & 1 deletion test/rules/ordered-imports/grouped-imports/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {bar} from '../bar';

import {foo, afoo} from 'foo';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: libraries, parent directories, current directory.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: libraries, parent directories, current directory .]
~~~~~~~~~ [Named imports must be alphabetized.]

import './baz'; // required
Expand Down
2 changes: 1 addition & 1 deletion test/rules/ordered-imports/groups-complex/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// comment outside of imports
import {app_f} from 'app/foo';
import {x} from '@pkg/foo';
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: extra, ^app, ^@pkg, current dir, parent_dir.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: extra, ^app, ^@pkg, current dir, parent_dir .]
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]

import {app_b} from 'app/bar';
Expand Down
4 changes: 2 additions & 2 deletions test/rules/ordered-imports/groups-complex/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"groups": [
{ "match": "^app", "order": 20 },
{ "match": "^@pkg", "order": 30 },
{ "name": "parent_dir", "match": "^[.][.]", "order": 50 },
{ "name": "current dir", "match": "^[.]", "order": 40 },
{ "name": "parent_dir", "match": "^\\.\\.", "order": 50 },
{ "name": "current dir", "match": "^\\.", "order": 40 },
{ "name": "extra", "match": ".*", "order": 5 }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {y} from 'app_a/bar';
import {a} from '@pkg/foo';

import {b} from '@pkg/bar';
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app_b, ^app_a, ^@pkg.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app_b, ^app_a, ^@pkg .]

import {o} from 'other/bar';

Expand Down
2 changes: 1 addition & 1 deletion test/rules/ordered-imports/groups-string-list/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { x } from "@pkg/foo";
import { app_f } from "app/foo";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app, ^@pkg, ^[.][.], ^[.].]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app, ^@pkg, ^\.\., ^\. .]

import { a } from "@pkg/bar";
import { app_b } from "app/bar";
Expand Down
2 changes: 1 addition & 1 deletion test/rules/ordered-imports/groups-string-list/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"import-sources-order": "case-insensitive",
"named-imports-order": "case-insensitive",
"grouped-imports": true,
"groups": ["^app", "^@pkg", "^[.][.]", "^[.]"]
"groups": ["^app", "^@pkg", "^\\.\\.", "^\\."]
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion test/rules/ordered-imports/groups-unmatched/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {app_f} from 'app/foo';
import {x} from '@pkg/foo';

import {app_b} from 'app/bar';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app, ^@pkg.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app, ^@pkg .]

import {a} from '@pkg/bar';

Expand Down

0 comments on commit ebc0fa3

Please sign in to comment.