Socket
Socket
Sign inDemoInstall

eslint-plugin-you-dont-need-lodash-underscore

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-you-dont-need-lodash-underscore - npm Package Compare versions

Comparing version 6.4.0 to 6.5.0

LICENSE

2

configuring.md

@@ -45,3 +45,3 @@ ## Configuring the ESLint Plugin

```js
"extends" : ["plugin:you-dont-need-lodash-underscore/compatible-error"],
"extends" : ["plugin:you-dont-need-lodash-underscore/compatible"],
```

@@ -48,0 +48,0 @@

@@ -8,2 +8,3 @@ 'use strict';

const ruleName = rules[rule].ruleName || kebabCase(rule);
const forbiddenImports = [`lodash/${rule}`, `lodash.${rule}`.toLowerCase()];
module.exports[ruleName] = {

@@ -24,6 +25,6 @@ create (context) {

ImportDeclaration(node) {
if (node.source.value === `lodash/${rule}`) {
if (forbiddenImports.indexOf(node.source.value) !== -1) {
context.report({
node,
message: `Import from 'lodash/${rule}' detected. Consider using the native ${alternative}`
message: `Import from '${node.source.value}' detected. Consider using the native ${alternative}`
});

@@ -30,0 +31,0 @@ }

@@ -6,2 +6,6 @@ {

},
"drop": {
"compatible": true,
"alternative": "Array.prototype.slice()"
},
"indexOf": {

@@ -134,2 +138,6 @@ "compatible": true,

},
"takeRight": {
"compatible": false,
"alternative": "Array.prototype.slice()"
},

@@ -141,3 +149,6 @@ "bind": {

},
"isFinite": {
"compatible": true,
"alternative": "Number.isFinite()"
},
"isNaN": {

@@ -149,2 +160,12 @@ "ruleName": "is-nan",

},
"isNull": {
"ruleName": "is-null",
"compatible": true,
"alternative": "value === null"
},
"isUndefined": {
"ruleName": "is-undefined",
"compatible": true,
"alternative": "value === undefined"
},

@@ -185,3 +206,10 @@ "keys": {

},
"split": {
"compatible": true,
"alternative": "String.prototype.split()"
},
"startsWith": {
"compatible": true,
"alternative": "String.prototype.startsWith()"
},
"toLower": {

@@ -212,3 +240,8 @@ "compatible": true,

"alternative": "String.prototype.replace()"
},
"omit": {
"compatible": true,
"alternative": "{a, b, c, ...notOmittedValues}",
"ES6": true
}
}
{
"name": "eslint-plugin-you-dont-need-lodash-underscore",
"version": "6.4.0",
"version": "6.5.0",
"description": "Check methods you can use natively without lodash/underscore",

@@ -5,0 +5,0 @@ "repository": {

@@ -7,3 +7,3 @@ 'use strict';

assert.equal(Object.keys(allRules).length, 46, 'Don\'t miss a rule 😄');
assert.equal(Object.keys(allRules).length, 54, 'Don\'t miss a rule 😄');

@@ -23,6 +23,9 @@ const ruleTester = new RuleTester({

errors: ['Consider using the native Array.prototype.concat()']
}, {
code: "import concat from 'lodash/concat';",
errors: ["Import from 'lodash/concat' detected. Consider using the native Array.prototype.concat()"]
}, {
code: "import concat from 'lodash.concat';",
errors: ["Import from 'lodash.concat' detected. Consider using the native Array.prototype.concat()"]
}]
}, {
code: "import concat from 'lodash/concat';",
errors: ["Import from 'lodash/concat' detected. Consider using the native Array.prototype.concat()"]
});

@@ -37,6 +40,9 @@

errors: ['Consider using the native Object.keys()']
}, {
code: "import concat from 'lodash/keys';",
errors: ["Import from 'lodash/keys' detected. Consider using the native Object.keys()"]
}, {
code: "import concat from 'lodash.keys';",
errors: ["Import from 'lodash.keys' detected. Consider using the native Object.keys()"]
}]
}, {
code: "import keys from 'lodash/keys';",
errors: ["Import from 'lodash/keys' detected. Consider using the native Object.keys()"]
});

@@ -51,6 +57,9 @@

