Skip to content

Commit

Permalink
change config to wix-editor/node and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Mar 28, 2016
1 parent caba19b commit 8a5b2b3
Show file tree
Hide file tree
Showing 77 changed files with 914 additions and 940 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"env": {
"node": true
},
"extends": "wix-editor",
"extends": "wix-editor/node",
"rules": {
"strict": [2, "global"],
"no-extra-parens": 0,
Expand Down
18 changes: 7 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var rules = fs.readdirSync(path.resolve(__dirname, 'rules')).map(function (f) {
return f.replace(/\.js$/, '');
});
'use strict'
const fs = require('fs')
const path = require('path')
const _ = require('lodash')
const rules = fs.readdirSync(path.resolve(__dirname, 'rules')).map(f => f.replace(/\.js$/, ''))

module.exports = {
rules: _.zipObject(rules, rules.map(function (rule) {
return require('./rules/' + rule);
})),
rules: _.zipObject(rules, rules.map(rule => require(`./rules/${rule}`))),
configs: {
recommended: {
rules: {
Expand Down Expand Up @@ -89,4 +85,4 @@ module.exports = {
}
}
}
};
}
32 changes: 16 additions & 16 deletions src/rules/callback-binding.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
/**
* @fileoverview Rule to disallow the use of a chain for a single method
*/
'use strict';
'use strict'

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

module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
var settings = require('../util/settingsUtil').getSettings(context);
var transformerMethods = ['reduce', 'reduceRight', 'transform'];
const lodashUtil = require('../util/lodashUtil')
const astUtil = require('../util/astUtil')
const settings = require('../util/settingsUtil').getSettings(context)
const transformerMethods = ['reduce', 'reduceRight', 'transform']

function isBound(node) {
return node && node.type === 'CallExpression' && astUtil.getMethodName(node) === 'bind' && node.arguments.length === 1;
return node && node.type === 'CallExpression' && astUtil.getMethodName(node) === 'bind' && node.arguments.length === 1
}

var callExpressionReporters = {
3: function (node, iteratee) {
const callExpressionReporters = {
3(node, iteratee) {
if (isBound(iteratee)) {
context.report(iteratee.callee.property, 'Unnecessary bind, pass `thisArg` to lodash method instead');
context.report(iteratee.callee.property, 'Unnecessary bind, pass `thisArg` to lodash method instead')
}
},
4: function (node, iteratee) {
var isTransformerMethod = transformerMethods.some(lodashUtil.isCallToMethod.bind(null, node, settings.version));
var iterateeIndex = node.arguments.indexOf(iteratee);
4(node, iteratee) {
const isTransformerMethod = transformerMethods.some(lodashUtil.isCallToMethod.bind(null, node, settings.version))
const iterateeIndex = node.arguments.indexOf(iteratee)
if (iterateeIndex !== -1 && (isTransformerMethod && node.arguments[iterateeIndex + 2] || (!isTransformerMethod && node.arguments[iterateeIndex + 1]))) {
context.report(iteratee, 'Do not use Lodash 3 thisArg, use binding instead');
context.report(iteratee, 'Do not use Lodash 3 thisArg, use binding instead')
}
}
};
}

return {
CallExpression: lodashUtil.getLodashMethodVisitor(settings, callExpressionReporters[settings.version])
};
};
}
}
38 changes: 19 additions & 19 deletions src/rules/chain-style.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/**
* @fileoverview Rule to enforce a specific chain style
*/
'use strict';
'use strict'

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
var settings = require('../util/settingsUtil').getSettings(context);
var callExpressionVisitors = {
'as-needed': function (node) {
const lodashUtil = require('../util/lodashUtil')
const astUtil = require('../util/astUtil')
const settings = require('../util/settingsUtil').getSettings(context)
const callExpressionVisitors = {
'as-needed'(node) {
if (lodashUtil.isExplicitChainStart(node, settings.pragma)) {
var curr = node.parent.parent;
var needed = false;
let curr = node.parent.parent
let needed = false
while (astUtil.isMethodCall(curr) && !lodashUtil.isChainBreaker(curr, settings.version)) {
if (!lodashUtil.isChainable(curr, settings.version) && !lodashUtil.isChainBreaker(curr.parent.parent, settings.version)) {
needed = true;
needed = true
}
curr = curr.parent.parent;
curr = curr.parent.parent
}
if (astUtil.isMethodCall(curr) && !needed) {
context.report(node, 'Unnecessary explicit chaining');
context.report(node, 'Unnecessary explicit chaining')
}
}
},
implicit: function (node) {
implicit(node) {
if (lodashUtil.isExplicitChainStart(node, settings.pragma)) {
context.report(node, 'Do not use explicit chaining');
context.report(node, 'Do not use explicit chaining')
}
},
explicit: function (node) {
explicit(node) {
if (lodashUtil.isImplicitChainStart(node, settings.pragma)) {
context.report(node, 'Do not use implicit chaining');
context.report(node, 'Do not use implicit chaining')
}
}
};
}

return {
CallExpression: callExpressionVisitors[context.options[0] || 'as-needed']
};
};
}
}

