Skip to content

Commit 11ebfbd

Browse files
authored
refactor: migrate deprecated doctrine to comment-parser (#314)
1 parent 4b7e2f4 commit 11ebfbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+548
-510
lines changed

.changeset/kind-bananas-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": minor
3+
---
4+
5+
refactor: migrate deprecated `doctrine` to `comment-parser`

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ lib
2626
!.yarn/plugins
2727
!.yarn/releases
2828
!.yarn/sdks
29+
30+
# Local test
31+
test.local.*

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
export type ResolvedResult = ResultNotFound | ResultFound
318318
```
319319
320-
You will be able to import `NewResolver` from `eslint-plugin-import-x/types`.
320+
You will be able to import `NewResolver` from `eslint-plugin-import-x`.
321321
322322
The most notable change is that `eslint-plugin-import-x` no longer passes the third argument (`options`) to the `resolve` function.
323323

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export default config(
149149
'.*.js',
150150
'**/*.d.ts',
151151
'**/.eslintrc.js',
152+
'test.local.*',
152153
'eslint.config.js',
153154
'jest.config.ts',
154155
],

index.d.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import eslintPluginImportX from './lib/index.js'
1+
import * as eslintPluginImportX from './lib/index.js'
22

33
export = eslintPluginImportX

package.json

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,22 @@
7171
"eslint": "^8.57.0 || ^9.0.0"
7272
},
7373
"dependencies": {
74-
"@pkgr/core": "^0.2.4",
75-
"@types/doctrine": "^0.0.9",
76-
"@typescript-eslint/utils": "^8.30.1",
74+
"@typescript-eslint/utils": "^8.31.0",
75+
"comment-parser": "^1.4.1",
7776
"debug": "^4.4.0",
78-
"doctrine": "^3.0.0",
7977
"eslint-import-resolver-node": "^0.3.9",
8078
"get-tsconfig": "^4.10.0",
8179
"is-glob": "^4.0.3",
8280
"minimatch": "^9.0.3 || ^10.0.1",
8381
"semver": "^7.7.1",
8482
"stable-hash": "^0.0.5",
8583
"tslib": "^2.8.1",
86-
"unrs-resolver": "^1.6.0"
84+
"unrs-resolver": "^1.7.0"
8785
},
8886
"devDependencies": {
8987
"@1stg/commitlint-config": "^5.0.6",
9088
"@1stg/lint-staged": "^4.0.9",
91-
"@1stg/prettier-config": "^5.1.3",
89+
"@1stg/prettier-config": "^5.1.4",
9290
"@1stg/remark-preset": "^3.1.1",
9391
"@1stg/simple-git-hooks": "^2.0.1",
9492
"@1stg/tsconfig": "^3.0.3",
@@ -106,10 +104,10 @@
106104
"@changesets/cli": "^2.29.2",
107105
"@commitlint/cli": "^19.8.0",
108106
"@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped",
109-
"@eslint/js": "^9.25.0",
107+
"@eslint/js": "^9.25.1",
110108
"@pkgr/rollup": "^6.0.3",
111109
"@swc-node/jest": "^1.8.13",
112-
"@swc/core": "^1.11.21",
110+
"@swc/core": "^1.11.22",
113111
"@swc/helpers": "^0.5.17",
114112
"@test-scope/some-module": "link:./test/fixtures/symlinked-module",
115113
"@total-typescript/ts-reset": "^0.6.1",
@@ -120,28 +118,28 @@
120118
"@types/jest": "^29.5.14",
121119
"@types/json-schema": "^7.0.15",
122120
"@types/klaw-sync": "^6.0.5",
123-
"@types/node": "^22.14.1",
121+
"@types/node": "^22.15.2",
124122
"@types/pnpapi": "^0.0.5",
125-
"@typescript-eslint/eslint-plugin": "^8.30.1",
126-
"@typescript-eslint/parser": "^8.30.1",
127-
"@typescript-eslint/rule-tester": "^8.30.1",
123+
"@typescript-eslint/eslint-plugin": "^8.31.0",
124+
"@typescript-eslint/parser": "^8.31.0",
125+
"@typescript-eslint/rule-tester": "^8.31.0",
128126
"@unts/patch-package": "^8.1.1",
129-
"clean-pkg-json": "^1.2.1",
130-
"eslint": "^9.25.0",
127+
"clean-pkg-json": "^1.3.0",
128+
"eslint": "^9.25.1",
131129
"eslint-config-prettier": "^10.1.2",
132130
"eslint-doc-generator": "^2.1.2",
133-
"eslint-import-resolver-typescript": "^4.3.3",
131+
"eslint-import-resolver-typescript": "^4.3.4",
134132
"eslint-import-resolver-webpack": "^0.13.10",
135133
"eslint-import-test-order-redirect": "link:./test/fixtures/order-redirect",
136134
"eslint-plugin-eslint-plugin": "^6.4.0",
137135
"eslint-plugin-import-x": "link:.",
138136
"eslint-plugin-jest": "^28.11.0",
139137
"eslint-plugin-json": "^4.0.1",
140-
"eslint-plugin-mdx": "^3.4.0",
138+
"eslint-plugin-mdx": "^3.4.1",
141139
"eslint-plugin-n": "^17.17.0",
142140
"eslint-plugin-prettier": "^5.2.6",
143141
"eslint-plugin-unicorn": "^58.0.0",
144-
"eslint-plugin-yml": "^1.17.0",
142+
"eslint-plugin-yml": "^1.18.0",
145143
"eslint8.56": "npm:eslint@~8.56.0",
146144
"eslint9": "npm:eslint@^9.24.0",
147145
"globals": "^16.0.0",
@@ -150,16 +148,16 @@
150148
"klaw-sync": "^7.0.0",
151149
"nano-staged": "^0.8.0",
152150
"npm-run-all2": "^7.0.2",
153-
"path-serializer": "^0.3.4",
151+
"path-serializer": "^0.4.0",
154152
"prettier": "^3.5.3",
155153
"redux": "^5.0.1",
156154
"rimraf": "^6.0.1",
157-
"simple-git-hooks": "^2.12.1",
155+
"simple-git-hooks": "^2.13.0",
158156
"tinyexec": "^1.0.1",
159157
"ts-node": "^10.9.2",
160158
"type-fest": "^4.40.0",
161159
"typescript": "^5.8.3",
162-
"typescript-eslint": "^8.30.1",
160+
"typescript-eslint": "^8.31.0",
163161
"yarn-berry-deduplicate": "^6.1.3",
164162
"zod": "^3.24.3"
165163
},

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import warnings from './config/warnings.js'
1919
// rules
2020
import { meta } from './meta.js'
2121
import { createNodeResolver } from './node-resolver.js'
22+
import { cjsRequire } from './require.js'
2223
import consistentTypeSpecifierStyle from './rules/consistent-type-specifier-style.js'
2324
import default_ from './rules/default.js'
2425
import dynamicImportChunkname from './rules/dynamic-import-chunkname.js'
@@ -183,6 +184,7 @@ export default {
183184
configs,
184185
flatConfigs,
185186
rules,
187+
cjsRequire,
186188
importXResolverCompat,
187189
createNodeResolver,
188190
}
@@ -192,6 +194,7 @@ export {
192194
configs,
193195
flatConfigs,
194196
rules,
197+
cjsRequire,
195198
importXResolverCompat,
196199
createNodeResolver,
197200
}

src/meta.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import { createRequire } from 'node:module'
2-
3-
import { EVAL_FILENAMES } from '@pkgr/core'
4-
import type { CjsRequire } from '@pkgr/core'
5-
6-
const cjsRequire: CjsRequire =
7-
typeof require === 'undefined' ||
8-
// workaround for #296
9-
EVAL_FILENAMES.has(__filename)
10-
? createRequire(import.meta.url)
11-
: /* istanbul ignore next */ require
1+
import { cjsRequire } from './require.js'
122

133
export const { name, version } = cjsRequire<{ name: string; version: string }>(
144
'../package.json',

src/require.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createRequire } from 'node:module'
2+
3+
import type { CjsRequire } from './types.js'
4+
5+
const importMetaUrl = import.meta.url
6+
7+
export const cjsRequire: CjsRequire = importMetaUrl
8+
? createRequire(importMetaUrl)
9+
: /* istanbul ignore next */ require

src/rules/no-deprecated.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TSESTree } from '@typescript-eslint/utils'
2-
import type { Tag } from 'doctrine'
2+
import type { Spec } from 'comment-parser'
33

44
import type { ModuleNamespace } from '../utils/index.js'
55
import {
@@ -9,7 +9,7 @@ import {
99
getValue,
1010
} from '../utils/index.js'
1111

12-
function message(deprecation: Tag) {
12+
function message(deprecation: Spec) {
1313
if (deprecation.description) {
1414
return {
1515
messageId: 'deprecatedDesc',
@@ -25,7 +25,7 @@ function getDeprecation(metadata?: ModuleNamespace | null) {
2525
return
2626
}
2727

28-
return metadata.doc.tags.find(t => t.title === 'deprecated')
28+
return metadata.doc.tags.find(t => t.tag === 'deprecated')
2929
}
3030

3131
export default createRule({
@@ -45,7 +45,7 @@ export default createRule({
4545
},
4646
defaultOptions: [],
4747
create(context) {
48-
const deprecated = new Map<string, Tag>()
48+
const deprecated = new Map<string, Spec>()
4949
const namespaces = new Map<string, ExportMap | null>()
5050

5151
return {
@@ -66,7 +66,7 @@ export default createRule({
6666
}
6767

6868
const moduleDeprecation = imports.doc?.tags.find(
69-
t => t.title === 'deprecated',
69+
t => t.tag === 'deprecated',
7070
)
7171
if (moduleDeprecation) {
7272
context.report({

0 commit comments

Comments
 (0)