Skip to content

Commit

Permalink
[Refactor]: remove deprecated context.report calls
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed May 23, 2019
1 parent a3c6d7e commit cf26613
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 49 deletions.
20 changes: 10 additions & 10 deletions lib/rules/default-props-match-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
});
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/jsx-no-comment-textnodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}

// --------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/jsx-no-target-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
}
};
Expand Down
22 changes: 11 additions & 11 deletions lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
});
}
});

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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`'
});
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`
});
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '[]')
}
);
});
});
}

Expand Down
20 changes: 10 additions & 10 deletions lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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}
});
});
}

Expand Down
6 changes: 5 additions & 1 deletion lib/rules/static-property-placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
});
}
}

Expand Down
15 changes: 12 additions & 3 deletions lib/rules/style-prop-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
}

Expand All @@ -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'
});
}
}
}
Expand All @@ -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);
}
Expand Down

0 comments on commit cf26613

Please sign in to comment.