eslint-plugin-react
Advanced tools
Comparing version 7.27.0 to 7.27.1
@@ -195,2 +195,5 @@ /** | ||
ObjectExpression(node) { | ||
if (!utils.isES5Component(node)) { | ||
return; | ||
} | ||
if (ignoreTranspilerName || !hasTranspilerName(node)) { | ||
@@ -197,0 +200,0 @@ // Search for the displayName declaration |
@@ -15,2 +15,16 @@ /** | ||
function getText(node) { | ||
const params = node.value.params.map((p) => p.name); | ||
if (node.type === 'Property') { | ||
return `: function(${params.join(', ')}) `; | ||
} | ||
if (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') { | ||
return `(${params.join(', ')}) `; | ||
} | ||
return null; | ||
} | ||
module.exports = { | ||
@@ -29,16 +43,2 @@ meta: { | ||
create: Components.detect((context, components, utils) => { | ||
function getText(node) { | ||
const params = node.value.params.map((p) => p.name); | ||
if (node.type === 'Property') { | ||
return `: function(${params.join(', ')}) `; | ||
} | ||
if (node.type === 'ClassProperty' || node.type === 'PropertyDefinition') { | ||
return `(${params.join(', ')}) `; | ||
} | ||
return null; | ||
} | ||
/** | ||
@@ -62,5 +62,40 @@ * @param {Array} properties list of component properties | ||
if (nodeType === 'ArrowFunctionExpression' && isLifecycleMethod) { | ||
const range = [node.key.range[1], node.value.body.range[0]]; | ||
const text = getText(node); | ||
const body = node.value.body; | ||
const isBlockBody = body.type === 'BlockStatement'; | ||
const sourceCode = context.getSourceCode(); | ||
let nextComment = []; | ||
let previousComment = []; | ||
let bodyRange; | ||
if (!isBlockBody) { | ||
const previousToken = sourceCode.getTokenBefore(body); | ||
if (sourceCode.getCommentsBefore) { | ||
// eslint >=4.x | ||
previousComment = sourceCode.getCommentsBefore(body); | ||
} else { | ||
// eslint 3.x | ||
const potentialComment = sourceCode.getTokenBefore(body, { includeComments: true }); | ||
previousComment = previousToken === potentialComment ? [] : [potentialComment]; | ||
} | ||
if (sourceCode.getCommentsAfter) { | ||
// eslint >=4.x | ||
nextComment = sourceCode.getCommentsAfter(body); | ||
} else { | ||
// eslint 3.x | ||
const potentialComment = sourceCode.getTokenAfter(body, { includeComments: true }); | ||
const nextToken = sourceCode.getTokenAfter(body); | ||
nextComment = nextToken === potentialComment ? [] : [potentialComment]; | ||
} | ||
bodyRange = [ | ||
(previousComment.length > 0 ? previousComment[0] : body).range[0], | ||
(nextComment.length > 0 ? nextComment[nextComment.length - 1] : body).range[1], | ||
]; | ||
} | ||
const headRange = [ | ||
node.key.range[1], | ||
(previousComment.length > 0 ? previousComment[0] : body).range[0], | ||
]; | ||
context.report({ | ||
@@ -72,3 +107,15 @@ node, | ||
}, | ||
fix: (fixer) => fixer.replaceTextRange(range, text), | ||
fix(fixer) { | ||
if (!sourceCode.getCommentsAfter) { | ||
// eslint 3.x | ||
return isBlockBody && fixer.replaceTextRange(headRange, getText(node)); | ||
} | ||
return [].concat( | ||
fixer.replaceTextRange(headRange, getText(node)), | ||
isBlockBody ? [] : fixer.replaceTextRange( | ||
bodyRange, | ||
`{ return ${previousComment.map((x) => sourceCode.getText(x)).join('')}${sourceCode.getText(body)}${nextComment.map((x) => sourceCode.getText(x)).join('')}; }` | ||
) | ||
); | ||
}, | ||
}); | ||
@@ -75,0 +122,0 @@ } |
@@ -18,2 +18,3 @@ /** | ||
['alternate', new Set(['link', 'area', 'a'])], | ||
['apple-touch-icon', new Set(['link'])], | ||
['author', new Set(['link', 'area', 'a'])], | ||
@@ -28,2 +29,3 @@ ['bookmark', new Set(['area', 'a'])], | ||
['manifest', new Set(['link'])], | ||
['mask-icon', new Set(['link'])], | ||
['modulepreload', new Set(['link'])], | ||
@@ -30,0 +32,0 @@ ['next', new Set(['link', 'area', 'a', 'form'])], |
@@ -24,2 +24,3 @@ /** | ||
'componentWillUpdate', | ||
'getChildContext', | ||
'getSnapshotBeforeUpdate', | ||
@@ -26,0 +27,0 @@ 'render', |
@@ -398,3 +398,3 @@ /** | ||
} else if (properties[k].value.type === 'Identifier') { | ||
propVariables.set(propName, parentNames.concat(propName)); | ||
propVariables.set(properties[k].value.name, parentNames.concat(propName)); | ||
} | ||
@@ -401,0 +401,0 @@ } |
{ | ||
"name": "eslint-plugin-react", | ||
"version": "7.27.0", | ||
"version": "7.27.1", | ||
"author": "Yannick Croissant <yannick.croissant+npm@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React specific linting rules for ESLint", |
@@ -71,3 +71,3 @@ `eslint-plugin-react` | ||
{"name": "Form", "formAttribute": "endpoint"} | ||
] | ||
], | ||
"linkComponents": [ | ||
@@ -74,0 +74,0 @@ // Components used as alternatives to <a> for linking, eg. <Link to={ url } /> |
Sorry, the diff of this file is too big to display
867935
18809