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 Proposal: prefer-global-parser-options #85

Open
bmish opened this issue Nov 6, 2019 · 1 comment
Open

Rule Proposal: prefer-global-parser-options #85

bmish opened this issue Nov 6, 2019 · 1 comment

Comments

@bmish
Copy link
Member

bmish commented Nov 6, 2019

If all test cases specify the same parserOptions, then parserOptions should be set globally in the test file when creating the RuleTester to simplify the individual test cases.

Before:

const rule = require('../../../lib/rules/my-rule');
const RuleTester = require('eslint').RuleTester;

const eslintTester = new RuleTester();

eslintTester.run('my-rule', rule, {
  valid: [
    {
      code: 'someFunction()',
      parserOptions: { ecmaVersion: 6, sourceType: 'module' },
    },
    {
      code: 'otherFunction()',
      parserOptions: { ecmaVersion: 6, sourceType: 'module' },
    },
  ],
  invalid: [
    {
      code: 'finalFunction()',
      parserOptions: { ecmaVersion: 6, sourceType: 'module' },
      output: null,
      errors: [
        {
          message: 'Some error message',
          type: 'CallExpression',
        },
      ],
    },
  ],
});

After:

const rule = require('../../../lib/rules/my-rule');
const RuleTester = require('eslint').RuleTester;

const eslintTester = new RuleTester({
  parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});

eslintTester.run('my-rule', rule, {
  valid: ['someFunction()', 'otherFunction()'],
  invalid: [
    {
      code: 'finalFunction()',
      output: null,
      errors: [
        {
          message: 'Some error message',
          type: 'CallExpression',
        },
      ],
    },
  ],
});
@aladdin-add
Copy link
Contributor

related: #4

It's fine to use the global option when it's the same in all tests. The question is what to do if some options are different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants