Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint-plugin] feat: only lint MenuItem with popoverProps attr #5495

Merged
merged 7 commits into from
Aug 11, 2022

Conversation

adidahiya
Copy link
Contributor

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

Improve @blueprintjs/no-deprecated-core-components & @blueprintjs/no-deprecated-components lint rule to understand components usage which is deprecated iff a specific prop is used. This is particularly useful for <MenuItem>, where we don't want to force consumers to unnecessarily migrate to <MenuItem2> in the overwhelming majority use case... we only need them to migrate when popoverProps is used. This will greatly reduce the code diff required in migrations.

Reviewers should focus on:

Implementation & test cases

@adidahiya adidahiya requested a review from styu August 10, 2022 20:11
@blueprint-bot
Copy link

[eslint-plugin] feat: only lint MenuItem with popoverProps attr

Previews: documentation | landing | table | demo

);
if (deprecatedProp !== undefined) {
const deprecatedComponentKey = Object.keys(deprecatedToNewComponentMapping).find(
key => key.split(".")[0] === node.name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is technically possible to have both MenuItem and MenuItem.popoverProps as keys, in which case this would return the wrong key, right?

Suggested change
key => key.split(".")[0] === node.name,
key => key.indexOf(".") >= 0 && key.split(".")[0] === node.name,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it would fail in that case. The rule doesn't gracefully handle bad configuration right now, but I figure it's ok to be a little simplistic here since the configuration is not exposed to consumers -- it only lives inside the rule implementation in this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it up a little to guard against the edge case you mentioned

Comment on lines 183 to 204
const deprecatedProp = node.parent.attributes.find(
attribute =>
attribute.type === TSESTree.AST_NODE_TYPES.JSXAttribute &&
attribute.name.type === TSESTree.AST_NODE_TYPES.JSXIdentifier &&
deprecatedToNewComponentMapping[`${node.property.name}.${attribute.name.name}`] != null,
);
if (deprecatedProp !== undefined) {
const deprecatedComponentKey = Object.keys(deprecatedToNewComponentMapping).find(
key => key.split(".")[0] === node.property.name,
);
context.report({
data: {
deprecatedComponentName: node.property.name,
deprecatedPropName: (
(deprecatedProp as TSESTree.JSXAttribute).name as TSESTree.JSXIdentifier
).name,
newComponentName: deprecatedToNewComponentMapping[deprecatedComponentKey!],
},
messageId: "migrationWithPropUsage",
node,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this code repeated, just for a different node type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a little different, it uses node.property.name instead of node.name. but yes it's very similar to the other block. I think it would be a little convoluted / unreadable if we tried to DRY this code between the two syntax handlers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought, I've refactored this bit into a function shared between the two handlers, it's still legible

@blueprint-bot
Copy link

DRY rule implementation based on CR feedback

Previews: documentation | landing | table | demo

@blueprint-bot
Copy link

fix lint flag

Previews: documentation | landing | table | demo

@blueprint-bot
Copy link

Merge remote-tracking branch 'origin/develop' into ad/eslint-menuitem

Previews: documentation | landing | table | demo

@blueprint-bot
Copy link

fix bad merge

Previews: documentation | landing | table | demo

@blueprint-bot
Copy link

minor rule documentation fix

Previews: documentation | landing | table | demo

@adidahiya adidahiya merged commit efde212 into develop Aug 11, 2022
@adidahiya adidahiya deleted the ad/eslint-menuitem branch August 11, 2022 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants