Skip to content

Commit baedad5

Browse files
committed
feat: restrict-plus-operands: improve diagnostic (#725)
NOTE: There is an issue with help messages not showing up in snapshots, I will fix this in the following PR. This rule's error message is packed with both type information and help information (what types are allowed). I've moved the resolved type info to be labeled ranges, and moved the message about what types are allowed to the help message. This should keep the information a little bit more structured and not crowd the main error message as much.
1 parent f3fe501 commit baedad5

File tree

3 files changed

+297
-95
lines changed

3 files changed

+297
-95
lines changed

e2e/__snapshots__/snapshot.test.ts.snap

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,8 +3298,24 @@ exports[`TSGoLint E2E Snapshot Tests > should generate consistent diagnostics sn
32983298
{
32993299
"file_path": "fixtures/basic/rules/restrict-plus-operands/index.ts",
33003300
"kind": 0,
3301+
"labeled_ranges": [
3302+
{
3303+
"label": "Type: bigint",
3304+
"range": {
3305+
"end": 12,
3306+
"pos": 10,
3307+
},
3308+
},
3309+
{
3310+
"label": "Type: number",
3311+
"range": {
3312+
"end": 16,
3313+
"pos": 15,
3314+
},
3315+
},
3316+
],
33013317
"message": {
3302-
"description": "Numeric '+' operations must either be both bigints or both numbers. Got \`bigint\` + \`number\`.",
3318+
"description": "Numeric '+' operations must either be both bigints or both numbers.",
33033319
"id": "bigintAndNumber",
33043320
},
33053321
"range": {
@@ -3312,7 +3328,8 @@ exports[`TSGoLint E2E Snapshot Tests > should generate consistent diagnostics sn
33123328
"file_path": "fixtures/basic/rules/restrict-plus-operands/index.ts",
33133329
"kind": 0,
33143330
"message": {
3315-
"description": "Invalid operand for a '+' operation. Operands must each be a number or string, allowing a string + any of: \`any\`, \`boolean\`, \`null\`, \`RegExp\`, \`undefined\`. Got \`never\`.",
3331+
"description": "Invalid operand of type 'never' for a '+' operation.",
3332+
"help": "Operands must each be a number or string, allowing a string + any of: \`any\`, \`boolean\`, \`null\`, \`RegExp\`, \`undefined\`.",
33163333
"id": "invalid",
33173334
},
33183335
"range": {

0 commit comments

Comments
 (0)