Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(experimental-utils): treat RuleTester arrays as readonly #2601

Merged
merged 1 commit into from Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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