diff --git a/README.md b/README.md index 802f9ea..7c4e0cd 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ React-specific guidelines described at [RingCentral React Style Guide](https://g 1. [Language statements and features](#language-statements-and-features) 1. [Spaces and alignments](#spaces-and-alignments) 1. [Naming](#naming) +1. [External libraries](#external-libraries) ## Overview @@ -825,3 +826,182 @@ export class MyCompositeComponent { } } ``` + +## External libraries + +### Prefer native js vs lodash + +> Reason: lodash is a great library which contains a lot of useful functions but the modern js has the short identical part of this functionality so some lodash functions are excess alternative. + +> Don't forget to check necessary browsers compatibility and turn on polyfills if it's needed. +```javascript +// BAD +_.each([1, 2, 3], callback); +// GOOD +[1, 2, 3].forEach(callback); +``` +```javascript +// BAD +_.filter([1, 2, 3], callback); +// GOOD +[1, 2, 3].filter(callback); +``` +```javascript +// BAD +_.compact([1, 2, 3, 0, false, '']); +// GOOD +[1, 2, 3, 0, false, ''].filter(Boolean); +``` +```javascript +// BAD +_.map([1, 2, 3], callback); +// GOOD +[1, 2, 3].map(callback); +``` +```javascript +// BAD +_.every([1, 2, 3], callback); +// GOOD +[1, 2, 3].every(callback); +``` +```javascript +// BAD +_.some([1, 2, 3], callback); +// GOOD +[1, 2, 3].some(callback); +``` +```javascript +// BAD +_.reduce([1, 2, 3], callback, 0); +// GOOD +[1, 2, 3].reduce(callback, 0); +``` +```javascript +// BAD +_.concat([1, 2, 3], [4, 5, 6]); +// GOOD +[1, 2, 3].concat([4, 5, 6]); +``` +```javascript +// BAD +_.indexOf([1, 2, 3], 1); +// GOOD +[1, 2, 3].indexOf(1); +``` +```javascript +// BAD +_.includes([1, 2, 3], 1); +// GOOD +[1, 2, 3].includes(1); +``` +```javascript +// BAD +const first = _.first([1, 2, 3]); +// GOOD +const [first] = [1, 2, 3]; +``` +```javascript +// BAD +_.join([1, 2, 3], '-'); +// GOOD +[1, 2, 3].join('-'); +``` +```javascript +// BAD +_.reverse([1, 2, 3]); +// GOOD +[1, 2, 3].reverse(); +``` +```javascript +// BAD +_.uniq([1, 2, 3, 3, 2]); +// GOOD +[...new Set([1, 2, 3, 3, 2])]; +``` +```javascript +// BAD +_.isArray([1, 2, 3]); +// GOOD +Array.isArray([1, 2, 3]); +``` +```javascript +// BAD +_.size([1, 2, 3]); +// GOOD +[1, 2, 3].length; +``` +```javascript +// BAD +_.isEmpty([]); +// GOOD +[].length === 0; +```` +```javascript +// BAD +_.bind(func, this); +// GOOD +func.bind(this); +``` +```javascript +// BAD +_.isNaN(value); +// GOOD +Number.isNaN(value); +``` +```javascript +// BAD +_.isUndefined(value); +// GOOD +value === undefined; +``` +```javascript +// BAD +_.isEmpty(object); +// GOOD +Object.keys(object).length === 0; +``` +```javascript +// BAD +const foo = _.assign({}, object1, object2); +// GOOD +const foo = { + ...object1, + ...object2, +}; +``` +```javascript +// BAD +const others = _.omit({a: 1, b: 2, c: 3, d: 4}, ['a', 'c']); +// GOOD +const {a, c, ...others} = {a: 1, b: 2, c: 3, d: 4}; +``` +```javascript +// BAD +_.isEmpty(object); +// GOOD +Object.keys(object).length === 0; +```` +```javascript +// BAD +_.keys(object); +// GOOD +Object.keys(object); +``` +```javascript +// BAD +_.values(object); +// GOOD +Object.values(object); +``` +```javascript +// BAD +_.entries(object); +// GOOD +Object.entries(object); +``` +```javascript +// BAD +_.trim(' 123 '); +// GOOD +' 123 '.trim(); +``` diff --git a/eslint-config-ringcentral/index.js b/eslint-config-ringcentral/index.js index 90de1f8..a985fe7 100644 --- a/eslint-config-ringcentral/index.js +++ b/eslint-config-ringcentral/index.js @@ -15,8 +15,8 @@ module.exports = { }, sourceType: 'module' }, - plugins: ['react', 'import', 'ringcentral'], - extends: ['eslint:recommended', 'plugin:ringcentral/all'], + plugins: ['react', 'import', 'ringcentral', 'you-dont-need-lodash-underscore'], + extends: ['eslint:recommended', 'plugin:ringcentral/all', 'plugin:you-dont-need-lodash-underscore/all-warn'], globals: { chai: true, expect: true, diff --git a/eslint-config-ringcentral/package.json b/eslint-config-ringcentral/package.json index 79f0c04..c86c530 100644 --- a/eslint-config-ringcentral/package.json +++ b/eslint-config-ringcentral/package.json @@ -30,12 +30,14 @@ "eslint": ">=4.1.1", "eslint-plugin-import": "^2.16.0", "eslint-plugin-react": "^7.1.0", - "eslint-plugin-ringcentral": "~1.0.5" + "eslint-plugin-ringcentral": "~1.0.5", + "eslint-plugin-you-dont-need-lodash-underscore": "^6.4.0" }, "peerDependencies": { "eslint": ">=4.1.1", "eslint-plugin-import": "^2.16.0", "eslint-plugin-react": "^7.1.0", - "eslint-plugin-ringcentral": "~1.0.5" + "eslint-plugin-ringcentral": "~1.0.5", + "eslint-plugin-you-dont-need-lodash-underscore": "^6.4.0" } }