Skip to content

Commit 0779e2f

Browse files
authored
fix: Revert "feat: add support for ignoring sync methods from certain locations" (eslint-community#416)
1 parent 90de242 commit 0779e2f

18 files changed

+9
-543
lines changed

docs/rules/no-sync.md

-57
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ fs.readFileSync(somePath).toString();
6161
#### ignores
6262

6363
You can `ignore` specific function names using this option.
64-
Additionally, if you are using TypeScript you can optionally specify where the function is declared.
6564

6665
Examples of **incorrect** code for this rule with the `{ ignores: ['readFileSync'] }` option:
6766

@@ -79,62 +78,6 @@ Examples of **correct** code for this rule with the `{ ignores: ['readFileSync']
7978
fs.readFileSync(somePath);
8079
```
8180

82-
##### Advanced (TypeScript only)
83-
84-
You can provide a list of specifiers to ignore. Specifiers are typed as follows:
85-
86-
```ts
87-
type Specifier =
88-
| string
89-
| {
90-
from: "file";
91-
path?: string;
92-
name?: string[];
93-
}
94-
| {
95-
from: "package";
96-
package?: string;
97-
name?: string[];
98-
}
99-
| {
100-
from: "lib";
101-
name?: string[];
102-
}
103-
```
104-
105-
###### From a file
106-
107-
Examples of **correct** code for this rule with the ignore file specifier:
108-
109-
```js
110-
/*eslint n/no-sync: ["error", { ignores: [{ from: 'file', path: './foo.ts' }]}] */
111-
112-
import { fooSync } from "./foo"
113-
fooSync()
114-
```
115-
116-
###### From a package
117-
118-
Examples of **correct** code for this rule with the ignore package specifier:
119-
120-
```js
121-
/*eslint n/no-sync: ["error", { ignores: [{ from: 'package', package: 'effect' }]}] */
122-
123-
import { Effect } from "effect"
124-
const value = Effect.runSync(Effect.succeed(42))
125-
```
126-
127-
###### From the TypeScript library
128-
129-
Examples of **correct** code for this rule with the ignore lib specifier:
130-
131-
```js
132-
/*eslint n/no-sync: ["error", { ignores: [{ from: 'lib' }]}] */
133-
134-
const stylesheet = new CSSStyleSheet()
135-
stylesheet.replaceSync("body { font-size: 1.4em; } p { color: red; }")
136-
```
137-
13881
## 🔎 Implementation
13982

14083
- [Rule source](../../lib/rules/no-sync.js)

lib/rules/no-sync.js

+4-110
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
*/
55
"use strict"
66

7-
const typeMatchesSpecifier =
8-
/** @type {import('ts-declaration-location').default} */ (
9-
/** @type {unknown} */ (require("ts-declaration-location"))
10-
)
11-
const getTypeOfNode = require("../util/get-type-of-node")
12-
const getParserServices = require("../util/get-parser-services")
13-
const getFullTypeName = require("../util/get-full-type-name")
14-
157
const selectors = [
168
// fs.readFileSync()
179
// readFileSync.call(null, 'path')
@@ -40,56 +32,7 @@ module.exports = {
4032
},
4133
ignores: {
4234
type: "array",
43-
items: {
44-
oneOf: [
45-
{ type: "string" },
46-
{
47-
type: "object",
48-
properties: {
49-
from: { const: "file" },
50-
path: {
51-
type: "string",
52-
},
53-
name: {
54-
type: "array",
55-
items: {
56-
type: "string",
57-
},
58-
},
59-
},
60-
additionalProperties: false,
61-
},
62-
{
63-
type: "object",
64-
properties: {
65-
from: { const: "lib" },
66-
name: {
67-
type: "array",
68-
items: {
69-
type: "string",
70-
},
71-
},
72-
},
73-
additionalProperties: false,
74-
},
75-
{
76-
type: "object",
77-
properties: {
78-
from: { const: "package" },
79-
package: {
80-
type: "string",
81-
},
82-
name: {
83-
type: "array",
84-
items: {
85-
type: "string",
86-
},
87-
},
88-
},
89-
additionalProperties: false,
90-
},
91-
],
92-
},
35+
items: { type: "string" },
9336
default: [],
9437
},
9538
},
@@ -114,64 +57,15 @@ module.exports = {
11457
* @returns {void}
11558
*/
11659
[selector.join(",")](node) {
117-
const parserServices = getParserServices(context)
118-
119-
/**
120-
* @type {import('typescript').Type | undefined | null}
121-
*/
122-
let type = undefined
123-
124-
/**
125-
* @type {string | undefined | null}
126-
*/
127-
let fullName = undefined
128-
129-
for (const ignore of ignores) {
130-
if (typeof ignore === "string") {
131-
if (ignore === node.name) {
132-
return
133-
}
134-
135-
continue
136-
}
137-
138-
if (
139-
parserServices === null ||
140-
parserServices.program === null
141-
) {
142-
throw new Error(
143-
'TypeScript parser services not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires TypeScript parser services to be available.'
144-
)
145-
}
146-
147-
type =
148-
type === undefined
149-
? getTypeOfNode(node, parserServices)
150-
: type
151-
152-
fullName =
153-
fullName === undefined
154-
? getFullTypeName(type)
155-
: fullName
156-
157-
if (
158-
typeMatchesSpecifier(
159-
parserServices.program,
160-
ignore,
161-
type
162-
) &&
163-
(ignore.name === undefined ||
164-
ignore.name.includes(fullName ?? node.name))
165-
) {
166-
return
167-
}
60+
if (ignores.includes(node.name)) {
61+
return
16862
}
16963

17064
context.report({
17165
node: node.parent,
17266
messageId: "noSync",
17367
data: {
174-
propertyName: fullName ?? node.name,
68+
propertyName: node.name,
17569
},
17670
})
17771
},

lib/util/get-full-type-name.js

-47
This file was deleted.

lib/util/get-parser-services.js

-24
This file was deleted.

lib/util/get-type-of-node.js

-21
This file was deleted.

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@
1818
},
1919
"dependencies": {
2020
"@eslint-community/eslint-utils": "^4.4.1",
21-
"@typescript-eslint/utils": "^8.21.0",
2221
"enhanced-resolve": "^5.17.1",
2322
"eslint-plugin-es-x": "^7.8.0",
2423
"get-tsconfig": "^4.8.1",
2524
"globals": "^15.11.0",
2625
"ignore": "^5.3.2",
2726
"minimatch": "^9.0.5",
28-
"semver": "^7.6.3",
29-
"ts-declaration-location": "^1.0.5"
27+
"semver": "^7.6.3"
3028
},
3129
"devDependencies": {
3230
"@eslint/js": "^9.14.0",
3331
"@types/eslint": "^9.6.1",
3432
"@types/estree": "^1.0.6",
3533
"@types/node": "^20.17.5",
36-
"@typescript-eslint/parser": "^8.21.0",
37-
"@typescript-eslint/typescript-estree": "^8.21.0",
34+
"@typescript-eslint/parser": "^8.12.2",
35+
"@typescript-eslint/typescript-estree": "^8.12.2",
3836
"eslint": "^9.14.0",
3937
"eslint-config-prettier": "^9.1.0",
4038
"eslint-doc-generator": "^1.7.1",
@@ -54,7 +52,7 @@
5452
"rimraf": "^5.0.10",
5553
"ts-ignore-import": "^4.0.1",
5654
"type-fest": "^4.26.1",
57-
"typescript": "^5.7"
55+
"typescript": "~5.6"
5856
},
5957
"scripts": {
6058
"build": "node scripts/update",

tests/fixtures/no-sync/base/file.ts

-1
This file was deleted.

tests/fixtures/no-sync/base/tsconfig.json

-10
This file was deleted.

tests/fixtures/no-sync/file.ts

-1
This file was deleted.

tests/fixtures/no-sync/ignore-package/file.ts

-1
This file was deleted.

tests/fixtures/no-sync/ignore-package/node_modules/aaa/index.d.ts

-1
This file was deleted.

tests/fixtures/no-sync/ignore-package/node_modules/aaa/index.js

Whitespace-only changes.

tests/fixtures/no-sync/ignore-package/node_modules/aaa/package.json

-6
This file was deleted.

tests/fixtures/no-sync/ignore-package/package.json

-7
This file was deleted.

tests/fixtures/no-sync/ignore-package/tsconfig.json

-10
This file was deleted.

tests/fixtures/no-sync/tsconfig.json

-10
This file was deleted.

0 commit comments

Comments
 (0)