From 80257776b78bd2b2b4389d6bd530b009a75fb520 Mon Sep 17 00:00:00 2001 From: Daniel Nixon Date: Mon, 28 Sep 2020 10:12:20 +1000 Subject: [PATCH] fix(experimental-utils): treat RuleTester arrays as readonly (#2601) --- packages/eslint-plugin/tests/rules/indent/indent.test.ts | 9 ++++++--- packages/experimental-utils/src/ts-eslint/RuleTester.ts | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/indent/indent.test.ts b/packages/eslint-plugin/tests/rules/indent/indent.test.ts index beb648d4f52..8296bf19520 100644 --- a/packages/eslint-plugin/tests/rules/indent/indent.test.ts +++ b/packages/eslint-plugin/tests/rules/indent/indent.test.ts @@ -621,6 +621,9 @@ type Foo = string | { (acc, testCase) => { const indent = ' '; + const validCases = [...acc.valid]; + const invalidCases = [...acc.invalid]; + const codeCases = testCase.code.map(code => [ '', // newline to make test error messages nicer @@ -631,7 +634,7 @@ type Foo = string | { codeCases.forEach(code => { // valid test case is just the code - acc.valid.push(code); + validCases.push(code); const invalid = { // test the fixer by removing all the spaces @@ -663,11 +666,11 @@ type Foo = string | { ), }; if (invalid.errors.length > 0) { - acc.invalid.push(invalid); + invalidCases.push(invalid); } }); - return acc; + return { ...acc, valid: validCases, invalid: invalidCases }; }, { valid: [], invalid: [] }, ); diff --git a/packages/experimental-utils/src/ts-eslint/RuleTester.ts b/packages/experimental-utils/src/ts-eslint/RuleTester.ts index b54c1190ad8..a1fa2104a91 100644 --- a/packages/experimental-utils/src/ts-eslint/RuleTester.ts +++ b/packages/experimental-utils/src/ts-eslint/RuleTester.ts @@ -64,7 +64,7 @@ interface InvalidTestCase< /** * Expected errors. */ - readonly errors: TestCaseError[]; + readonly errors: readonly TestCaseError[]; /** * The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested. */ @@ -114,8 +114,8 @@ interface RunTests< TOptions extends Readonly > { // RuleTester.run also accepts strings for valid cases - readonly valid: (ValidTestCase | string)[]; - readonly invalid: InvalidTestCase[]; + readonly valid: readonly (ValidTestCase | string)[]; + readonly invalid: readonly InvalidTestCase[]; } interface RuleTesterConfig { // should be require.resolve(parserPackageName)