Skip to content

Commit

Permalink
fix(experimental-utils): treat RuleTester arrays as readonly (#2601)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnixon committed Sep 28, 2020
1 parent 7cba2de commit 8025777
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/eslint-plugin/tests/rules/indent/indent.test.ts
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: [] },
);
Expand Down
6 changes: 3 additions & 3 deletions packages/experimental-utils/src/ts-eslint/RuleTester.ts
Expand Up @@ -64,7 +64,7 @@ interface InvalidTestCase<
/**
* Expected errors.
*/
readonly errors: TestCaseError<TMessageIds>[];
readonly errors: readonly TestCaseError<TMessageIds>[];
/**
* The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
*/
Expand Down Expand Up @@ -114,8 +114,8 @@ interface RunTests<
TOptions extends Readonly<unknown[]>
> {
// RuleTester.run also accepts strings for valid cases
readonly valid: (ValidTestCase<TOptions> | string)[];
readonly invalid: InvalidTestCase<TMessageIds, TOptions>[];
readonly valid: readonly (ValidTestCase<TOptions> | string)[];
readonly invalid: readonly InvalidTestCase<TMessageIds, TOptions>[];
}
interface RuleTesterConfig {
// should be require.resolve(parserPackageName)
Expand Down

0 comments on commit 8025777

Please sign in to comment.