eslint-plugin-you-dont-need-lodash-underscore
Advanced tools
Comparing version 6.12.0 to 6.13.0
@@ -0,0 +0,0 @@ ## Configuring the ESLint Plugin |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const forbiddenLibs = ['lodash', 'lodash-es']; | ||
const forbiddenLibs = ['lodash', 'lodash/fp', 'lodash-es']; | ||
@@ -25,3 +25,9 @@ function getAssignmentLeftHandSide(node) { | ||
const ruleName = rules[rule].ruleName || kebabCase(rule); | ||
const forbiddenImports = { [`lodash/${rule}`]: 1, [`lodash-es/${rule}`]: 1, [`lodash.${rule.toLowerCase()}`]: 1 }; | ||
const forbiddenImports = { | ||
[`lodash/${rule}`]: 1, | ||
[`lodash/fp/${rule}`]: 1, | ||
[`lodash-es/${rule}`]: 1, | ||
[`lodash.${rule.toLowerCase()}`]: 1, | ||
}; | ||
module.exports[ruleName] = { | ||
@@ -28,0 +34,0 @@ create(context) { |
@@ -24,3 +24,4 @@ { | ||
"compatible": true, | ||
"alternative": "Array.prototype.slice()" | ||
"alternative": "Array.prototype.at(-1) or Array.prototype.slice()", | ||
"ES13": true | ||
}, | ||
@@ -52,3 +53,4 @@ "lastIndexOf": { | ||
"compatible": true, | ||
"alternative": "Array.prototype.slice()" | ||
"alternative": "Array.prototype.at(0) or Array.prototype.slice()", | ||
"ES13": true | ||
}, | ||
@@ -286,3 +288,3 @@ "findIndex": { | ||
"compatible": true, | ||
"alternative": "str && typeof str.valueOf() === \"string\"" | ||
"alternative": "str != null && typeof str.valueOf() === \"string\"" | ||
}, | ||
@@ -296,3 +298,30 @@ "castArray": { | ||
"alternative": "typeof func === \"function\"" | ||
}, | ||
"unionBy": { | ||
"compatible": false, | ||
"alternative": "Example of native implementation: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_unionBy", | ||
"ES10": true | ||
}, | ||
"capitalize": { | ||
"compatible": true, | ||
"alternative": "string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()" | ||
}, | ||
"isDate": { | ||
"compatible": true, | ||
"alternative": "String.prototype.toString.call()" | ||
}, | ||
"defaults": { | ||
"compatible": true, | ||
"alternative": "Object.assign({}, defaultValues, newValues)", | ||
"ES6": true | ||
}, | ||
"isArrayBuffer": { | ||
"compatible": false, | ||
"alternative": "value instanceof ArrayBuffer" | ||
}, | ||
"head": { | ||
"compatible": true, | ||
"alternative": "Array.prototype.at(0)", | ||
"ES13": true | ||
} | ||
} |
{ | ||
"name": "eslint-plugin-you-dont-need-lodash-underscore", | ||
"version": "6.12.0", | ||
"version": "6.13.0", | ||
"description": "Check methods you can use natively without lodash/underscore", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -0,0 +0,0 @@ ## Quick Links |
@@ -0,0 +0,0 @@ require('./lib/rules/all.js'); |
@@ -107,2 +107,3 @@ 'use strict'; | ||
'[0, 1, 3][0]', | ||
'[0, 1, 3].at(0)', | ||
'[0, 1, 3].slice(0, 2)' | ||
@@ -112,6 +113,6 @@ ], | ||
code: '_.first([0, 1, 3])', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
errors: ['Consider using the native Array.prototype.at(0) or Array.prototype.slice()'] | ||
}, { | ||
code: '_.first([0, 1, 3], 2)', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
errors: ['Consider using the native Array.prototype.at(0) or Array.prototype.slice()'] | ||
}] | ||
@@ -123,2 +124,3 @@ }); | ||
'var numbers = [0, 1, 3]; numbers[numbers.length - 1]', | ||
'[0, 1, 3].at(-1)', | ||
'[0, 1, 3].slice(-2)' | ||
@@ -128,6 +130,6 @@ ], | ||
code: '_.last([0, 1, 3])', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
errors: ['Consider using the native Array.prototype.at(-1) or Array.prototype.slice()'] | ||
}, { | ||
code: '_.last([0, 1, 3], 2)', | ||
errors: ['Consider using the native Array.prototype.slice()'] | ||
errors: ['Consider using the native Array.prototype.at(-1) or Array.prototype.slice()'] | ||
}] | ||
@@ -232,1 +234,11 @@ }); | ||
ruleTester.run('_.head', rules['head'], { | ||
valid: [ | ||
'[0, 1, 3].at(0)', | ||
], | ||
invalid: [{ | ||
code: '_.head([0, 1, 3])', | ||
errors: ['Consider using the native Array.prototype.at(0)'] | ||
}] | ||
}); | ||
@@ -179,2 +179,25 @@ 'use strict'; | ||
}) | ||
describe('isDate', () => { | ||
const isDate = (obj) => { | ||
return (obj ? Object.prototype.toString.call(obj) === "[object Date]" : false); | ||
}; | ||
it ('_.Date(null)', () => { | ||
assert.equal( | ||
_.isDate(null), | ||
isDate(null) | ||
) | ||
}) | ||
it ("_.Date('Mon April 23 2012')", () => { | ||
assert.equal( | ||
_.isDate('Mon April 23 2012'), | ||
isDate('Mon April 23 2012') | ||
) | ||
}) | ||
it ('_.Date(new Date)', () => { | ||
assert.equal( | ||
_.isDate(new Date), | ||
isDate(new Date) | ||
) | ||
}) | ||
}) | ||
describe('isEmpty', () => { | ||
@@ -664,3 +687,3 @@ const isEmpty = (obj) => { | ||
function isString(str) { | ||
if (str && typeof str.valueOf() === "string") { | ||
if (str != null && typeof str.valueOf() === "string") { | ||
return true | ||
@@ -671,3 +694,3 @@ } | ||
it('_.isString(abc)', () => { | ||
it('_.isString("abc")', () => { | ||
assert.deepEqual(_.isString("abc"), | ||
@@ -682,6 +705,37 @@ isString("abc")) | ||
it('_.isString("")', () => { | ||
assert.deepEqual(_.isString(''), | ||
isString('')) | ||
}) | ||
}); | ||
describe('lowerFirst', () => { | ||
const lowerFirst = (string) => { | ||
return string ? string.charAt(0).toLowerCase() + string.slice(1) : '' | ||
} | ||
it('_.lowerFirst("Fred")', () => { | ||
assert.equal( | ||
_.lowerFirst('fred'), | ||
lowerFirst('fred') | ||
) | ||
}) | ||
it('_.lowerFirst(null)', () => { | ||
assert.equal( | ||
_.lowerFirst(null), | ||
lowerFirst(null) | ||
) | ||
}) | ||
it('_.lowerFirst("")', () => { | ||
assert.equal( | ||
_.lowerFirst(''), | ||
lowerFirst('') | ||
) | ||
}) | ||
}) | ||
describe('isUndefined', () => { | ||
@@ -856,2 +910,96 @@ const definedVariable = 1; //defined variable (will return false) | ||
}); | ||
describe('unionBy', () => { | ||
function unionBy(...arrays) { | ||
const iteratee = (arrays).pop(); | ||
if (Array.isArray(iteratee)) { | ||
return []; // return empty if iteratee is missing | ||
} | ||
return [...arrays].flat().filter( | ||
(set => (o) => set.has(iteratee(o)) ? false : set.add(iteratee(o)))(new Set()), | ||
); | ||
}; | ||
it('should take an iteratee function', () => { | ||
assert.deepStrictEqual(_.unionBy([2.1], [1.2, 2.3], Math.floor), unionBy([2.1], [1.2, 2.3], Math.floor)); | ||
}); | ||
it('should output values from the first possible array', () => { | ||
assert.deepStrictEqual(_.unionBy([{ x: 1, y: 1 }], [{ x: 1, y: 2 }], (x) => x.x), | ||
unionBy([{ x: 1, y: 1 }], [{ x: 1, y: 2 }], (x) => x.x)); | ||
}); | ||
}); | ||
describe('capitalize', () => { | ||
function capitalize(string) { | ||
return string ? string.charAt(0).toUpperCase() + string.slice(1).toLowerCase() : ''; | ||
} | ||
it('_.capitalize("FRED")', () => { | ||
assert.deepStrictEqual(_.capitalize("FRED"), capitalize("FRED")); | ||
}); | ||
it('_.capitalize("fred")', () => { | ||
assert.deepStrictEqual(_.capitalize("fred"), capitalize("fred")); | ||
}); | ||
it('_.capitalize("HELLO WORLD")', () => { | ||
assert.deepStrictEqual(_.capitalize("HELLO WORLD"), capitalize("HELLO WORLD")); | ||
}); | ||
it('_.capitalize("hello world")', () => { | ||
assert.deepStrictEqual(_.capitalize("hello world"), capitalize("hello world")); | ||
}); | ||
}); | ||
describe('defaults', () => { | ||
it('sets up default values the same way', () => { | ||
const defaultValues = { a: 1, b: 2, c: 3 }; | ||
const givenValues = { b: 4 }; | ||
const lodashObject = _.defaults(givenValues, defaultValues); | ||
const vanillaObject = Object.assign({}, defaultValues, givenValues); | ||
assert.deepStrictEqual(vanillaObject, { a: 1, b: 4, c: 3}); | ||
assert.deepStrictEqual(vanillaObject, lodashObject); | ||
}); | ||
it('should handle nested values equally', () => { | ||
const defaultValues = { a: 1, b: 2, c: { x: 3, y: 4 } }; | ||
const givenValues = { c: { x: 5 } }; | ||
const lodashObject = _.defaults(givenValues, defaultValues); | ||
const vanillaObject = Object.assign({}, defaultValues, givenValues); | ||
assert.deepStrictEqual(vanillaObject, { a: 1, b: 2, c: { x: 5 } }) | ||
assert.deepStrictEqual(vanillaObject, lodashObject); | ||
}); | ||
}); | ||
describe('last', () => { | ||
it('_.last([1,2,3,4,5])', () => { | ||
assert.deepEqual(_.last([1,2,3,4,5]), [1,2,3,4,5].at(-1)); | ||
}); | ||
it('_.last([])', () => { | ||
assert.deepEqual(_.last([]), [].at(-1)); | ||
}); | ||
}); | ||
describe('first', () => { | ||
it('_.first([1,2,3,4,5])', () => { | ||
assert.deepEqual(_.first([1,2,3,4,5]), [1,2,3,4,5].at(0)); | ||
}); | ||
it('_.first([])', () => { | ||
assert.deepEqual(_.first([]), [].at(0)); | ||
}); | ||
}) | ||
describe('head', () => { | ||
it('_.head([1,2,3,4,5])', () => { | ||
assert.deepEqual(_.head([1,2,3,4,5]), [1,2,3,4,5].at(0)); | ||
}); | ||
it('_.head([])', () => { | ||
assert.deepEqual(_.head([]), [].at(0)); | ||
}); | ||
}) | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
158508
22
1566
3360