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

Commit

Permalink
Add tests for new ordered-imports groups option.
Browse files Browse the repository at this point in the history
  • Loading branch information
abierbaum committed Aug 25, 2018
1 parent e9f0bdd commit 7cc27f4
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/rules/ordered-imports/groups-complex/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

// comment outside of imports
import {afoo, foo} from 'foo';
import x = require('y');

import {app_b} from 'app/bar';
import {app_f} from 'app/foo';

// comment pkg/bar
import {a} from '@pkg/bar';
import {x} from '@pkg/foo';

import './baa';
import './baz'; // required

import {bar} from '../bar';
import {xbar} from '../xbar';

export class Test {}
27 changes: 27 additions & 0 deletions test/rules/ordered-imports/groups-complex/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node

// comment outside of imports
import {app_f} from 'app/foo';
import {x} from '@pkg/foo';
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: default, ^app, ^@pkg, current dir, parent_dir.]
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]

import {app_b} from 'app/bar';
// comment pkg/bar
import {a} from '@pkg/bar';
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]

import {xbar} from '../xbar';

import {bar} from '../bar';

import {foo, afoo} from 'foo';
~~~~~~~~~ [Named imports must be alphabetized.]

import './baz'; // required
import './baa';
~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]

import x = require('y');

export class Test {}
19 changes: 19 additions & 0 deletions test/rules/ordered-imports/groups-complex/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"rules": {
"ordered-imports": [
true,
{
"import-sources-order": "case-insensitive",
"named-imports-order": "case-insensitive",
"grouped-imports": true,
"groups": [
{ "match": "^app", "order": 20 },
{ "match": "^@pkg", "order": 30 },
{ "name": "parent_dir", "match": "^[.][.]", "order": 50 },
{ "name": "current dir", "match": "^[.]", "order": 40 },
{ "match": null, "order": 10 }
]
}
]
}
}
12 changes: 12 additions & 0 deletions test/rules/ordered-imports/groups-shared-order/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

import {y} from 'app_a/bar';
import {x} from 'app_a/foo';
import {f} from 'app_b/foo';

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

import {o} from 'other/bar';

export class Test {}
17 changes: 17 additions & 0 deletions test/rules/ordered-imports/groups-shared-order/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

import {f} from 'app_b/foo';
import {x} from 'app_a/foo';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]
import {y} from 'app_a/bar';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.]


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 {o} from 'other/bar';

export class Test {}
17 changes: 17 additions & 0 deletions test/rules/ordered-imports/groups-shared-order/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"rules": {
"ordered-imports": [
true,
{
"import-sources-order": "case-insensitive",
"named-imports-order": "case-insensitive",
"grouped-imports": true,
"groups": [
{ "match": "^app_b", "order": 10 },
{ "match": "^app_a", "order": 10 },
{ "match": "^@pkg", "order": 20 }
]
}
]
}
}
13 changes: 13 additions & 0 deletions test/rules/ordered-imports/groups-unmatched/test.ts.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node

import {app_b} from 'app/bar';
import {app_f} from 'app/foo';

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

import {foo} from 'foo';
import {xbar} from '../xbar';
import {b} from './ybar';

export class Test {}
17 changes: 17 additions & 0 deletions test/rules/ordered-imports/groups-unmatched/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

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 {a} from '@pkg/bar';

import {xbar} from '../xbar';

import {foo} from 'foo';
import {b} from './ybar';

export class Test {}
13 changes: 13 additions & 0 deletions test/rules/ordered-imports/groups-unmatched/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": {
"ordered-imports": [
true,
{
"import-sources-order": "case-insensitive",
"named-imports-order": "case-insensitive",
"grouped-imports": true,
"groups": [{ "match": "^app", "order": 20 }, { "match": "^@pkg", "order": 30 }]
}
]
}
}

0 comments on commit 7cc27f4

Please sign in to comment.