eslint-plugin-you-dont-need-lodash-underscore
Advanced tools
Comparing version 6.3.1 to 6.4.0
@@ -22,2 +22,10 @@ 'use strict'; | ||
}, | ||
ImportDeclaration(node) { | ||
if (node.source.value === `lodash/${rule}`) { | ||
context.report({ | ||
node, | ||
message: `Import from 'lodash/${rule}' detected. Consider using the native ${alternative}` | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -24,0 +32,0 @@ } |
@@ -14,2 +14,6 @@ { | ||
}, | ||
"last": { | ||
"compatible": true, | ||
"alternative": "Array.prototype.slice()" | ||
}, | ||
"lastIndexOf": { | ||
@@ -29,3 +33,3 @@ "compatible": true, | ||
"find": { | ||
"compatible": true, | ||
"compatible": false, | ||
"alternative": "Array.prototype.find()", | ||
@@ -39,7 +43,15 @@ "ES6": true | ||
}, | ||
"first": { | ||
"compatible": true, | ||
"alternative": "Array.prototype.slice()" | ||
}, | ||
"findIndex": { | ||
"compatible": true, | ||
"compatible": false, | ||
"alternative": "Array.prototype.findIndex()", | ||
"ES6": true | ||
}, | ||
"isArray": { | ||
"compatible": true, | ||
"alternative": "Array.isArray()" | ||
}, | ||
@@ -120,3 +132,13 @@ "each": { | ||
}, | ||
"slice": { | ||
"compatible": true, | ||
"alternative": "Array.prototype.slice()" | ||
}, | ||
"bind": { | ||
"ruleName": "bind", | ||
"compatible": true, | ||
"alternative": "Function.prototype.bind()" | ||
}, | ||
"isNaN": { | ||
@@ -180,3 +202,12 @@ "ruleName": "is-nan", | ||
"ES6": true | ||
}, | ||
"uniq": { | ||
"compatible": true, | ||
"alternative": "[... new Set(arr)]", | ||
"ES6": true | ||
}, | ||
"replace": { | ||
"compatible": true, | ||
"alternative": "String.prototype.replace()" | ||
} | ||
} |
{ | ||
"name": "eslint-plugin-you-dont-need-lodash-underscore", | ||
"version": "6.3.1", | ||
"version": "6.4.0", | ||
"description": "Check methods you can use natively without lodash/underscore", | ||
@@ -25,3 +25,4 @@ "repository": { | ||
"coveralls": "cat ./coverage/lcov.info | coveralls", | ||
"test": "istanbul cover tests" | ||
"test": "istanbul cover tests", | ||
"test:unit": "mocha tests/unit" | ||
}, | ||
@@ -34,3 +35,5 @@ "dependencies": { | ||
"eslint": "^3.0.0", | ||
"istanbul": "^0.4.4" | ||
"istanbul": "^0.4.4", | ||
"lodash": "^4.17.4", | ||
"mocha": "^4.1.0" | ||
}, | ||
@@ -37,0 +40,0 @@ "engines": { |
436
README.md
@@ -87,8 +87,15 @@ # You don't (may not) need Lodash/Underscore [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cht8687/You-Dont-Need-Lodash-Underscore) | ||
1. [_.findIndex](#_findindex) | ||
1. [_.first](#_first) | ||
1. [_.flatten](#_flatten) | ||
1. [_.flattenDeep](#_flattendeep) | ||
1. [_.fromPairs](#_frompairs) | ||
1. [_.head and _.tail](#_head-and-_tail) | ||
1. [_.indexOf](#_indexof) | ||
1. [_.join](#_join) | ||
1. [_.last](#_last) | ||
1. [_.lastIndexOf](#_lastindexof) | ||
1. [_.reverse](#_reverse) | ||
1. [_.without](#_without) | ||
1. [_.slice](#_slice) | ||
1. [_.isArray](#_isarray) | ||
@@ -104,2 +111,3 @@ **[Collection*](#collection*)** | ||
1. [_.filter](#_filter) | ||
1. [_.groupBy](#_groupby) | ||
1. [_.includes](#_includes) | ||
@@ -109,2 +117,3 @@ 1. [_.map](#_map) | ||
1. [_.pluck](#_pluck) | ||
1. [_.range](#_range) | ||
1. [_.reduce](#_reduce) | ||
@@ -114,2 +123,3 @@ 1. [_.reduceRight](#_reduceright) | ||
1. [_.some](#_some) | ||
1. [_.uniq](#_uniq) | ||
@@ -119,2 +129,4 @@ **[Function](#function)** | ||
1. [_.after](#_after) | ||
1. [_.bind](#_bind) | ||
1. [_.partial](#_partial) | ||
@@ -139,4 +151,4 @@ **[Lang](#lang)** | ||
1. [_.trim](#_trim) | ||
1. [_.replace](#_replace) | ||
## Array | ||
@@ -146,3 +158,3 @@ | ||
Creates an array with all falsey values removed. | ||
Creates an array with all falsy values removed. | ||
@@ -154,3 +166,3 @@ ```js | ||
// Native | ||
[0, 1, false, 2, '', 3].filter( v => !!v) | ||
[0, 1, false, 2, '', 3].filter(v => v) | ||
``` | ||
@@ -233,3 +245,3 @@ | ||
:-: | :-: | :-: | :-: | :-: | | ||
45.0 ✔ | 31.0 ✔ | Not supported | Not supported | 7.1 ✔ | | ||
45.0 ✔ | 31.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ | | ||
@@ -268,3 +280,3 @@ **[⬆ back to top](#quick-links)** | ||
:-: | :-: | :-: | :-: | :-: | | ||
45.0 ✔ | 25.0 ✔ | Not supported | Not supported | 7.1 ✔ | | ||
45.0 ✔ | 25.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ | | ||
@@ -305,6 +317,115 @@ **[⬆ back to top](#quick-links)** | ||
:-: | :-: | :-: | :-: | :-: | | ||
45.0 ✔ | 25.0 ✔ | Not supported | Not supported | 7.1 ✔ | | ||
45.0 ✔ | 25.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.first | ||
Returns the first element of an array. Passing n will return the first n elements of the array. | ||
```js | ||
// Underscore/Lodash | ||
_.first([1, 2, 3, 4, 5]); | ||
// => 1 | ||
_.first([1, 2, 3, 4, 5], 2); | ||
// => [1, 2] | ||
// Native | ||
[1, 2, 3, 4, 5][0]; | ||
// => 1 | ||
[1, 2, 3, 4, 5].slice(0, 2); | ||
// => [1, 2] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | ✔ | ✔ | ✔ | ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.flatten | ||
Flattens array a single level deep. | ||
```js | ||
// Underscore/Lodash | ||
_.flatten([1, [2, [3, [4]], 5]]); | ||
// => [1, 2, [3, [4]], 5] | ||
// Native | ||
const flatten = [1, [2, [3, [4]], 5]].reduce( (a, b) => a.concat(b), []) | ||
// => [1, 2, [3, [4]], 5] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
46.0 ✔ | 3.0 ✔ | 9.0 ✔ | 10.5 ✔ | 7.1 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.flattenDeep | ||
Recursively flattens array. | ||
```js | ||
// Underscore/Lodash | ||
_.flattenDeep([1, [2, [3, [4]], 5]]); | ||
// => [1, 2, 3, 4, 5] | ||
// Native | ||
const flattenDeep = (arr) => Array.isArray(arr) | ||
? arr.reduce( (a, b) => [...flattenDeep(a), ...flattenDeep(b)] , []) | ||
: [arr] | ||
flattenDeep([1, [[2], [3, [4]], 5]]) | ||
// => [1, 2, 3, 4, 5] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
46.0 ✔ | 16.0 ✔ | Not supported | 37.0 ✔ | 7.1 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.fromPairs | ||
Returns an object composed from key-value pairs. | ||
```js | ||
// Underscore/Lodash | ||
_.fromPairs([['a', 1], ['b', 2]]); | ||
// => { 'a': 1, 'b': 2 } | ||
// Native | ||
const fromPairs = function(arr) { | ||
return arr.reduce(function(accumulator, value) { | ||
accumulator[value[0]] = value[1]; | ||
return accumulator; | ||
}, {}) | ||
} | ||
// Compact form | ||
const fromPairs = (arr) => arr.reduce((acc, val) => (acc[val[0]] = val[1], acc), {}) | ||
fromPairs([['a', 1], ['b', 2]]); | ||
// => { 'a': 1, 'b': 2 } | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.head and _.tail | ||
@@ -339,3 +460,3 @@ Gets the first element or all but the first element. | ||
:-: | :-: | :-: | :-: | :-: | | ||
49 ✔ | 34 ✔ | Not Supported | Not Supported | ✔ | | ||
49 ✔ | 34 ✔ | Not Supported | 37 ✔ | ✔ | | ||
@@ -394,2 +515,35 @@ **[⬆ back to top](#quick-links)** | ||
### _.last | ||
Returns the last element of an array. Passing n will return the last n elements of the array. | ||
```js | ||
// Underscore/Lodash | ||
const numbers = [1, 2, 3, 4, 5]; | ||
_.last(numbers); | ||
// => 5 | ||
_.last(numbers, 2); | ||
// => [4, 5] | ||
// Native | ||
const numbers = [1, 2, 3, 4, 5]; | ||
numbers[numbers.length - 1]; | ||
// => 5 | ||
//or | ||
numbers.slice(-1)[0]; | ||
// => 5 | ||
numbers.slice(-2); | ||
// => [4, 5] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | ✔ | ✔ | ✔ | ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.lastIndexOf | ||
@@ -477,2 +631,48 @@ | ||
### _.slice | ||
Returns a shallow copy of a portion of an array into a new array object selected from `begin` to `end` (`end` not included) | ||
```js | ||
// Lodash | ||
var array = [1, 2, 3, 4] | ||
console.log(_.slice(array, 1, 3)) | ||
// output: [2, 3] | ||
// Native | ||
var array = [1, 2, 3, 4] | ||
console.log(array.slice(1, 3)); | ||
// output: [2, 3] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | ✔ | ✔ | ✔ | ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.isArray | ||
Returns true if given value is an array. | ||
```js | ||
// Lodash | ||
var array = [] | ||
console.log(_.isArray(array)) | ||
// output: true | ||
// Native | ||
var array = [] | ||
console.log(Array.isArray(array)); | ||
// output: true | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
5 ✔ | 4 ✔ | 9 ✔ | 10.5 ✔ | 5 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
## Collection* | ||
@@ -575,2 +775,38 @@ | ||
### _.groupBy | ||
Group items by key. | ||
```js | ||
// Underscore/Lodash | ||
var grouped = _.groupBy(['one', 'two', 'three'], 'length') | ||
console.log(grouped) | ||
// output: {3: ["one", "two"], 5: ["three"]} | ||
// Native | ||
var grouped = ['one', 'two', 'three'].reduce((r, v, i, a, k = v.length) => ((r[k] || (r[k] = [])).push(v), r), {}) | ||
console.log(grouped) | ||
// output: {3: ["one", "two"], 5: ["three"]} | ||
``` | ||
```js | ||
// Underscore/Lodash | ||
var grouped = _.groupBy([1.3, 2.1, 2.4], num => Math.floor(num)) | ||
console.log(grouped) | ||
// output: {1: [1.3], 2: [2.1, 2.4]} | ||
// Native | ||
var grouped = [1.3, 2.1, 2.4].reduce((r, v, i, a, k = Math.floor(v)) => ((r[k] || (r[k] = [])).push(v), r), {}) | ||
console.log(grouped) | ||
// output: {1: [1.3], 2: [2.1, 2.4]} | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.includes | ||
@@ -659,3 +895,3 @@ | ||
const minByValue = makeSelect((a, b) => a.value <= b.value) | ||
const maxByValue = makeSelect((a, b) => a.value <= b.value) | ||
const maxByValue = makeSelect((a, b) => a.value >= b.value) | ||
@@ -672,3 +908,3 @@ // main logic | ||
const minBy = (collection, key) => { | ||
// slower becouse need to create a lambda function for each call... | ||
// slower because need to create a lambda function for each call... | ||
const select = (a, b) => a[key] <= b[key] ? a : b | ||
@@ -678,3 +914,3 @@ return collection.reduce(select, {}) | ||
console.log(minBy(data)) | ||
console.log(minBy(data, 'value')) | ||
// output: { value: 2 } | ||
@@ -749,2 +985,38 @@ ``` | ||
### _.range | ||
Creates an array of numbers progressing from start up to. | ||
```js | ||
// Underscore/Lodash | ||
_.range(4) // output: [0, 1, 2, 3] | ||
_.range(-4) // output: [0, -1, -2, -3] | ||
_.range(1, 5) // output: [1, 2, 3, 4] | ||
_.range(0, 20, 5) // output: [0, 5, 10, 15] | ||
// Native ( solution with Array.from ) | ||
Array.from({length: 4}, (_, i) => i) // output: [0, 1, 2, 3] | ||
Array.from({length: 4}, (_, i) => -i) // output: [0, -1, -2, -3] | ||
Array.from({length: 4}, (_, i) => i + 1) // output: [1, 2, 3, 4] | ||
Array.from({length: 4}, (_, i) => i * 5) // output: [0, 5, 10, 15] | ||
// Native ( solution with keys() and spread ) | ||
[...Array(4).keys()] // output: [0, 1, 2, 3] | ||
``` | ||
#### Browser Support ( Array.from ) | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
45 ✔ | 32 ✔ | Not supported | ✔ | 9.0 ✔ | | ||
#### Browser Support ( keys and array spread ) | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
46 ✔ | 16 ✔ | Not supported | 37 ✔ | 7.1 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.reduceRight | ||
@@ -833,2 +1105,28 @@ | ||
:-: | :-: | :-: | :-: | :-: | | ||
38 ✔ | 13 ✔ | Not Supported | 25 ✔ | 9 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.uniq | ||
Produces a duplicate-free version of the array, using === to test object equality. | ||
```js | ||
// Underscore/Lodash | ||
var array = [1, 2, 1, 4, 1, 3] | ||
var result = _.uniq(array) | ||
console.log(result) | ||
// output: [1, 2, 4, 3] | ||
// Native | ||
var array = [1, 2, 1, 4, 1, 3]; | ||
var result = [...new Set(array)]; | ||
console.log(result) | ||
// output: [1, 2, 4, 3] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ | | ||
@@ -844,3 +1142,3 @@ | ||
```js | ||
```js | ||
var notes = ['profile', 'settings'] | ||
@@ -870,4 +1168,58 @@ // Underscore/Lodash | ||
**[⬆ back to top](#quick-links)** | ||
### _.bind | ||
Create a new function that calls _func_ with _thisArg_ and _args_. | ||
```js | ||
var objA = { | ||
x: 66, | ||
offsetX: function(offset) { | ||
return this.x + offset; | ||
} | ||
} | ||
var objB = { | ||
x: 67 | ||
}; | ||
// Underscore/Lodash | ||
var boundOffsetX = _.bind(objA.offsetX, objB, 0); | ||
// Native | ||
var boundOffsetX = objA.offsetX.bind(objB, 0); | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | ✔ | 9 ✔ | ✔ | ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
### _.partial | ||
Create a new function that calls _func_ with _args_. | ||
```js | ||
// Lodash | ||
function greet(greeting, name) { | ||
return greeting + ' ' + name; | ||
} | ||
var sayHelloTo = _.partial(greet, 'hello'); | ||
// Native | ||
function greet(greeting, name) { | ||
return greeting + ' ' + name; | ||
} | ||
var sayHelloTo = (...args) => greet('hello', ...args) | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
62 ✔ | 56 ✔ | ✗ | 49 ✔ | 11 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
## Lang | ||
@@ -945,3 +1297,3 @@ | ||
Bar.prototype.f = 6; | ||
var result = Object.assign(new Foo, new Bar); | ||
var result = Object.assign({}, new Foo, new Bar); | ||
console.log(result); | ||
@@ -992,3 +1344,3 @@ // output: { 'c': 3, 'e': 5 } | ||
console.log(result) | ||
// output: [["one", 1], ["two": 2], ["three", 3]] | ||
// output: [["one", 1], ["two", 2], ["three", 3]] | ||
@@ -998,3 +1350,3 @@ // Native | ||
console.log(result2) | ||
// output: [["one", 1], ["two": 2], ["three", 3]] | ||
// output: [["one", 1], ["two", 2], ["three", 3]] | ||
``` | ||
@@ -1030,3 +1382,3 @@ | ||
:-: | :-: | :-: | :-: | :-: | | ||
54 ✔ | 47 ✔ | Not supported | Not supported | Not supported | | ||
54 ✔ | 47 ✔ | Not supported | 41.0 ✔ | 10.1 ✔ | | ||
@@ -1057,3 +1409,3 @@ **[⬆ back to top](#quick-links)** | ||
:-: | :-: | :-: | :-: | :-: | | ||
41 ✔ | 24 ✔ | Not supported | Not supported | 9 ✔ | | ||
41 ✔ | 24 ✔ | Not supported | 28 ✔ | 9 ✔ | | ||
@@ -1074,3 +1426,3 @@ **[⬆ back to top](#quick-links)** | ||
const templateLitreal = (value) => `hello ${value.user}`; | ||
templateLiterlFunction({ 'user': 'fred' }); | ||
templateLitreal({ 'user': 'fred' }); | ||
``` | ||
@@ -1158,2 +1510,29 @@ | ||
### _.replace | ||
returns a new string with some or all matches of a `pattern` replaced by a `replacement` | ||
```js | ||
// Lodash | ||
var re = /apples/gi; | ||
var str = 'Apples are round, and apples are juicy.'; | ||
var newstr = _.replace(str, re, 'oranges'); | ||
console.log(newstr); | ||
// output: 'oranges are round, and oranges are juicy.' | ||
// Native | ||
var re = /apples/gi; | ||
var str = 'Apples are round, and apples are juicy.'; | ||
var result = str.replace(re, 'oranges'); | ||
console.log(result); | ||
// output: 'oranges are round, and oranges are juicy.' | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
✔ | ✔ | ✔ | ✔ | ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
## Reference | ||
@@ -1165,3 +1544,26 @@ | ||
### _.uniq | ||
Removes all duplicates entries from an array. | ||
```js | ||
// Underscore/Lodash | ||
var result = _.uniq([1, 2, 1, 4, 1, 3]); | ||
console.log(result) | ||
// output: [1, 2, 4, 3] | ||
// Native | ||
var result = [... new Set([1, 2, 1, 4, 1, 3])] | ||
console.log(result) | ||
// output: [1, 2, 4, 3] | ||
``` | ||
#### Browser Support | ||
![Chrome][chrome-image] | ![Firefox][firefox-image] | ![IE][ie-image] | ![Opera][opera-image] | ![Safari][safari-image] | ||
:-: | :-: | :-: | :-: | :-: | | ||
38 ✔ | 13 ✔ | 11 ✔ | 25 ✔ | 7.1 ✔ | | ||
**[⬆ back to top](#quick-links)** | ||
## Inspired by: | ||
@@ -1168,0 +1570,0 @@ |
@@ -11,4 +11,4 @@ require('./lib/rules/all.js'); | ||
assert.equal(plugin.configs['compatible-warn'].rules['you-dont-need-lodash-underscore/each'], undefined); | ||
assert.equal(plugin.configs['compatible-warn'].rules['you-dont-need-lodash-underscore/find-index'], 1); | ||
assert.equal(plugin.configs['compatible-warn'].rules['you-dont-need-lodash-underscore/last-index-of'], 1); | ||
assert.equal(plugin.configs.compatible.rules['you-dont-need-lodash-underscore/for-each'], 1); | ||
assert.equal(plugin.configs.compatible.rules['you-dont-need-lodash-underscore/is-nan'], 2); |
@@ -7,5 +7,7 @@ 'use strict'; | ||
assert.equal(Object.keys(allRules).length, 39, 'Don\'t miss a rule 😄'); | ||
assert.equal(Object.keys(allRules).length, 46, 'Don\'t miss a rule 😄'); | ||
const ruleTester = new RuleTester(); | ||
const ruleTester = new RuleTester({ | ||
parserOptions: { ecmaVersion: 2018, sourceType: "module" } | ||
}); | ||
@@ -22,2 +24,5 @@ // Only a couple of smoke tests because otherwise it would get very reduntant | ||
}] | ||
}, { | ||
code: "import concat from 'lodash/concat';", | ||
errors: ["Import from 'lodash/concat' detected. Consider using the native Array.prototype.concat()"] | ||
}); | ||
@@ -33,2 +38,5 @@ | ||
}] | ||
}, { | ||
code: "import keys from 'lodash/keys';", | ||
errors: ["Import from 'lodash/keys' detected. Consider using the native Object.keys()"] | ||
}); | ||
@@ -44,2 +52,5 @@ | ||
}] | ||
}, { | ||
code: "import forEach from 'lodash/forEach';", | ||
errors: ["Import from 'lodash/forEach' detected. Consider using the native Array.prototype.forEach()"] | ||
}); | ||
@@ -55,4 +66,35 @@ | ||
}] | ||
}, { | ||
code: `import isNaN from "lodash/isNaN";`, | ||
errors: ["Import from 'lodash/isNaN' detected. Consider using the native Number.isNaN()"] | ||
}); | ||
ruleTester.run('_.first', rules['first'], { | ||
valid: [ | ||
'[0, 1, 3][0]', | ||
'[0, 1, 3].slice(0, 2)' | ||
], | ||
invalid: [{ | ||
code: '_.first([0, 1, 3])', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
}, { | ||
code: '_.first([0, 1, 3], 2)', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
}] | ||
}); | ||
ruleTester.run('_.last', rules['last'], { | ||
valid: [ | ||
'var numbers = [0, 1, 3]; numbers[numbers.length - 1]', | ||
'[0, 1, 3].slice(-2)' | ||
], | ||
invalid: [{ | ||
code: '_.last([0, 1, 3])', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
}, { | ||
code: '_.last([0, 1, 3], 2)', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
}] | ||
}); | ||
ruleTester.run('_', rules.concat, { | ||
@@ -59,0 +101,0 @@ valid: [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56860
415
1555
5