Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use eslint-import-resolver-typescript instead #59

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shareable ESLint configs cannot have dependencies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to understand, or should I list it in peer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, but I'm also using this for a long time without any issue.

https://github.com/1stG/configs/blob/master/packages/eslint-config/package.json#L30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I have a shared ESLint config with dependencies and it's only plugins that are a problem, everything else works as expected.

    "@typescript-eslint/eslint-plugin": "^4.28.3",
    "@typescript-eslint/parser": "^4.28.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.18.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-airbnb-typescript": "^12.3.1",
    "eslint-config-prettier": "^6.12.0",
    "eslint-import-resolver-alias": "^1.1.2",
    "eslint-import-resolver-typescript": "^2.3.0",
    "eslint-import-resolver-webpack": "^0.13.2",
    "eslint-plugin-babel": "^5.3.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-react": "^7.20.3",
    "eslint-plugin-react-hooks": "^4.0.8"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer to wait until we move to flat ESLint config, which should have no problem with any kind of dependency.

},
"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 => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous test case is absolutely wrong.

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));
});