wix-incubator / eslint-plugin-lodash

ESLint rules for lodash
MIT License
277 stars 65 forks source link

lodash/prefer-* rules cause problems with Jest mocks #340

Open jamesarosen opened 2 years ago

jamesarosen commented 2 years ago

The lodash/prefer-* rules, notably lodash/prefer-noop, cause issues with Jest Mocks.

For example:

import noop from 'lodash/noop'

jest.mock('./widget', () => ({
  __esModule: true,
  default: noop,
}))

This causes the error

The module factory of “jest.mock()” is not allowed to reference any out-of-scope variables.

The problem is that jest.mock can't reference the imported noop.

jamesarosen commented 2 years ago

This isn't hard to fix manually:

// .eslintrc.js
{
  overrides: [
    files: ['server/**/*.test.js'],
    rules: {
      'lodash/prefer-noop': 0,
    }
  ]
}

I'm wondering whether that should be in the default eslint-config. What do others think?