From 2f6d82879cdcbe39b6db87cf2bdb739e5d663d2e Mon Sep 17 00:00:00 2001 From: golopot Date: Wed, 22 May 2019 05:44:32 +0800 Subject: [PATCH] [Refactor]: remove deprecated context.report calls --- lib/rules/default-props-match-prop-types.js | 20 +++++++++---------- lib/rules/jsx-no-comment-textnodes.js | 5 ++++- lib/rules/jsx-no-target-blank.js | 7 +++++-- lib/rules/no-access-state-in-setstate.js | 22 ++++++++++----------- lib/rules/no-danger-with-children.js | 10 ++++++++-- lib/rules/no-unused-prop-types.js | 9 +++++---- lib/rules/no-unused-state.js | 5 ++++- lib/rules/prop-types.js | 9 +++++---- lib/rules/require-default-props.js | 20 +++++++++---------- lib/rules/static-property-placement.js | 6 +++++- lib/rules/style-prop-object.js | 15 +++++++++++--- 11 files changed, 79 insertions(+), 49 deletions(-) diff --git a/lib/rules/default-props-match-prop-types.js b/lib/rules/default-props-match-prop-types.js index fca3c0fae6..19d47a0e65 100644 --- a/lib/rules/default-props-match-prop-types.js +++ b/lib/rules/default-props-match-prop-types.js @@ -60,17 +60,17 @@ module.exports = { } if (prop) { - context.report( - defaultProp.node, - 'defaultProp "{{name}}" defined for isRequired propType.', - {name: defaultPropName} - ); + context.report({ + node: defaultProp.node, + message: 'defaultProp "{{name}}" defined for isRequired propType.', + data: {name: defaultPropName} + }); } else { - context.report( - defaultProp.node, - 'defaultProp "{{name}}" has no corresponding propTypes declaration.', - {name: defaultPropName} - ); + context.report({ + node: defaultProp.node, + message: 'defaultProp "{{name}}" has no corresponding propTypes declaration.', + data: {name: defaultPropName} + }); } }); } diff --git a/lib/rules/jsx-no-comment-textnodes.js b/lib/rules/jsx-no-comment-textnodes.js index 8f7ddfb68e..e245d11fc0 100644 --- a/lib/rules/jsx-no-comment-textnodes.js +++ b/lib/rules/jsx-no-comment-textnodes.js @@ -29,7 +29,10 @@ module.exports = { create(context) { function reportLiteralNode(node) { - context.report(node, 'Comments inside children section of tag should be placed inside braces'); + context.report({ + node, + message: 'Comments inside children section of tag should be placed inside braces' + }); } // -------------------------------------------------------------------------- diff --git a/lib/rules/jsx-no-target-blank.js b/lib/rules/jsx-no-target-blank.js index 46c266ab85..be20eb788e 100644 --- a/lib/rules/jsx-no-target-blank.js +++ b/lib/rules/jsx-no-target-blank.js @@ -76,8 +76,11 @@ module.exports = { const linkAttribute = components.get(node.parent.name.name); if (hasExternalLink(node.parent, linkAttribute) || (enforceDynamicLinks === 'always' && hasDynamicLink(node.parent, linkAttribute))) { - context.report(node, 'Using target="_blank" without rel="noopener noreferrer" ' + - 'is a security risk: see https://mathiasbynens.github.io/rel-noopener'); + context.report({ + node, + message: 'Using target="_blank" without rel="noopener noreferrer" ' + + 'is a security risk: see https://mathiasbynens.github.io/rel-noopener' + }); } } }; diff --git a/lib/rules/no-access-state-in-setstate.js b/lib/rules/no-access-state-in-setstate.js index 068219c173..9a0af61d61 100644 --- a/lib/rules/no-access-state-in-setstate.js +++ b/lib/rules/no-access-state-in-setstate.js @@ -72,10 +72,10 @@ module.exports = { const methodName = node.callee.name; methods.forEach((method) => { if (method.methodName === methodName) { - context.report( - method.node, - 'Use callback in setState when referencing the previous state.' - ); + context.report({ + node: method.node, + message: 'Use callback in setState when referencing the previous state.' + }); } }); @@ -94,10 +94,10 @@ module.exports = { while (current.type !== 'Program') { // Reporting if this.state is directly within this.setState if (isFirstArgumentInSetStateCall(current, node)) { - context.report( + context.report({ node, - 'Use callback in setState when referencing the previous state.' - ); + message: 'Use callback in setState when referencing the previous state.' + }); break; } @@ -146,10 +146,10 @@ module.exports = { vars .filter(v => v.scope === context.getScope() && v.variableName === node.name) .forEach((v) => { - context.report( - v.node, - 'Use callback in setState when referencing the previous state.' - ); + context.report({ + node: v.node, + message: 'Use callback in setState when referencing the previous state.' + }); }); } current = current.parent; diff --git a/lib/rules/no-danger-with-children.js b/lib/rules/no-danger-with-children.js index 46ac070b27..5df28af07b 100644 --- a/lib/rules/no-danger-with-children.js +++ b/lib/rules/no-danger-with-children.js @@ -99,7 +99,10 @@ module.exports = { hasChildren && findJsxProp(node, 'dangerouslySetInnerHTML') ) { - context.report(node, 'Only set one of `children` or `props.dangerouslySetInnerHTML`'); + context.report({ + node, + message: 'Only set one of `children` or `props.dangerouslySetInnerHTML`' + }); } }, CallExpression(node) { @@ -131,7 +134,10 @@ module.exports = { } if (dangerously && hasChildren) { - context.report(node, 'Only set one of `children` or `props.dangerouslySetInnerHTML`'); + context.report({ + node, + message: 'Only set one of `children` or `props.dangerouslySetInnerHTML`' + }); } } } diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index 1f095a1cc7..f7d9074656 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -103,12 +103,13 @@ module.exports = { } if (prop.node && !isPropUsed(component, prop)) { - context.report( - prop.node.value || prop.node, - UNUSED_MESSAGE, { + context.report({ + node: prop.node.value || prop.node, + message: UNUSED_MESSAGE, + data: { name: prop.fullName } - ); + }); } if (prop.children) { diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index be0796e37f..fcdc749810 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -210,7 +210,10 @@ module.exports = { for (const node of classInfo.stateFields) { const name = getName(node.key); if (!classInfo.usedStateFields.has(name)) { - context.report(node, `Unused state field: '${name}'`); + context.report({ + node, + message: `Unused state field: '${name}'` + }); } } } diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 9131e0311c..13fe4ba095 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -168,12 +168,13 @@ module.exports = { !isDeclaredInComponent(component.node, propType.allNames) )); undeclareds.forEach((propType) => { - context.report( - propType.node, - MISSING_MESSAGE, { + context.report({ + node: propType.node, + message: MISSING_MESSAGE, + data: { name: propType.allNames.join('.').replace(/\.__COMPUTED_PROP__/g, '[]') } - ); + }); }); } diff --git a/lib/rules/require-default-props.js b/lib/rules/require-default-props.js index f128090822..12a1515439 100644 --- a/lib/rules/require-default-props.js +++ b/lib/rules/require-default-props.js @@ -54,11 +54,11 @@ module.exports = { const prop = propTypes[propName]; if (prop.isRequired) { if (forbidDefaultForRequired && defaultProps[propName]) { - context.report( - prop.node, - 'propType "{{name}}" is required and should not have a defaultProps declaration.', - {name: propName} - ); + context.report({ + node: prop.node, + message: 'propType "{{name}}" is required and should not have a defaultProps declaration.', + data: {name: propName} + }); } return; } @@ -67,11 +67,11 @@ module.exports = { return; } - context.report( - prop.node, - 'propType "{{name}}" is not required, but has no corresponding defaultProps declaration.', - {name: propName} - ); + context.report({ + node: prop.node, + message: 'propType "{{name}}" is not required, but has no corresponding defaultProps declaration.', + data: {name: propName} + }); }); } diff --git a/lib/rules/static-property-placement.js b/lib/rules/static-property-placement.js index e8d3046d5c..8e2a89a55a 100644 --- a/lib/rules/static-property-placement.js +++ b/lib/rules/static-property-placement.js @@ -119,7 +119,11 @@ module.exports = { // If name is set but the configured rule does not match expected then report error if (name && config[name] !== expectedRule) { // Report the error - context.report(node, ERROR_MESSAGES[config[name]], {name}); + context.report({ + node, + message: ERROR_MESSAGES[config[name]], + data: {name} + }); } } diff --git a/lib/rules/style-prop-object.js b/lib/rules/style-prop-object.js index d062359f80..33fc1a40ea 100644 --- a/lib/rules/style-prop-object.js +++ b/lib/rules/style-prop-object.js @@ -42,7 +42,10 @@ module.exports = { } if (isNonNullaryLiteral(variable.defs[0].node.init)) { - context.report(node, 'Style prop value must be an object'); + context.report({ + node, + message: 'Style prop value must be an object' + }); } } @@ -60,7 +63,10 @@ module.exports = { if (style.value.type === 'Identifier') { checkIdentifiers(style.value); } else if (isNonNullaryLiteral(style.value)) { - context.report(style.value, 'Style prop value must be an object'); + context.report({ + node: style.value, + message: 'Style prop value must be an object' + }); } } } @@ -73,7 +79,10 @@ module.exports = { } if (node.value.type !== 'JSXExpressionContainer' || isNonNullaryLiteral(node.value.expression)) { - context.report(node, 'Style prop value must be an object'); + context.report({ + node, + message: 'Style prop value must be an object' + }); } else if (node.value.expression.type === 'Identifier') { checkIdentifiers(node.value.expression); }