Skip to content

Commit

Permalink
feat: use eslint-import-resolver-typescript instead
Browse files Browse the repository at this point in the history
close xojs#58
  • Loading branch information
JounQin committed Jun 25, 2022
1 parent 7decafc commit b997620
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ module.exports = {
],
settings: {
'import/resolver': {
node: {
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx'
]
typescript: {
alwaysTryTypes: true,
}
},
'import/parsers': {
Expand Down Expand Up @@ -503,14 +498,14 @@ module.exports = {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',

// Disabled for now. When using try/catch, the error is by default `any` and if you pass the error anywhere, it will trigger this rule. This is a very common occurence.
// Disabled for now. When using try/catch, the error is by default `any` and if you pass the error anywhere, it will trigger this rule. This is a very common occurrence.
// TODO: Enable this rule when TypeScript has more strongly typed errors, probably 2023 at the earliest.
// '@typescript-eslint/no-unsafe-argument': 'error',

'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',

// Disabled until TypeScrpt supports the `node:` protocol.
// Disabled until TypeScirpt supports the `node:` protocol.
// '@typescript-eslint/no-unsafe-member-access': 'error',

'@typescript-eslint/no-unsafe-return': 'error',
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
"hint",
"simple"
],
"dependencies": {
"eslint-import-resolver-typescript": "^2.7.1"
},
"devDependencies": {
"@types/unist": "^2.0.6",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"ava": "^2.4.0",
Expand All @@ -53,6 +57,7 @@
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">=5.22.0",
"eslint": ">=8.0.0",
"eslint-plugin-import": ">=2.0.0",
"typescript": ">=4.4"
}
}
8 changes: 5 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path'
import test from 'ava';
import {ESLint} from 'eslint';
import config from '../index.js';
Expand All @@ -10,12 +11,13 @@ async function runEslint(string, config) {
overrideConfig: config,
});

const [firstResult] = await eslint.lintText(string, {filePath: '_x.ts'});
const [firstResult] = await eslint.lintText(string, {filePath: path.resolve('test', '_x.ts')});

return firstResult.messages;
}

test.failing('main', async t => {
const errors = await runEslint('const foo: number = 5;', config);
test('main', async t => {
const errors = await runEslint('import { Node } from "unist";\nconst foo: number = 5;', config);
t.true(hasRule(errors, '@typescript-eslint/no-inferrable-types'), JSON.stringify(errors));
t.false(hasRule(errors, 'import/no-unresolved'), JSON.stringify(errors));
});

0 comments on commit b997620

Please sign in to comment.