Skip to content

Commit 1b97ad9

Browse files
committed
feat(no-unnecessary-condition): improve diagnostics (#1092)
Part of #677. Improves no-unnecessary-condition diagnostics by: - narrowing primary spans to the decisive operator or optional-chain token - labeling relevant operands and expressions with their effective types - improving static comparison, callback, type-guard, and nullish diagnostics - adding focused range and regression coverage with updated snapshots Test: go test ./internal/rules/no_unnecessary_condition
1 parent 1abf9a5 commit 1b97ad9

4 files changed

Lines changed: 1545 additions & 246 deletions

File tree

e2e/__snapshots__/snapshot.test.ts.snap

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ exports[`TSGoLint E2E Snapshot Tests > should generate consistent diagnostics sn
474474
{
475475
"file_path": "fixtures/basic/rules/no-confusing-void-expression/index.ts",
476476
"kind": 0,
477+
"labeled_ranges": [
478+
{
479+
"label": "Type: undefined",
480+
"range": {
481+
"end": 255,
482+
"pos": 245,
483+
},
484+
},
485+
],
477486
"message": {
478487
"description": "Unnecessary conditional, value is always falsy.",
479488
"id": "alwaysFalsy",
@@ -2201,13 +2210,29 @@ exports[`TSGoLint E2E Snapshot Tests > should generate consistent diagnostics sn
22012210
{
22022211
"file_path": "fixtures/basic/rules/no-unsafe-enum-comparison/index.ts",
22032212
"kind": 0,
2213+
"labeled_ranges": [
2214+
{
2215+
"label": "Type: Status.Open",
2216+
"range": {
2217+
"end": 228,
2218+
"pos": 217,
2219+
},
2220+
},
2221+
{
2222+
"label": "Type: Color.Red",
2223+
"range": {
2224+
"end": 242,
2225+
"pos": 233,
2226+
},
2227+
},
2228+
],
22042229
"message": {
22052230
"description": "Unnecessary comparison between literal values.",
22062231
"id": "comparisonBetweenLiteralTypes",
22072232
},
22082233
"range": {
2209-
"end": 242,
2210-
"pos": 217,
2234+
"end": 232,
2235+
"pos": 229,
22112236
},
22122237
"rule": "no-unnecessary-condition",
22132238
},

0 commit comments

Comments
 (0)