Skip to content
Omer Ganim edited this page Oct 30, 2016 · 2 revisions

Version 2.0.0

We've just released a new major version, 2.0.0, which is a major release that features some major upgrades. This release also has some breaking changes, so please read the following.

Highlights

This is a summary of the major changes in the version.

Single Method Imports and Destructuring

This is the most major part of the upgrade - all the rules in the plugin now support both using single Lodash methods and importing the entire lodash library. for instance, all these snippets will cause the prop-shorthand rule to report when set to always:

  • Using CommonJS or ES6 to import the entire lodash library:
const _ = require('lodash');
//...
const ids = _.map(users, x => x.id); //Prefer property shorthand syntax
import _ from `lodash`;
//...
const ids = _.map(users, x => x.id); //Prefer property shorthand syntax
  • Using CommonJS or ES6 to import a single method
const map = require('lodash/map');
//...
const ids = map(users, x => x.id); //Prefer property shorthand syntax
import map from 'lodash/map';
//...
const ids = map(users, x => x.id); //Prefer property shorthand syntax
  • Importing methods as single members of the lodash library, even with aliases
import {map as m} from 'lodash';
//...
const ids = m(users, x => x.id); //Prefer property shorthand syntax
  • Using destructuring for importing methods from lodash
const {map: m} = require('lodash');
//...
const ids = m(users, x => x.id); //Prefer property shorthand syntax

Plugin rule configurations

The recommended configuration is now directed towards single-method imports. For those still planning on using the full build, there is a new configuration, canonical for using the full build. This configuration is best for these cases:

  • Using Lodash as a global (e.g. a <script> tag)
  • Using AMD syntax to load Lodash, e.g. with RequireJS (the plugin does not support importing single Lodash methods in AMD)
  • When using the full Lodash build (and using chaining)

The pragma setting

In version 1, pragma signified the Lodash object and defaulted to _ when none was specified. In version 2, the pragma setting can still be set as a "hint". In these cases, the rules will try to use the pragma to identify method calls first, and if that fails, will try to see if lodash or its methods were defined in the code.

Breaking Changes

There have been several changes to rules and configurations:

  • Node v0.10 is no longer supported.
  • The rule prefer-lodash-method's configuration for exceptions was changed. beforehand, there were three different ways to announce exceptions with confusing names, and now there are two: ignoreMethods to ignore specific methods, and ignoreObjects to ignore specific objects. Both receive arrays of strings, which can be regular expressions. e.g.:
{
"rules": {
    "lodash/prefer-lodash-method": [2, {"ignoreObjects": ["React(DOM)?"]}]
  }
}
  • The rules no-single-chain and prefer-chain were removed in favor of a comprehensive chaining rule. This rule allows you to choose between disallowing chains altogether, or requiring them over a certain depth of nesting.
  • The rule path-style has been reimplemented. The modes string and array have not changed, but since there is no longer a significant difference between string and array performance, the as-needed mode now recommends using strings, unless part of the path is a variable, e.g. _.get(x, ['a', someVar, 'b']) rather than _.get(x, 'a.' + someVar + 'b') or _.get(x, `a.${someVar}.b`). The default is now as-needed.