Skip to content

Commit

Permalink
reuse invalid tests to test fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jun 28, 2019
1 parent f993881 commit 0e57f7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-explicit-any.ts
Expand Up @@ -5,13 +5,13 @@ import {
import * as util from '../util';
import { TSESLint } from '@typescript-eslint/experimental-utils';

type Options = [
export type Options = [
{
fixToUnknown?: boolean;
ignoreRestArgs?: boolean;
}
];
type MessageIds = 'unexpectedAny';
export type MessageIds = 'unexpectedAny';

export default util.createRule<Options, MessageIds>({
name: 'no-explicit-any',
Expand Down
27 changes: 24 additions & 3 deletions packages/eslint-plugin/tests/rules/no-explicit-any.test.ts
@@ -1,5 +1,8 @@
import rule from '../../src/rules/no-explicit-any';
import rule, { MessageIds, Options } from '../../src/rules/no-explicit-any';
import { RuleTester } from '../RuleTester';
import { TSESLint } from '@typescript-eslint/experimental-utils';

type InvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -187,7 +190,7 @@ type obj = {
options: [{ ignoreRestArgs: true }],
},
],
invalid: [
invalid: ([
{
code: 'const number: any = 1',
errors: [
Expand Down Expand Up @@ -784,5 +787,23 @@ type obj = {
},
],
},
],
] as InvalidTestCase[]).reduce<InvalidTestCase[]>((acc, testCase) => {
acc.push(testCase);
const options = testCase.options || [];
const code = `// fixToUnknown: true\n${testCase.code}`;
acc.push({
code,
output: code.replace(/any/g, 'unknown'),
options: [{ ...options[0], fixToUnknown: true }],
errors: testCase.errors.map(err => {
if (err.line === undefined) {
return err;
}

return { ...err, line: err.line + 1 };
}),
});

return acc;
}, []),
});

0 comments on commit 0e57f7b

Please sign in to comment.