module.exports.schema = [
{
enum: ['as-needed', 'implicit', 'explicit']
}
];
]
56 changes: 28 additions & 28 deletions src/rules/collection-return.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
/**
* @fileoverview Rule to check that iteratees for all collection functions except forEach return a value;
*/
'use strict';
'use strict'

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

module.exports = function (context) {
var _ = require('lodash');
var astUtil = require('../util/astUtil');
var lodashUtil = require('../util/lodashUtil');
var settings = require('../util/settingsUtil').getSettings(context);
var callStack = [];
const _ = require('lodash')
const astUtil = require('../util/astUtil')
const lodashUtil = require('../util/lodashUtil')
const settings = require('../util/settingsUtil').getSettings(context)
const callStack = []

function handleExitOfFunctionWithBlock(node) {
var functionNode = callStack.pop();
var last = _.last(callStack);
const functionNode = callStack.pop()
const last = _.last(callStack)
if (!functionNode.found && _.get(last, 'node.type') === 'CallExpression') {
context.report(node, 'Do not use _.' + astUtil.getMethodName(last.node) + ' without returning a value');
context.report(node, `Do not use _.${astUtil.getMethodName(last.node)} without returning a value`)
}
if (last && last.node === node.parent) {
callStack.pop();
callStack.pop()
}
}
function addToCallStackIfCollectionMethod(node) {
if (node.parent.type === 'CallExpression' && lodashUtil.isLodashCollectionMethod(node.parent, settings.pragma, settings.version)) {
callStack.push({node: node.parent});
callStack.push({node: node.parent})
}
}

return {
FunctionExpression: function (node) {
addToCallStackIfCollectionMethod(node);
callStack.push({node: node, found: false});
FunctionExpression(node) {
addToCallStackIfCollectionMethod(node)
callStack.push({node, found: false})
},
'FunctionExpression:exit': handleExitOfFunctionWithBlock,
ArrowFunctionExpression: function (node) {
addToCallStackIfCollectionMethod(node);
ArrowFunctionExpression(node) {
addToCallStackIfCollectionMethod(node)
if (node.body.type === 'BlockStatement') {
callStack.push({node: node, found: false});
callStack.push({node, found: false})
}
},
'ArrowFunctionExpression:exit': function (node) {
var last = _.last(callStack);
'ArrowFunctionExpression:exit'(node) {
const last = _.last(callStack)
if (last && last.node === node) {
handleExitOfFunctionWithBlock(node);
handleExitOfFunctionWithBlock(node)
}
},
ReturnStatement: function () {
var last = _.last(callStack);
ReturnStatement() {
const last = _.last(callStack)
if (last) {
last.found = true;
last.found = true
}
},
'CallExpression:exit': function (node) {
var last = _.last(callStack);
'CallExpression:exit'(node) {
const last = _.last(callStack)
if (last && last.node === node) {
callStack.pop();
callStack.pop()
}
}
};
};
}
}
32 changes: 16 additions & 16 deletions src/rules/identity-shorthand.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/**
* @fileoverview Rule to check if the identity shorthand can be used
*/
'use strict';
'use strict'

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


module.exports = function (context) {
var _ = require('lodash');
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
var settings = require('../util/settingsUtil').getSettings(context);
const _ = require('lodash')
const lodashUtil = require('../util/lodashUtil')
const astUtil = require('../util/astUtil')
const settings = require('../util/settingsUtil').getSettings(context)


function isExplicitIdentityFunction(iteratee) {
var firstParamName = astUtil.getFirstParamName(iteratee);
return firstParamName && _.get(astUtil.getValueReturnedInFirstLine(iteratee), 'name') === firstParamName;
const firstParamName = astUtil.getFirstParamName(iteratee)
return firstParamName && _.get(astUtil.getValueReturnedInFirstLine(iteratee), 'name') === firstParamName
}

var isLodashIdentityFunction = _.matches({
const isLodashIdentityFunction = _.matches({
type: 'MemberExpression',
object: {name: settings.pragma},
property: {name: 'identity'}
});
})

var canUseIdentityShorthand = _.overSome(isExplicitIdentityFunction, isLodashIdentityFunction);
const canUseShorthand = _.overSome(isExplicitIdentityFunction, isLodashIdentityFunction)

function usesShorthand(node, iteratee) {
return lodashUtil.methodSupportsShorthand(settings.version, node) && !iteratee;
return lodashUtil.methodSupportsShorthand(settings.version, node) && !iteratee
}

return {
CallExpression: lodashUtil.getShorthandVisitor(context, settings, {
canUseShorthand: canUseIdentityShorthand,
usesShorthand: usesShorthand
canUseShorthand,
usesShorthand
}, {
always: 'Prefer omitting the iteratee over a function that returns its argument',
never: 'Do not use the identity shorthand syntax'
})
};
};
}
}

module.exports.schema = [
{
enum: ['always', 'never']
}
];
]
34 changes: 17 additions & 17 deletions src/rules/matches-prop-shorthand.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/**
* @fileoverview Rule to check if the macthesProperty shorthand can be used
*/
'use strict';
'use strict'

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = function (context) {
var lodashUtil = require('../util/lodashUtil');
var astUtil = require('../util/astUtil');
var settings = require('../util/settingsUtil').getSettings(context);
const lodashUtil = require('../util/lodashUtil')
const astUtil = require('../util/astUtil')
const settings = require('../util/settingsUtil').getSettings(context)

function isFunctionDeclarationThatCanUseShorthand(func) {
return astUtil.isEqEqEqToMemberOf(astUtil.getValueReturnedInFirstLine(func), astUtil.getFirstParamName(func), Infinity);
return astUtil.isEqEqEqToMemberOf(astUtil.getValueReturnedInFirstLine(func), astUtil.getFirstParamName(func), Infinity)
}

function canUseShorthand(iteratee) {
return isFunctionDeclarationThatCanUseShorthand(iteratee) || lodashUtil.isLodashCallToMethod(iteratee, settings, 'matchesProperty');
return isFunctionDeclarationThatCanUseShorthand(iteratee) || lodashUtil.isLodashCallToMethod(iteratee, settings, 'matchesProperty')
}

function callHasExtraParamAfterIteratee(node, iteratee) {
return node.arguments[node.arguments.indexOf(iteratee) + 1];
return node.arguments[node.arguments.indexOf(iteratee) + 1]
}

var matchesPropertyChecks = {
3: function (node, iteratee) {
return iteratee && iteratee.type === 'Literal' && callHasExtraParamAfterIteratee(node, iteratee);
const matchesPropertyChecks = {
3(node, iteratee) {
return iteratee && iteratee.type === 'Literal' && callHasExtraParamAfterIteratee(node, iteratee)
},
4: function (node, iteratee) {
return iteratee && iteratee.type === 'ArrayExpression';
4(node, iteratee) {
return iteratee && iteratee.type === 'ArrayExpression'
}
};
}

return {
CallExpression: lodashUtil.getShorthandVisitor(context, settings, {
canUseShorthand: canUseShorthand,
canUseShorthand,
usesShorthand: matchesPropertyChecks[settings.version]
}, {
always: 'Prefer matches property syntax',
never: 'Do not use matches property syntax'
})
};
};
}
}

module.exports.schema = [
{
enum: ['always', 'never']
}
];
]
Loading

0 comments on commit 8a5b2b3

Please sign in to comment.