Skip to content

Commit f8cc331

Browse files
Initial commit
0 parents  commit f8cc331

File tree

7 files changed

+87
-0
lines changed

7 files changed

+87
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# eslint-plugin-import-typescript-resolver
2+
3+
This plugin allows you to use `eslint-plugin-import` with `.ts` and `.tsx` files.
4+
5+
![](screenshot.png)
6+
7+
## Installation
8+
9+
```
10+
npm install --save-dev eslint-plugin-import-typescript-resolver
11+
```
12+
13+
Add the following to your eslint config:
14+
15+
```
16+
"settings": {
17+
"import/resolver": {
18+
"node": true,
19+
"eslint-plugin-import-typescript-resolver": true
20+
}
21+
}
22+
```

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const resolve = require('resolve');
2+
const path = require('path');
3+
4+
module.exports.interfaceVersion = 2;
5+
6+
function opts(file, config) {
7+
return Object.assign(
8+
{ extensions: ['.ts', '.tsx'] },
9+
config,
10+
// path.resolve will handle paths relative to CWD
11+
{ basedir: path.dirname(path.resolve(file)) },
12+
);
13+
}
14+
15+
module.exports.resolve = function(source, file, config) {
16+
if (resolve.isCore(source)) {
17+
return { found: true, path: null };
18+
}
19+
20+
try {
21+
return { found: true, path: resolve.sync(source, opts(file, config)) };
22+
} catch (err) {
23+
return { found: false };
24+
}
25+
};

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "eslint-plugin-import-typescript-resolver",
3+
"version": "1.0.0",
4+
"description": "TypeScript .ts .tsx module resolver for `eslint-plugin-import`.",
5+
"main": "index.js",
6+
"files": ["index.js"],
7+
"keywords": ["typescript", "eslint", "import", "resolver", "plugin"],
8+
"author": "Alex Gorbatchev <alex.gorbatchev@gmail.com>",
9+
"license": "ISC",
10+
"dependencies": {
11+
"resolve": "^1.4.0"
12+
}
13+
}

prettier.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
parser: 'typescript',
3+
singleQuote: true,
4+
trailingComma: 'all',
5+
};

screenshot.png

59.4 KB
Loading

0 commit comments

Comments
 (0)