From cd41171ba7b39701e128ec1126e3c6883e376cd4 Mon Sep 17 00:00:00 2001 From: Vinccool96 Date: Thu, 26 Jun 2025 10:27:34 -0400 Subject: [PATCH 1/2] Switch to handwritten test cases and fixed messageId --- .../tests/rules/no-unused-expressions.test.ts | 229 +++++++++--------- .../eslint-plugin/typings/eslint-rules.d.ts | 2 +- 2 files changed, 120 insertions(+), 111 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts b/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts index 567b206a42ad..fa3159a96aa2 100644 --- a/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unused-expressions.test.ts @@ -1,6 +1,4 @@ -import type { TestCaseError } from '@typescript-eslint/rule-tester'; - -import { noFormat, RuleTester } from '@typescript-eslint/rule-tester'; +import { RuleTester } from '@typescript-eslint/rule-tester'; import rule from '../../src/rules/no-unused-expressions'; @@ -12,20 +10,6 @@ const ruleTester = new RuleTester({ }, }); -type RuleTestCaseError = Omit, 'messageId'>; - -// the base rule doesn't have messageIds -function error( - messages: RuleTestCaseError[], - // eslint-disable-next-line @typescript-eslint/no-explicit-any -): any[] { - return messages.map(message => ({ - ...message, - message: - 'Expected an assignment or function call and instead saw an expression.', - })); -} - ruleTester.run('no-unused-expressions', rule, { valid: [ ` @@ -91,37 +75,40 @@ ruleTester.run('no-unused-expressions', rule, { ], invalid: [ { - code: ` -if (0) 0; - `, - errors: error([ + code: 'if (0) 0;', + errors: [ { column: 8, - line: 2, + endColumn: 10, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -f(0), {}; - `, - errors: error([ + code: 'f(0), {};', + errors: [ { column: 1, - line: 2, + endColumn: 10, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -a, b(); - `, - errors: error([ + code: 'a, b();', + errors: [ { column: 1, - line: 2, + endColumn: 8, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` @@ -130,100 +117,111 @@ a() && f(); }; `, - errors: error([ + errors: [ { column: 1, + endColumn: 5, + endLine: 5, line: 2, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -a?.b; - `, - errors: error([ + code: 'a?.b;', + errors: [ { column: 1, - line: 2, + endColumn: 6, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -(a?.b).c; - `, - errors: error([ + code: '(a?.b).c;', + errors: [ { column: 1, - line: 2, + endColumn: 10, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -a?.['b']; - `, - errors: error([ + code: "a?.['b'];", + errors: [ { column: 1, - line: 2, + endColumn: 10, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -(a?.['b']).c; - `, - errors: error([ + code: "(a?.['b']).c;", + errors: [ { column: 1, - line: 2, + endColumn: 14, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -a?.b()?.c; - `, - errors: error([ + code: 'a?.b()?.c;', + errors: [ { column: 1, - line: 2, + endColumn: 11, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -(a?.b()).c; - `, - errors: error([ + code: '(a?.b()).c;', + errors: [ { column: 1, - line: 2, + endColumn: 12, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -one[2]?.[3][4]; - `, - errors: error([ + code: 'one[2]?.[3][4];', + errors: [ { column: 1, - line: 2, + endColumn: 16, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: ` -one.two?.three.four; - `, - errors: error([ + code: 'one.two?.three.four;', + errors: [ { column: 1, - line: 2, + endColumn: 21, + endLine: 1, + line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` @@ -232,14 +230,15 @@ module Foo { 'use strict'; } `, - errors: error([ + errors: [ { column: 3, endColumn: 16, endLine: 4, line: 4, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` @@ -250,54 +249,58 @@ namespace Foo { 'use strict'; } `, - errors: error([ + errors: [ { column: 3, endColumn: 16, endLine: 6, line: 6, + messageId: 'unusedExpression', }, - ]), + ], }, { - code: noFormat` + code: ` function foo() { const foo = true; - 'use strict'; + ('use strict'); } `, - errors: error([ + errors: [ { column: 3, - endColumn: 16, + endColumn: 18, endLine: 5, line: 5, + messageId: 'unusedExpression', }, - ]), + ], }, { code: 'foo && foo?.bar;', - errors: error([ + errors: [ { column: 1, endColumn: 17, endLine: 1, line: 1, + messageId: 'unusedExpression', }, - ]), + ], options: [{ allowShortCircuit: true }], }, { code: 'foo ? foo?.bar : bar.baz;', - errors: error([ + errors: [ { column: 1, endColumn: 26, endLine: 1, line: 1, + messageId: 'unusedExpression', }, - ]), + ], options: [{ allowTernary: true }], }, { @@ -305,81 +308,87 @@ function foo() { class Foo {} Foo; `, - errors: error([ + errors: [ { column: 1, endColumn: 13, endLine: 3, line: 3, + messageId: 'unusedExpression', }, - ]), + ], }, { code: 'Map;', - errors: error([ + errors: [ { column: 1, endColumn: 21, endLine: 1, line: 1, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` declare const foo: number | undefined; foo; `, - errors: error([ + errors: [ { column: 1, endColumn: 5, endLine: 3, line: 3, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` declare const foo: number | undefined; foo as any; `, - errors: error([ + errors: [ { column: 1, endColumn: 12, endLine: 3, line: 3, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` declare const foo: number | undefined; foo; `, - errors: error([ + errors: [ { column: 1, endColumn: 10, endLine: 3, line: 3, + messageId: 'unusedExpression', }, - ]), + ], }, { code: ` declare const foo: number | undefined; foo!; `, - errors: error([ + errors: [ { column: 1, endColumn: 6, endLine: 3, line: 3, + messageId: 'unusedExpression', }, - ]), + ], }, ], }); diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 0a72f5b1ed80..b7a830094823 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -345,7 +345,7 @@ declare module 'eslint/lib/rules/no-unused-expressions' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - 'expected', + 'unusedExpression', [ { allowShortCircuit?: boolean; From 1438ffdc3fca2d77108b1103e0f6651b2d737055 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Sun, 6 Jul 2025 16:08:53 -0600 Subject: [PATCH 2/2] empty pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy