Skip to content

Commit 73ad24d

Browse files
fix: fix logic for getting a type's full name
1 parent e554e55 commit 73ad24d

File tree

3 files changed

+47
-81
lines changed

3 files changed

+47
-81
lines changed

lib/rules/no-sync.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const typeMatchesSpecifier =
1010
)
1111
const getTypeOfNode = require("../util/get-type-of-node")
1212
const getParserServices = require("../util/get-parser-services")
13-
const getNodeScopedName = require("../util/get-node-scoped-name")
13+
const getFullTypeName = require("../util/get-full-type-name")
1414

1515
const selectors = [
1616
// fs.readFileSync()
@@ -115,9 +115,16 @@ module.exports = {
115115
*/
116116
[selector.join(",")](node) {
117117
const parserServices = getParserServices(context)
118+
119+
/**
120+
* @type {import('typescript').Type | undefined | null}
121+
*/
118122
let type = undefined
119-
const nodeName =
120-
getNodeScopedName(node, parserServices) ?? node.name
123+
124+
/**
125+
* @type {string | undefined | null}
126+
*/
127+
let fullName = undefined
121128

122129
for (const ignore of ignores) {
123130
if (typeof ignore === "string") {
@@ -138,14 +145,19 @@ module.exports = {
138145
type === undefined
139146
? getTypeOfNode(node, parserServices)
140147
: type
148+
fullName =
149+
fullName === undefined
150+
? getFullTypeName(type)
151+
: fullName
152+
141153
if (
142154
typeMatchesSpecifier(
143155
parserServices.program,
144156
ignore,
145157
type
146158
) &&
147159
(ignore.name === undefined ||
148-
ignore.name.includes(nodeName))
160+
ignore.name.includes(fullName ?? node.name))
149161
) {
150162
return
151163
}
@@ -155,7 +167,7 @@ module.exports = {
155167
node: node.parent,
156168
messageId: "noSync",
157169
data: {
158-
propertyName: nodeName,
170+
propertyName: fullName ?? node.name,
159171
},
160172
})
161173
},

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict"
2+
3+
/**
4+
* @param {import('typescript').Type | null} type
5+
* @returns {string | null}
6+
*/
7+
module.exports = function getFullTypeName(type) {
8+
if (type === null) {
9+
return null
10+
}
11+
12+
/**
13+
* @type {string[]}
14+
*/
15+
let nameParts = []
16+
let currentSymbol = type.getSymbol()
17+
while (currentSymbol !== undefined) {
18+
nameParts.unshift(currentSymbol.getName())
19+
currentSymbol =
20+
/** @type {import('typescript').Symbol & {parent: import('typescript').Symbol | undefined}} */ (
21+
currentSymbol
22+
).parent
23+
}
24+
25+
if (nameParts.length === 0) {
26+
return null
27+
}
28+
29+
return nameParts.join(".")
30+
}

lib/util/get-node-scoped-name.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)