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

cliOptions.fix is ignored #58

Closed
Radivarig opened this issue Oct 23, 2018 · 3 comments · Fixed by #200
Closed

cliOptions.fix is ignored #58

Radivarig opened this issue Oct 23, 2018 · 3 comments · Fixed by #200

Comments

@Radivarig
Copy link

// jest-runner-eslint.config.js
module.exports = {
  cliOptions: {
    fix: true,
    rules: {
      'strict': 0,
    },
  },
}

The config is taken into account since strict override works, but it still does not fix and shows the following:

2 errors and 0 warnings potentially fixable with the `--fix` option.
@mkoelle
Copy link

mkoelle commented Feb 23, 2022

I've also been unable to get the runner to actually fix the files, I can see that auto fix is enabled with the output Press F to toggle ESLint --fix (enabled) , but the error is not addressed.

Running eslint --fix separately does fix the file however.

package versions

  • "eslint": "8.9.0",
  • "jest": "27.5.1",
  • "jest-runner-eslint": "1.0.0",
# test output
 8:21  error  There should be no space before ','  comma-spacing

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.038 s
Ran all test suites related to changed files.

Watch Usage
 › Press a to run all tests.
 › Press f to quit "only failed tests" mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press F to toggle ESLint --fix (enabled).
 › Press i to run failing tests interactively.
 › Press Enter to trigger a test run.
// jest.config.js
//....
  watchPlugins: ['jest-runner-eslint/watch-fix'],
  projects: [
    {
      displayName: 'test'
    },
    {
      runner: 'jest-runner-eslint',
      displayName: 'lint',
      testMatch: ['<rootDir>/src/**/*']
    }
  ]
//...
// package.json
...
  "jest-runner-eslint": {
    "cliOptions": {
      "fix":true
    }
  }
...

@iamakulov
Copy link

iamakulov commented Apr 5, 2023

So the reason for this lies here:

const cliOptions = {
...baseCliOptions,
fix: getComputedFixValue(baseCliOptions),
...extraOptions,
};

When you’re outside of the watch mode, extraOptions includes { fix: undefined }, which overrides the correct fix option. extraOptions, in turn, comes from here:

const runner = createJestRunner(require.resolve('./runESLint'), {
getExtraOptions: () => ({ fix: configOverrides.getFix() }),
});

That configOverrides.getFix() is always undefined in non-watch mode (or is set to true/false when you press F in the watch mode).

So, basically, we’re always overriding the correct fix option with undefined.

The fix would be to omit extraOptions that are not defined when doing the spread. (I won’t have time to submit the PR but maybe someone else wants? It should be small.)

@iamakulov
Copy link

Dunno what the workaround could be, though. I tried doing

// jest-runner-eslint.config.js
const configOverrides = require('jest-runner-eslint/build/utils/configOverrides')
configOverrides.getFix = () => true

but that didn’t help.

hassoubeat pushed a commit to hassoubeat/jest-runner-eslint that referenced this issue Aug 15, 2023
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

Successfully merging a pull request may close this issue.

3 participants