Skip to content

Commit c3b5707

Browse files
Andrew Schmadelljharb
Andrew Schmadel
authored andcommitted
Test both typescript-eslint-parser and @typescript-eslint/parser
augments #1304
1 parent a68ab3b commit c3b5707

File tree

5 files changed

+124
-100
lines changed

5 files changed

+124
-100
lines changed

Diff for: README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ rules:
148148

149149
You may use the following shortcut or assemble your own config using the granular settings described below.
150150

151-
Make sure you have installed the [`@typescript-eslint/parser`] which is used in the following configuration. Unfortunately NPM does not allow to list optional peer dependencies.
151+
Make sure you have installed [`@typescript-eslint/parser`] which is used in the following configuration. Unfortunately NPM does not allow to list optional peer dependencies.
152152

153153
```yaml
154154
extends:
@@ -344,14 +344,16 @@ directly using webpack, for example:
344344
# .eslintrc.yml
345345
settings:
346346
import/parsers:
347-
typescript-eslint-parser: [ .ts, .tsx ]
347+
@typescript-eslint/parser: [ .ts, .tsx ]
348348
```
349349

350-
In this case, [`typescript-eslint-parser`](https://github.com/eslint/typescript-eslint-parser) must be installed and require-able from
351-
the running `eslint` module's location (i.e., install it as a peer of ESLint).
350+
In this case, [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
351+
must be installed and require-able from the running `eslint` module's location
352+
(i.e., install it as a peer of ESLint).
352353

353-
This is currently only tested with `typescript-eslint-parser` but should theoretically
354-
work with any moderately ESTree-compliant parser.
354+
This is currently only tested with `@typescript-eslint/parser` (and its predecessor,
355+
`typescript-eslint-parser`) but should theoretically work with any moderately
356+
ESTree-compliant parser.
355357

356358
It's difficult to say how well various plugin features will be supported, too,
357359
depending on how far down the rabbit hole goes. Submit an issue if you find strange

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"homepage": "https://github.com/benmosher/eslint-plugin-import",
4646
"devDependencies": {
47+
"@typescript-eslint/parser": "^1.5.0",
4748
"babel-eslint": "^8.2.6",
4849
"babel-plugin-istanbul": "^4.1.6",
4950
"babel-preset-es2015-argon": "latest",
@@ -69,7 +70,7 @@
6970
"rimraf": "^2.6.3",
7071
"sinon": "^2.4.1",
7172
"typescript": "^3.2.2",
72-
"typescript-eslint-parser": "^21.0.2"
73+
"typescript-eslint-parser": "^22.0.0"
7374
},
7475
"peerDependencies": {
7576
"eslint": "2.x - 5.x"

Diff for: tests/src/core/getExports.js

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ describe('ExportMap', function () {
315315
const configs = [
316316
// ['string form', { 'typescript-eslint-parser': '.ts' }],
317317
['array form', { 'typescript-eslint-parser': ['.ts', '.tsx'] }],
318+
['array form', { '@typescript-eslint/parser': ['.ts', '.tsx'] }],
318319
]
319320

320321
configs.forEach(([description, parserConfig]) => {

Diff for: tests/src/rules/named.js

+97-93
Original file line numberDiff line numberDiff line change
@@ -254,99 +254,103 @@ ruleTester.run('named (export *)', rule, {
254254
})
255255

256256

257-
context("Typescript", function () {
257+
context('Typescript', function () {
258258
// Typescript
259-
ruleTester.run("named", rule, {
260-
valid: [
261-
test({
262-
code: 'import { MyType } from "./typescript"',
263-
parser: 'typescript-eslint-parser',
264-
settings: {
265-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
266-
'import/resolver': { 'eslint-import-resolver-typescript': true },
267-
},
268-
}),
269-
test({
270-
code: 'import { Foo } from "./typescript"',
271-
parser: 'typescript-eslint-parser',
272-
settings: {
273-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
274-
'import/resolver': { 'eslint-import-resolver-typescript': true },
275-
},
276-
}),
277-
test({
278-
code: 'import { Bar } from "./typescript"',
279-
parser: 'typescript-eslint-parser',
280-
settings: {
281-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
282-
'import/resolver': { 'eslint-import-resolver-typescript': true },
283-
},
284-
}),
285-
test({
286-
code: 'import { getFoo } from "./typescript"',
287-
parser: 'typescript-eslint-parser',
288-
settings: {
289-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
290-
'import/resolver': { 'eslint-import-resolver-typescript': true },
291-
},
292-
}),
293-
test({
294-
code: 'import { MyEnum } from "./typescript"',
295-
parser: 'typescript-eslint-parser',
296-
settings: {
297-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
298-
'import/resolver': { 'eslint-import-resolver-typescript': true },
299-
},
300-
}),
301-
test({
302-
code: `
303-
import { MyModule } from "./typescript"
304-
MyModule.ModuleFunction()
305-
`,
306-
parser: 'typescript-eslint-parser',
307-
settings: {
308-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
309-
'import/resolver': { 'eslint-import-resolver-typescript': true },
310-
},
311-
}),
312-
test({
313-
code: `
314-
import { MyNamespace } from "./typescript"
315-
MyNamespace.NSModule.NSModuleFunction()
316-
`,
317-
parser: 'typescript-eslint-parser',
318-
settings: {
319-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
320-
'import/resolver': { 'eslint-import-resolver-typescript': true },
321-
},
322-
}),
323-
],
324-
325-
invalid: [
326-
test({
327-
code: 'import { MissingType } from "./typescript"',
328-
parser: 'typescript-eslint-parser',
329-
settings: {
330-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
331-
'import/resolver': { 'eslint-import-resolver-typescript': true },
332-
},
333-
errors: [{
334-
message: "MissingType not found in './typescript'",
335-
type: 'Identifier',
336-
}],
337-
}),
338-
test({
339-
code: 'import { NotExported } from "./typescript"',
340-
parser: 'typescript-eslint-parser',
341-
settings: {
342-
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
343-
'import/resolver': { 'eslint-import-resolver-typescript': true },
344-
},
345-
errors: [{
346-
message: "NotExported not found in './typescript'",
347-
type: 'Identifier',
348-
}],
349-
}),
350-
]
259+
const parsers = ['@typescript-eslint/parser', 'typescript-eslint-parser']
260+
261+
parsers.forEach((parser) => {
262+
ruleTester.run('named', rule, {
263+
valid: [
264+
test({
265+
code: 'import { MyType } from "./typescript"',
266+
parser: parser,
267+
settings: {
268+
'import/parsers': { [parser]: ['.ts'] },
269+
'import/resolver': { 'eslint-import-resolver-typescript': true },
270+
},
271+
}),
272+
test({
273+
code: 'import { Foo } from "./typescript"',
274+
parser: parser,
275+
settings: {
276+
'import/parsers': { [parser]: ['.ts'] },
277+
'import/resolver': { 'eslint-import-resolver-typescript': true },
278+
},
279+
}),
280+
test({
281+
code: 'import { Bar } from "./typescript"',
282+
parser: parser,
283+
settings: {
284+
'import/parsers': { [parser]: ['.ts'] },
285+
'import/resolver': { 'eslint-import-resolver-typescript': true },
286+
},
287+
}),
288+
test({
289+
code: 'import { getFoo } from "./typescript"',
290+
parser: parser,
291+
settings: {
292+
'import/parsers': { [parser]: ['.ts'] },
293+
'import/resolver': { 'eslint-import-resolver-typescript': true },
294+
},
295+
}),
296+
test({
297+
code: 'import { MyEnum } from "./typescript"',
298+
parser: parser,
299+
settings: {
300+
'import/parsers': { [parser]: ['.ts'] },
301+
'import/resolver': { 'eslint-import-resolver-typescript': true },
302+
},
303+
}),
304+
test({
305+
code: `
306+
import { MyModule } from "./typescript"
307+
MyModule.ModuleFunction()
308+
`,
309+
parser: parser,
310+
settings: {
311+
'import/parsers': { [parser]: ['.ts'] },
312+
'import/resolver': { 'eslint-import-resolver-typescript': true },
313+
},
314+
}),
315+
test({
316+
code: `
317+
import { MyNamespace } from "./typescript"
318+
MyNamespace.NSModule.NSModuleFunction()
319+
`,
320+
parser: parser,
321+
settings: {
322+
'import/parsers': { [parser]: ['.ts'] },
323+
'import/resolver': { 'eslint-import-resolver-typescript': true },
324+
},
325+
}),
326+
],
327+
328+
invalid: [
329+
test({
330+
code: 'import { MissingType } from "./typescript"',
331+
parser: parser,
332+
settings: {
333+
'import/parsers': { [parser]: ['.ts'] },
334+
'import/resolver': { 'eslint-import-resolver-typescript': true },
335+
},
336+
errors: [{
337+
message: "MissingType not found in './typescript'",
338+
type: 'Identifier',
339+
}],
340+
}),
341+
test({
342+
code: 'import { NotExported } from "./typescript"',
343+
parser: parser,
344+
settings: {
345+
'import/parsers': { [parser]: ['.ts'] },
346+
'import/resolver': { 'eslint-import-resolver-typescript': true },
347+
},
348+
errors: [{
349+
message: "NotExported not found in './typescript'",
350+
type: 'Identifier',
351+
}],
352+
}),
353+
],
354+
})
351355
})
352356
})

Diff for: tests/src/rules/order.js

+16
Original file line numberDiff line numberDiff line change
@@ -1276,5 +1276,21 @@ ruleTester.run('order', rule, {
12761276
message: '`fs` import should occur before import of `async`',
12771277
}],
12781278
}),
1279+
// fix incorrect order with @typescript-eslint/parser
1280+
test({
1281+
code: `
1282+
var async = require('async');
1283+
var fs = require('fs');
1284+
`,
1285+
output: `
1286+
var fs = require('fs');
1287+
var async = require('async');
1288+
`,
1289+
parser: '@typescript-eslint/parser',
1290+
errors: [{
1291+
ruleId: 'order',
1292+
message: '`fs` import should occur before import of `async`',
1293+
}],
1294+
}),
12791295
],
12801296
})

0 commit comments

Comments
 (0)