Skip to content

Commit

Permalink
drop requireindex and style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Jul 2, 2016
1 parent 16f13d9 commit 6f67d93
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
22 changes: 4 additions & 18 deletions index.js
@@ -1,19 +1,5 @@
/**
* @fileoverview Discourages the use of lodash / underscore when native methods for the same functions exist.
* @author Patrick McElhaney
*/
"use strict";
'use strict';

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var requireIndex = require("requireindex");

//------------------------------------------------------------------------------
// Plugin Definition
//------------------------------------------------------------------------------


// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + "/lib/rules");
module.exports.rules = {
all: require('./lib/rules/all')
}
9 changes: 4 additions & 5 deletions lib/rules/all.js
@@ -1,11 +1,13 @@
/**
* @fileoverview Discourages the use of Underscore/Lodash where native methods will do
* @fileoverview Check methods you can use natively without lodash/underscore
* @author Patrick McElhaney
*/
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

const errorMessages = {
concat: 'Consider using the native Array.prototype.concat()',
fill: 'Consider using the native ES6 Array.prototype.fill()',
Expand Down Expand Up @@ -35,7 +37,6 @@ const errorMessages = {
};

module.exports = {

create (context) {
function checkForUnneededLibraryFunctions (node) {
const functionName = getUnderscoreFunctionName(node);
Expand All @@ -52,11 +53,9 @@ module.exports = {
return {
'CallExpression': checkForUnneededLibraryFunctions,
};
},

}
};


function getUnderscoreFunctionName (node) {
const callee = node.callee;
return callee && callee.object && callee.object.name === '_' && callee.property && callee.property.name;
Expand Down
6 changes: 2 additions & 4 deletions package.json
Expand Up @@ -25,12 +25,10 @@
"test": "npm run unit-test",
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter dot"
},
"dependencies": {
"requireindex": "~1.1.0"
},
"dependencies": {},
"devDependencies": {
"coveralls": "^2.11.9",
"eslint": "^3.0",
"eslint": "^3.0.0",
"istanbul": "^0.4.4",
"mocha": "^2.5.3"
},
Expand Down
19 changes: 9 additions & 10 deletions tests/lib/rules/all.js
@@ -1,24 +1,24 @@
/**
* @fileoverview Discourages the use of Underscore/Lodash where native methods will do
* @fileoverview Check methods you can use natively without lodash/underscore
* @author Patrick McElhaney
*/
"use strict";
'use strict';

var rule = require("../../../lib/rules/all"),

RuleTester = require("eslint").RuleTester;
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/all');
const RuleTester = require('eslint').RuleTester;

// Only a couple of smoke tests because otherwise it would get very reduntant

var ruleTester = new RuleTester();
const ruleTester = new RuleTester();
ruleTester.run('no-lodash-underscore', rule, {

valid: [
'array.concat(2, [3], [[4]])',
'Object.keys({one: 1, two: 2, three: 3})'
],

invalid: [
{
code: '_.concat(array, 2, [3], [[4]])',
Expand All @@ -27,7 +27,6 @@ ruleTester.run('no-lodash-underscore', rule, {
{
code: '_.keys({one: 1, two: 2, three: 3})',
errors: ['Consider using the native Object.keys()']
},

}
]
});

0 comments on commit 6f67d93

Please sign in to comment.