Skip to content

Commit eeb4127

Browse files
committed
feat(no-sync)!: move ts-declaration-location to peerDependencies
- Set `ts-declaration-location` as an optional peer dependency for the `n/no-sync` rule. - Move `ts-declaration-location` to `devDependencies` for development and testing. - Update the `n/no-sync` documentation to refer the updated peer dependency requirement. - Update `n/no-sync` rule to conditionally require `ts-declaration-location` only when advanced ignores are used.
1 parent 42464ab commit eeb4127

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

docs/rules/no-sync.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ Examples of **correct** code for this rule with the `{ ignores: ['readFileSync']
7979
fs.readFileSync(somePath);
8080
```
8181

82+
> [!WARNING]
83+
> Advanced `ignores` options (object specifiers) require TypeScript and the [`ts-declaration-location`](https://www.npmjs.com/package/ts-declaration-location) package. This package is an **optional peer dependency** for the `n/no-sync` rule. If you want to use advanced TypeScript-based ignores, please install it in your project:
84+
>
85+
> ```sh
86+
> npm install --save-dev ts-declaration-location
87+
> ```
88+
8289
##### Advanced (TypeScript only)
8390
8491
You can provide a list of specifiers to ignore. Specifiers are typed as follows:
@@ -102,6 +109,9 @@ type Specifier =
102109
}
103110
```
104111
112+
> [!NOTE]
113+
> To use advanced TypeScript-based ignores, you must have `ts-declaration-location` installed as a dev dependency in your project.
114+
105115
###### From a file
106116

107117
Examples of **correct** code for this rule with the ignore file specifier:

lib/rules/no-sync.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
*/
55
"use strict"
66

7-
let typeMatchesSpecifier =
8-
/** @type {import('ts-declaration-location').default | undefined} */
9-
(undefined)
10-
11-
try {
12-
typeMatchesSpecifier =
13-
/** @type {import('ts-declaration-location').default} */ (
14-
/** @type {unknown} */ (require("ts-declaration-location"))
15-
)
16-
17-
// eslint-disable-next-line no-empty -- Deliberately left empty.
18-
} catch {}
197
const getTypeOfNode = require("../util/get-type-of-node")
208
const getParserServices = require("../util/get-parser-services")
219
const getFullTypeName = require("../util/get-full-type-name")
@@ -124,6 +112,29 @@ module.exports = {
124112
const selector = options.allowAtRootLevel
125113
? selectors.map(selector => `:function ${selector}`)
126114
: selectors
115+
116+
// Only require `ts-declaration-location` if needed.
117+
let typeMatchesSpecifier =
118+
/** @type {import('ts-declaration-location').default | undefined} */
119+
(undefined)
120+
121+
const hasAdvancedIgnores = ignores.some(
122+
ignore => typeof ignore !== "string"
123+
)
124+
125+
if (hasAdvancedIgnores) {
126+
try {
127+
typeMatchesSpecifier =
128+
/** @type {import('ts-declaration-location').default} */ (
129+
/** @type {unknown} */ (
130+
require("ts-declaration-location")
131+
)
132+
)
133+
} catch {
134+
// Will throw below if needed.
135+
}
136+
}
137+
127138
return {
128139
/**
129140
* @param {import('estree').Identifier & {parent: import('estree').Node}} node

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
"types/index.d.ts"
1515
],
1616
"peerDependencies": {
17-
"eslint": ">=8.23.0"
17+
"eslint": ">=8.23.0",
18+
"ts-declaration-location": "^1.0.6"
19+
},
20+
"peerDependenciesMeta": {
21+
"ts-declaration-location": {
22+
"optional": true
23+
}
1824
},
1925
"dependencies": {
2026
"@eslint-community/eslint-utils": "^4.5.0",
@@ -25,8 +31,7 @@
2531
"globals": "^15.11.0",
2632
"ignore": "^5.3.2",
2733
"minimatch": "^9.0.5",
28-
"semver": "^7.6.3",
29-
"ts-declaration-location": "^1.0.6"
34+
"semver": "^7.6.3"
3035
},
3136
"devDependencies": {
3237
"@eslint/js": "^9.14.0",
@@ -52,6 +57,7 @@
5257
"punycode": "^2.3.1",
5358
"release-it": "^17.10.0",
5459
"rimraf": "^5.0.10",
60+
"ts-declaration-location": "^1.0.6",
5561
"ts-ignore-import": "^4.0.1",
5662
"type-fest": "^4.26.1",
5763
"typescript": "~5.6"
@@ -122,4 +128,4 @@
122128
"imports": {
123129
"#test-helpers": "./tests/test-helpers.js"
124130
}
125-
}
131+
}

0 commit comments

Comments
 (0)