errors: ['Consider using the native Array.prototype.forEach()']
}, {
code: "import concat from 'lodash/forEach';",
errors: ["Import from 'lodash/forEach' detected. Consider using the native Array.prototype.forEach()"]
}, {
code: "import concat from 'lodash.foreach';",
errors: ["Import from 'lodash.foreach' detected. Consider using the native Array.prototype.forEach()"]
}]
}, {
code: "import forEach from 'lodash/forEach';",
errors: ["Import from 'lodash/forEach' detected. Consider using the native Array.prototype.forEach()"]
});

@@ -65,6 +74,9 @@

errors: ['Consider using the native Number.isNaN()']
}, {
code: "import concat from 'lodash/isNaN';",
errors: ["Import from 'lodash/isNaN' detected. Consider using the native Number.isNaN()"]
}, {
code: "import concat from 'lodash.isnan';",
errors: ["Import from 'lodash.isnan' detected. Consider using the native Number.isNaN()"]
}]
}, {
code: `import isNaN from "lodash/isNaN";`,
errors: ["Import from 'lodash/isNaN' detected. Consider using the native Number.isNaN()"]
});

@@ -71,0 +83,0 @@

@@ -24,2 +24,36 @@ 'use strict';

it('pick', () => {
var object = { 'a': 1, 'b': '2', 'c': 3 };
function pick(object, paths) {
const obj = {};
for (const path of paths) {
if (object[path]) {
obj[path] = object[path]
}
}
return obj;
}
assert.deepEqual(
_.pick(object, ['a', 'c']),
pick(object, ['a', 'c'])
)
})
it('pickBy', () => {
var object = { 'a': 1, 'b': null, 'c': 3, 'd': false, 'e': undefined };
function pickBy(object) {
const obj = {};
for (const key in object) {
if (object[key] !== null && object[key] !== false && object[key] !== undefined) {
obj[key] = object[key];
}
}
return obj;
}
assert.deepEqual(
_.pickBy(object),
pickBy(object)
)
})
describe('fill', () => {

@@ -47,2 +81,250 @@ it("_.fill(array, 'a')", () => {

})
})
describe('chunk', () => {
const chunk = (input, size) => {
return input.reduce((arr, item, idx) => {
return idx % size === 0
? [...arr, [item]]
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
}, []);
};
it("_.chunk(['a', 'b', 'c', 'd'], 2);", () => {
assert.deepEqual(
_.chunk(['a', 'b', 'c', 'd'], 2),
chunk(['a', 'b', 'c', 'd'], 2)
)
})
it("_.chunk(['a', 'b', 'c', 'd'], 3);", () => {
assert.deepEqual(
_.chunk(['a', 'b', 'c', 'd'], 3),
chunk(['a', 'b', 'c', 'd'], 3)
)
})
})
describe('times', () => {
const times = (n, fn = (_, x) => x) => {
return Array.from(Array(n), fn)
};
it("_.times(10);", () => {
assert.deepEqual(
_.times(10),
times(10)
)
})
it("_.times(10, x => x + 1);", () => {
assert.deepEqual(
_.times(10, x => x + 1),
times(10, (_, x) => x + 1)
)
})
})
describe('assign', () => {
function Foo() {
this.c = 3;
}
function Bar() {
this.e = 5;
}
Foo.prototype.d = 4;
Bar.prototype.f = 6;
const assign = (target, ...sources) => Object.assign(target, ...sources);
it("_.assign({}, new Foo, new Bar);", () => {
assert.deepEqual(
_.assign({}, new Foo, new Bar),
assign({}, new Foo, new Bar)
)
})
it("_.assign(new Foo, new Bar);", () => {
assert.deepEqual(
_.assign(new Foo, new Bar),
assign(new Foo, new Bar)
)
})
})
describe('extend', () => {
function Foo() {
this.c = 3;
}
function Bar() {
this.e = 5;
}
Foo.prototype.d = 4;
Bar.prototype.f = 6;
const extend = (target, ...sources) => {
let source = [];
sources.forEach(src => {
source = source.concat([src, Object.getPrototypeOf(src)])
})
return Object.assign(target, ...source)
};
it("_.extend({}, new Foo, new Bar);", () => {
assert.deepEqual(
_.extend({}, new Foo, new Bar),
extend({}, new Foo, new Bar)
)
})
it("_.extend(new Foo, new Bar);", () => {
assert.deepEqual(
_.extend(new Foo, new Bar),
extend(new Foo, new Bar)
)
})
})
describe('isEmpty', () => {
const isEmpty = (obj) => {
return (obj ? [Object, Array].includes(obj.constructor) && !Object.entries(obj).length : true);
};
it ('_.isEmpty(null)', () => {
assert.equal(
_.isEmpty(null),
isEmpty(null)
)
})
it ("_.isEmpty('')", () => {
assert.equal(
_.isEmpty(''),
isEmpty('')
)
})
it ("_.isEmpty({})", () => {
assert.equal(
_.isEmpty({}),
isEmpty({})
)
})
it ("_.isEmpty([])", () => {
assert.equal(
_.isEmpty([]),
isEmpty([])
)
})
it ("_.isEmpty({a: '1'})", () => {
assert.equal(
_.isEmpty({a: '1'}),
isEmpty({a: '1'})
)
})
})
describe('get', () => {
// add array notation
const get = (obj, path, defaultValue = null) =>
String.prototype.split.call(path, /[,[\].]+?/)
.filter(Boolean)
.reduce((a, c) => (Object.hasOwnProperty.call(a,c) ? a[c] : defaultValue), obj)
var obj = { aa: [{ b: { c: 0 }, 1: 0 }], dd: { ee: { ff: 2 } } };
it ("should handle falsey values", () => {
var val = _.get(obj, 'aa[0].b.c', 1)
assert.equal(val, get(obj, 'aa[0].b.c', 1))
assert.notEqual(val, 1)
})
it ("should handle just bracket notation", () => {
var val = _.get(obj, 'aa[0][1]', 1)
assert.equal(val, get(obj, 'aa[0][1]', 1))
assert.notEqual(val, 1)
})
it ("should handle just period notation", () => {
var val = _.get(obj, 'dd.ee.ff', 1)
assert.equal(val, get(obj, 'dd.ee.ff', 1))
assert.notEqual(val, 1)
})
it ("should handle neither notation", () => {
var val = _.get(obj, 'aa', 1)
assert.deepEqual(val, get(obj, 'aa', 1))
assert.notEqual(val, 1)
})
it ("should handle both notation", () => {
var val = _.get(obj, 'aa[0].b.c', 1)
assert.equal(val, get(obj, 'aa[0].b.c', 1))
assert.notEqual(val, 1)
})
it ("should handle array path", () => {
var val = _.get(obj, ['aa', [0], 'b', 'c'], 1)
assert.equal(val, get(obj, ['aa', [0], 'b', 'c'], 1))
assert.notEqual(val, 1)
})
})
describe('split', () => {
const source = 'a-b-c';
const separator = '-';
const limit = 2;
it(`_.split("${source}", "${separator}")`, () => {
assert.equal(
_.split(source, separator),
source.split(separator)
);
})
it(`_.split("${source}", "${separator}", ${limit})`, () => {
assert.equal(
_.split(source, separator, limit),
source.split(separator, limit)
);
})
})
describe('inRange', () => {
const inRange = (num, init, final) => {
if(final === undefined){
final = init;
init = 0;
}
return (num >= Math.min(init, final) && num < Math.max(init, final));
}
it('_.inRange(3, 2, 4)', () => {
assert.equal(
_.inRange(3, 2, 4),
inRange(3, 2, 4)
)
});
it('_.inRange(4, 8)', () => {
assert.equal(
_.inRange(4, 8),
inRange(4, 8)
)
});
it('_.inRange(4, 2)', () => {
assert.equal(
_.inRange(4, 2),
inRange(4, 2)
)
});
it('_.inRange(2, 2)', () => {
assert.equal(
_.inRange(2, 2),
inRange(2, 2)
)
});
it('_.inRange(1.2, 2)', () => {
assert.equal(
_.inRange(1.2, 2),
inRange(1.2, 2)
)
});
it('_.inRange(5.2, 4)', () => {
assert.equal(
_.inRange(5.2, 4),
inRange(5.2, 4)
)
});
it('_.inRange(-3, -2, -6)', () => {
assert.equal(
_.inRange(-3, -2, -6),
inRange(-3, -2, -6)
)
});
it('_.inRange(1, 1, 5)', () => {
assert.equal(
_.inRange(1, 1, 5),
inRange(1, 1, 5)
)
});
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc