@bem-react/eslint-plugin
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -6,2 +6,6 @@ # Change Log | ||
## [1.1.2](https://github.com/bem/bem-react/compare/@bem-react/eslint-plugin@1.1.1...@bem-react/eslint-plugin@1.1.2) (2020-03-12) | ||
**Note:** Version bump only for package @bem-react/eslint-plugin | ||
## [1.1.1](https://github.com/bem/bem-react/compare/@bem-react/eslint-plugin@1.1.0...@bem-react/eslint-plugin@1.1.1) (2019-10-20) | ||
@@ -8,0 +12,0 @@ |
@@ -13,2 +13,11 @@ 'use strict' | ||
create: function(context) { | ||
function canOptimizeAllArguments(args) { | ||
// eslint-disable-next-line no-use-before-define | ||
return [].concat(args).every(canOptimize) | ||
} | ||
function isOptimizableCallExpression(node) { | ||
return node.type === 'CallExpression' && canOptimizeAllArguments(node.arguments) | ||
} | ||
function canOptimize(arg) { | ||
@@ -24,13 +33,15 @@ if (!arg) return false | ||
if ( | ||
arg.object.type === 'ThisExpression' && | ||
(arg.property.name === 'props' || arg.property.name === 'state') | ||
) | ||
arg.object.type === 'ThisExpression' | ||
&& (arg.property.name === 'props' || arg.property.name === 'state') | ||
) { | ||
return false | ||
} | ||
// Exception for props.x or state.x (case for destructuring) | ||
if ( | ||
arg.object.type === 'Identifier' && | ||
(arg.object.name === 'props' || arg.object.name === 'state') | ||
) | ||
arg.object.type === 'Identifier' | ||
&& (arg.object.name === 'props' || arg.object.name === 'state') | ||
) { | ||
return false | ||
} | ||
@@ -54,16 +65,8 @@ return canOptimize(arg.object) && canOptimize(arg.property) | ||
function canOptimizeAllArguments(args) { | ||
return [].concat(args).every(canOptimize) | ||
} | ||
function isOptimizableCallExpression(node) { | ||
return node.type === 'CallExpression' && canOptimizeAllArguments(node.arguments) | ||
} | ||
return { | ||
JSXAttribute: function(node) { | ||
const isEvaluatedClassName = | ||
node.name.type === 'JSXIdentifier' && | ||
node.name.name === 'className' && | ||
node.value.type === 'JSXExpressionContainer' | ||
const isEvaluatedClassName | ||
= node.name.type === 'JSXIdentifier' | ||
&& node.name.name === 'className' | ||
&& node.value.type === 'JSXExpressionContainer' | ||
@@ -75,11 +78,11 @@ if (!isEvaluatedClassName) return | ||
// className={cn('x')} | ||
isOptimizableCallExpression(expression) || | ||
isOptimizableCallExpression(expression) | ||
// className={isA ? cn('A') : cn('B')} | ||
(expression.type === 'ConditionalExpression' && | ||
(isOptimizableCallExpression(expression.consequent) || | ||
isOptimizableCallExpression(expression.alternate))) || | ||
|| (expression.type === 'ConditionalExpression' | ||
&& (isOptimizableCallExpression(expression.consequent) | ||
|| isOptimizableCallExpression(expression.alternate))) | ||
// className={isA && cn('A') || cn('B')} || className={isA ? cn('A') : cn('B')} || | ||
((expression.type === 'BinaryExpression' || expression.type === 'LogicalExpression') && | ||
(isOptimizableCallExpression(expression.left) || | ||
isOptimizableCallExpression(expression.right))) | ||
|| ((expression.type === 'BinaryExpression' || expression.type === 'LogicalExpression') | ||
&& (isOptimizableCallExpression(expression.left) | ||
|| isOptimizableCallExpression(expression.right))) | ||
) { | ||
@@ -86,0 +89,0 @@ context.report({ |
@@ -49,25 +49,2 @@ 'use strict' | ||
if (shouldIgnoreFile(filepath)) { | ||
return {} | ||
} | ||
const fileLevel = getLevelFromFilename(filepath) || defaultLevel | ||
const allowedLevels = whiteList[fileLevel] || [] | ||
return { | ||
ImportDeclaration: function(node) { | ||
const importPath = node.source.value | ||
const importLevel = getLevelFromFilename(importPath) | ||
if (importLevel && !allowedLevels.includes(importLevel)) { | ||
context.report({ | ||
node: node, | ||
message: | ||
"Imports from '{{ importLevel }}' level in files from '{{ fileLevel }}' level are forbidden", | ||
data: { importLevel, fileLevel }, | ||
}) | ||
} | ||
}, | ||
} | ||
/** | ||
@@ -104,3 +81,26 @@ * @param {String} filepath | ||
} | ||
if (shouldIgnoreFile(filepath)) { | ||
return {} | ||
} | ||
const fileLevel = getLevelFromFilename(filepath) || defaultLevel | ||
const allowedLevels = whiteList[fileLevel] || [] | ||
return { | ||
ImportDeclaration: function(node) { | ||
const importPath = node.source.value | ||
const importLevel = getLevelFromFilename(importPath) | ||
if (importLevel && !allowedLevels.includes(importLevel)) { | ||
context.report({ | ||
node: node, | ||
message: | ||
"Imports from '{{ importLevel }}' level in files from '{{ fileLevel }}' level are forbidden", | ||
data: { importLevel, fileLevel }, | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
{ | ||
"name": "@bem-react/eslint-plugin", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"publishConfig": { | ||
@@ -27,3 +27,3 @@ "access": "public" | ||
}, | ||
"gitHead": "b83ef616697787c3ea46ef6db7fe63b209c68fe5" | ||
"gitHead": "2d0812109bdb4f8d8d4d507e3585e51ddb556ed5" | ||
} |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
33756
11
333
3