Skip to content

Commit 8025777

Browse files
authored
fix(experimental-utils): treat RuleTester arrays as readonly (typescript-eslint#2601)
1 parent 7cba2de commit 8025777

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/eslint-plugin/tests/rules/indent/indent.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ type Foo = string | {
621621
(acc, testCase) => {
622622
const indent = ' ';
623623

624+
const validCases = [...acc.valid];
625+
const invalidCases = [...acc.invalid];
626+
624627
const codeCases = testCase.code.map(code =>
625628
[
626629
'', // newline to make test error messages nicer
@@ -631,7 +634,7 @@ type Foo = string | {
631634

632635
codeCases.forEach(code => {
633636
// valid test case is just the code
634-
acc.valid.push(code);
637+
validCases.push(code);
635638

636639
const invalid = {
637640
// test the fixer by removing all the spaces
@@ -663,11 +666,11 @@ type Foo = string | {
663666
),
664667
};
665668
if (invalid.errors.length > 0) {
666-
acc.invalid.push(invalid);
669+
invalidCases.push(invalid);
667670
}
668671
});
669672

670-
return acc;
673+
return { ...acc, valid: validCases, invalid: invalidCases };
671674
},
672675
{ valid: [], invalid: [] },
673676
);

packages/experimental-utils/src/ts-eslint/RuleTester.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface InvalidTestCase<
6464
/**
6565
* Expected errors.
6666
*/
67-
readonly errors: TestCaseError<TMessageIds>[];
67+
readonly errors: readonly TestCaseError<TMessageIds>[];
6868
/**
6969
* The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
7070
*/
@@ -114,8 +114,8 @@ interface RunTests<
114114
TOptions extends Readonly<unknown[]>
115115
> {
116116
// RuleTester.run also accepts strings for valid cases
117-
readonly valid: (ValidTestCase<TOptions> | string)[];
118-
readonly invalid: InvalidTestCase<TMessageIds, TOptions>[];
117+
readonly valid: readonly (ValidTestCase<TOptions> | string)[];
118+
readonly invalid: readonly InvalidTestCase<TMessageIds, TOptions>[];
119119
}
120120
interface RuleTesterConfig {
121121
// should be require.resolve(parserPackageName)

0 commit comments

Comments
 (0)
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