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

Rule: disallow boilerplate test options #4

Open
not-an-aardvark opened this issue Apr 6, 2017 · 0 comments
Open

Rule: disallow boilerplate test options #4

not-an-aardvark opened this issue Apr 6, 2017 · 0 comments

Comments

@not-an-aardvark
Copy link
Contributor

not-an-aardvark commented Apr 6, 2017

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 have ecmaVersion: 6 and others have ecmaVersion: 7, should the rule conclude that the user can put ecmaVersion: 7 in the constructor?)
  • Aside from parserOptions, what other duplicate options should the rule report? Should it report RuleTester-specific options such as errors? Should it report all configuration options (e.g. env)?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants