eslint-plugin-th-rules 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-explicit-nil-check.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-explicit-nil-check.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAWtF,QAAA,MAAM,sBAAsB;;
|
|
1
|
+
{"version":3,"file":"prefer-explicit-nil-check.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-explicit-nil-check.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAWtF,QAAA,MAAM,sBAAsB;;CAmb1B,CAAC;AAEH,eAAe,sBAAsB,CAAC"}
|
|
@@ -46,12 +46,33 @@ const preferExplicitNilCheck = createRule({
|
|
|
46
46
|
return node.expression;
|
|
47
47
|
return node;
|
|
48
48
|
}
|
|
49
|
+
function getTypeFromSymbolAnnotation(symbol) {
|
|
50
|
+
const decl = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
51
|
+
if (_.isNil(decl))
|
|
52
|
+
return null;
|
|
53
|
+
if ('type' in decl) {
|
|
54
|
+
const typeNode = decl.type;
|
|
55
|
+
if (!_.isNil(typeNode)) {
|
|
56
|
+
return checker.getTypeFromTypeNode(typeNode);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
49
61
|
function getTsType(node) {
|
|
50
62
|
const unwrapped = unwrapChainExpression(node);
|
|
51
63
|
const tsNode = services.esTreeNodeToTSNodeMap.get(unwrapped);
|
|
52
64
|
if (_.isNil(tsNode))
|
|
53
65
|
return null;
|
|
54
|
-
|
|
66
|
+
let type;
|
|
67
|
+
if (unwrapped.type === AST_NODE_TYPES.Identifier) {
|
|
68
|
+
const symbol = checker.getSymbolAtLocation(tsNode);
|
|
69
|
+
const annotated = _.isNil(symbol) ? null : getTypeFromSymbolAnnotation(symbol);
|
|
70
|
+
type = annotated ?? checker.getTypeAtLocation(tsNode);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
type = checker.getTypeAtLocation(tsNode);
|
|
74
|
+
}
|
|
75
|
+
return checker.getWidenedType(type);
|
|
55
76
|
}
|
|
56
77
|
function isNullableFlag(flags) {
|
|
57
78
|
return (flags & ts.TypeFlags.Null) !== 0 || (flags & ts.TypeFlags.Undefined) !== 0;
|