Open
Description
Disallows repeating boilerplate options like { parserOptions: { ecmaVersion: 6 } }
in rule tests, in favor of specifying defaults in the RuleTester
constructor instead.
Incorrect code for this rule:
/* eslint eslint-plugin/no-boilerplate-test-options: error */
const ruleTester = new RuleTester();
ruleTester.run("foo", rule, {
valid: [
{
code: "foo",
parserOptions: { ecmaVersion: 6 }
}
],
invalid: [
{
code: "bar",
parserOptions: { ecmaVersion: 6 },
errors: ["baz"]
}
]
});
Correct code for this rule:
/* eslint eslint-plugin/no-boilerplate-test-options: error */
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
ruleTester.run("foo", rule, {
valid: [
{
code: "foo",
}
],
invalid: [
{
code: "bar",
errors: ["baz"]
}
]
});
There are a few open design questions:
- How many identical uses of
parserOptions
should the rule need to detect in order to report an error? (2? Some percentage of the total number of test cases? All of the test cases?) - Should the rule reason about maximum
ecmaVersion
? (For example, if some tests haveecmaVersion: 6
and others haveecmaVersion: 7
, should the rule conclude that the user can putecmaVersion: 7
in the constructor?) - Aside from
parserOptions
, what other duplicate options should the rule report? Should it reportRuleTester
-specific options such aserrors
? Should it report all configuration options (e.g.env
)?