-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change config to wix-editor/node and fix errors
- Loading branch information
Showing
77 changed files
with
914 additions
and
940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
}; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} | ||
]; | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
}; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} | ||
]; | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} | ||
]; | ||
] |
Oops, something went wrong.