Skip to content

Commit f22f92e

Browse files
committed
Initial commit
0 parents  commit f22f92e

23 files changed

+3707
-0
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
default:
9+
strategy:
10+
matrix:
11+
node:
12+
- 16
13+
- 18
14+
- 20
15+
os:
16+
# - macOS-latest
17+
# - windows-latest # I don't have a Windows machine to debug
18+
- ubuntu-latest
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup target Node.js to enable Corepack
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node }}
27+
28+
- name: Enable Corepack
29+
run: corepack enable
30+
31+
- name: Setup Node.js ${{ matrix.node }} with cache
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: ${{ matrix.node }}
35+
cache: pnpm
36+
37+
- name: Install Dependencies
38+
run: pnpm install
39+
40+
- name: Lint
41+
run: pnpm lint
42+
43+
- name: Type checking
44+
run: pnpm type-check

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@v4
15+
with:
16+
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
17+
fetch-depth: 0
18+
19+
- name: Enable Corepack
20+
run: corepack enable
21+
22+
- name: Setup Node.js LTS
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: lts/*
26+
cache: pnpm
27+
28+
- name: Install Dependencies
29+
run: pnpm install
30+
31+
- name: Build
32+
run: pnpm build
33+
34+
- name: Create Release Pull Request or Publish to npm
35+
id: changesets
36+
uses: changesets/action@v1
37+
with:
38+
publish: yarn release
39+
commit: 'chore: release @helljs/eslint-import-resolver-x'
40+
title: 'chore: release e@helljs/eslint-import-resolver-x'
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.*cache
2+
.type-coverage
3+
dist
4+
node_modules
5+
*.log

.nvmrc

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

.prettierignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Ignore build output directories
2+
dist
3+
out
4+
build
5+
6+
# Ignore node modules
7+
node_modules
8+
9+
# Ignore specific configuration files
10+
*.config.js
11+
12+
# Ignore environment variables files
13+
.env
14+
.env.*
15+
16+
# Ignore lock files
17+
yarn.lock
18+
package-lock.json
19+
pnpm-lock.yaml
20+
21+
# Ignore logs
22+
*.log
23+
24+
# Ignore compiled files
25+
*.min.js
26+
*.min.css
27+
28+
# Ignore specific file types
29+
*.png
30+
*.jpg
31+
*.jpeg
32+
*.gif
33+
*.svg
34+
35+
# Ignore other generated files
36+
coverage/

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
trailingComma: 'es5',
3+
printWidth: 120,
4+
tabWidth: 2,
5+
semi: false,
6+
bracketSpacing: true,
7+
jsxBracketSameLine: true,
8+
arrowParens: 'always',
9+
singleQuote: true,
10+
}

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2024, Roman Olin <[email protected]>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# eslint-import-resolver-x
2+
3+
This resolver adds [`TypeScript`][] or [`JavaScript`][] import support to [`eslint-plugin-import`][] with `tsconfig.json` or `jsconfig.json` aliases (`compilerOptions.paths`)
4+
5+
This is fork of [`eslint-import-resolver-typescript`][] but much faster **(~30-40%)**
6+
7+
For example we can use `strace` package for count of [fstat](`https://nodejs.org/api/fs.html#fsfstatsyncfd-options`) call when linting you codebase
8+
9+
Example you codebase has multiple packages with 100k LOC and more
10+
11+
| syscall | eslint-import-resolver-x | eslint-import-resolver-typescript |
12+
| ---------- | ------------------------ | --------------------------------- |
13+
| access | 85 027 |
14+
| chdir | 1 |
15+
| execve | 78 |
16+
| faccessat2 | 1 |
17+
| getcwd | 3 |
18+
| mkdir | 2 |
19+
| newfstatat | 31 761 |
20+
| openat | 86 287 |
21+
| readlink | 1 183 633 |
22+
| statfs | 2 |
23+
| statx | 1 081 306 |
24+
| unlink | 3 |
25+
26+
We are interested in how many accesses to the file system occurred during the linting process. We can pay attention to `statx` syscall.
27+
28+
`eslint-import-resolver-x` makes calls `statx` 100 times less.
29+
30+
**If you notice an increase in linting performance in your CI on large code bases, write your feedback [here](https://github.com/helljs/eslint-import-resolver-x/discussions/1)**
31+
32+
## Description
33+
34+
You can:
35+
36+
- `import`/`require` files with extension any extenstions of `js` or `ts`
37+
- Use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in `tsconfig.json` or `jsconfig.json`
38+
- Multiple tsconfigs or jsconfigs support
39+
- `imports/exports` fields support in `package.json`
40+
41+
## Installation
42+
43+
```sh
44+
# npm
45+
npm i -D eslint-plugin-import @helljs/eslint-import-resolver-x
46+
47+
# pnpm
48+
pnpm i -D eslint-plugin-import @helljs/eslint-import-resolver-x
49+
50+
# yarn
51+
yarn add -D eslint-plugin-import @helljs/eslint-import-resolver-x
52+
```
53+
54+
## Configuration
55+
56+
Add the following to your `.eslintrc` config:
57+
58+
### TypeScript
59+
60+
```jsonc
61+
{
62+
"plugins": ["import"],
63+
"rules": {
64+
// turn on errors for missing imports
65+
"import/no-unresolved": "error",
66+
},
67+
"settings": {
68+
"import/parsers": {
69+
"@typescript-eslint/parser": [".ts", ".tsx"],
70+
},
71+
"import/resolver": {
72+
"x": {
73+
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
74+
75+
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
76+
77+
// use <root>/path/to/folder/tsconfig.json
78+
"project": "path/to/folder",
79+
80+
// Multiple tsconfigs (Useful for monorepos)
81+
82+
// use a glob pattern
83+
"project": "packages/*/tsconfig.json",
84+
85+
// use an array
86+
"project": ["packages/module-a/tsconfig.json", "packages/module-b/tsconfig.json"],
87+
88+
// use an array of glob patterns
89+
"project": ["packages/*/tsconfig.json", "other-packages/*/tsconfig.json"],
90+
},
91+
},
92+
},
93+
}
94+
```
95+
96+
### JavaScript
97+
98+
```jsonc
99+
{
100+
"plugins": ["import"],
101+
"rules": {
102+
// turn on errors for missing imports
103+
"import/no-unresolved": "error",
104+
},
105+
"settings": {
106+
"import/parsers": {
107+
"@babel/eslint-parser": [".js", ".mjs"],
108+
},
109+
"import/resolver": {
110+
"x": {
111+
// use <root>/path/to/folder/jsconfig.json
112+
"project": "path/to/folder",
113+
114+
// Multiple jsconfigs (Useful for monorepos)
115+
116+
// use a glob pattern
117+
"project": "packages/*/jsconfig.json",
118+
119+
// use an array
120+
"project": ["packages/module-a/jsconfig.json", "packages/module-b/jsconfig.json"],
121+
122+
// use an array of glob patterns
123+
"project": ["packages/*/jsconfig.json", "other-packages/*/jsconfig.json"],
124+
},
125+
},
126+
},
127+
}
128+
```
129+
130+
## Options from [`enhanced-resolve`][]
131+
132+
#### `conditionNames` - [See default](src/default.ts)
133+
134+
#### `extensions` - [See default](src/default.ts)
135+
136+
#### `extensionAlias` - [See default](src/default.ts)
137+
138+
### `mainFields` - [See default](src/default.ts)
139+
140+
### Other options
141+
142+
You can pass through other options of [`enhanced-resolve`][] directly

eslint.config.mjs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// @ts-check
2+
import eslint from '@eslint/js'
3+
import { flatConfigs } from 'eslint-plugin-import'
4+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
5+
import globals from 'globals'
6+
// eslint-disable-next-line import/no-unresolved
7+
import tseslint from 'typescript-eslint'
8+
9+
export default [
10+
{
11+
ignores: ['docs', 'build', 'out', 'index.d.ts', '__test__', 'dist', '**/node_modules/**', 'node_modules'],
12+
},
13+
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
14+
eslint.configs.recommended,
15+
...tseslint.configs.recommended,
16+
flatConfigs.recommended,
17+
eslintPluginPrettierRecommended,
18+
{
19+
settings: {
20+
'import/parsers': {
21+
'@typescript-eslint/parser': ['.ts', '.tsx'],
22+
},
23+
'import/resolver': {
24+
node: {
25+
extensions: ['.ts', '.js', '.d.ts', '.mjs', '.cjs'],
26+
},
27+
},
28+
},
29+
},
30+
{
31+
rules: {
32+
'@typescript-eslint/consistent-type-imports': 'error',
33+
'import/no-deprecated': 2,
34+
'import/no-unresolved': 2,
35+
'import/prefer-default-export': 'off',
36+
'import/no-extraneous-dependencies': 'off',
37+
'import/no-useless-path-segments': 1,
38+
'import/order': [
39+
'error',
40+
{
41+
alphabetize: {
42+
caseInsensitive: false,
43+
order: 'asc',
44+
},
45+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index'], 'type'],
46+
'newlines-between': 'always',
47+
distinctGroup: false,
48+
pathGroups: [
49+
{
50+
group: 'external',
51+
pattern: 'node_modules',
52+
position: 'before',
53+
},
54+
{
55+
group: 'external',
56+
pattern: '@foxford/**',
57+
position: 'after',
58+
},
59+
{
60+
group: 'internal',
61+
pattern: '@@foxford/*',
62+
position: 'before',
63+
},
64+
{
65+
group: 'internal',
66+
pattern: 'services/**',
67+
position: 'before',
68+
},
69+
{
70+
group: 'internal',
71+
pattern: 'modules/**',
72+
position: 'before',
73+
},
74+
],
75+
pathGroupsExcludedImportTypes: ['type'],
76+
},
77+
],
78+
},
79+
},
80+
]

0 commit comments

Comments
 (0)