Skip to content

Commit

Permalink
Merge pull request #958 from spencerhakim/ts-nodes
Browse files Browse the repository at this point in the history
Support named TypeScript enums/interfaces/modules
  • Loading branch information
ljharb authored Jan 17, 2018
2 parents c9269be + 69084df commit 655c33d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"cross-env": "^4.0.0",
"eslint": "2.x - 4.x",
"eslint-import-resolver-node": "file:./resolvers/node",
"eslint-import-resolver-typescript": "^1.0.2",
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-module-utils": "file:./utils",
"eslint-plugin-import": "2.x",
Expand All @@ -71,8 +72,8 @@
"redux": "^3.0.4",
"rimraf": "^2.6.2",
"sinon": "^2.3.2",
"typescript": "^2.0.3",
"typescript-eslint-parser": "^8.0.0"
"typescript": "^2.6.2",
"typescript-eslint-parser": "^12.0.0"
},
"peerDependencies": {
"eslint": "2.x - 4.x"
Expand Down
1 change: 1 addition & 0 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ ExportMap.parse = function (path, content, context) {
case 'TSEnumDeclaration':
case 'TSInterfaceDeclaration':
case 'TSAbstractClassDeclaration':
case 'TSModuleDeclaration':
m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n))
break
case 'VariableDeclaration':
Expand Down
14 changes: 14 additions & 0 deletions tests/files/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ export abstract class Bar {
export function getFoo() : MyType {
return "foo"
}

export module MyModule {
export function ModuleFunction(){}
}

export namespace MyNamespace {
export function NamespaceFunction(){}

export module NSModule {
export function NSModuleFunction(){}
}
}

interface NotExported {}
90 changes: 90 additions & 0 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,70 @@ ruleTester.run('named', rule, {
'parser': 'babel-eslint',
}),

// TypeScript
test({
code: 'import { MyType } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: 'import { Foo } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: 'import { Bar } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: 'import { getFoo } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: 'import { MyEnum } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `
import { MyModule } from "./typescript"
MyModule.ModuleFunction()
`,
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),
test({
code: `
import { MyNamespace } from "./typescript"
MyNamespace.NSModule.NSModuleFunction()
`,
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}),

// jsnext
test({
code: '/*jsnext*/ import { createStore } from "redux"',
Expand Down Expand Up @@ -190,6 +254,32 @@ ruleTester.run('named', rule, {
}],
}),

// TypeScript
test({
code: 'import { MissingType } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
errors: [{
message: "MissingType not found in './typescript'",
type: 'Identifier',
}],
}),
test({
code: 'import { NotExported } from "./typescript"',
parser: 'typescript-eslint-parser',
settings: {
'import/parsers': { 'typescript-eslint-parser': ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
errors: [{
message: "NotExported not found in './typescript'",
type: 'Identifier',
}],
}),

// jsnext
test({
code: '/*jsnext*/ import { createSnorlax } from "redux"',
Expand Down

0 comments on commit 655c33d

Please sign in to comment.