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: prefer-box-no-classname rule w/ autofix + merged into prefer-box-lonely-ref #1629

Merged
merged 6 commits into from Aug 19, 2021

Conversation

AlbertCarreras
Copy link
Contributor

@AlbertCarreras AlbertCarreras commented Aug 17, 2021

Summary

prefer-box-no-disallowed: "Prefer Box: prevent <div> tags that don't contain disallowed attributes: className, onClick. Use Gestalt Box, instead"

This is a list of the eslint-plugin-jsx-a11y eslints that cover div but won't cover Box. Other props [ role, onMouseOver, onMouseOut, accessKey, autoFocus, tabIndex] are also considered ignored or disallowed to prevent losing coverage:

  • aria-activedescendant-has-tabindex: AFFECTS div
  • aria-props: AFFECTS div
  • aria-proptypes: AFFECTS div
  • aria-role: AFFECTS div
  • interactive-supports-focus: AFFECTS div somewhat
  • mouse-events-have-key-events: AFFECTS div
  • no-access-key: AFFECTS div
  • no-autofocus: AFFECTS div
  • no-noninteractive-tabindex: AFFECTS div
  • no-static-element-interactions: AFFECTS div but not that much disallowing onClick
  • role-has-required-aria-props: AFFECTS div
  • role-supports-aria-props: AFFECTS div
  • tabindex-no-positive: AFFECTS div

Good to go on Pinboard:

`TIMING=1 ./node_modules/.bin/eslint ~/code/pinboard/webapp/app
No errors thrown.

image

Example:
Kapture 2021-08-19 at 01 55 04

Links

  • [Jira](link to Jira ticket(s))
  • [TDD](link to Paper doc)
  • [Figma](link to Figma file)

Checklist

  • Added unit and Flow Tests
  • Added documentation + accessibility tests
  • Verified accessibility: keyboard & screen reader interaction
  • Checked dark mode, responsiveness, and right-to-left support
  • Checked stakeholder feedback (e.g. Gestalt designers)

@AlbertCarreras AlbertCarreras changed the title Eslint plugin: prefer-box-no-classname rule w/ autofix + merged into prefer-box-lonely-ref Eslint plugin: prefer-box-no-classname rule w/ autofix + merged into prefer-box-lonely-ref Aug 17, 2021
@AlbertCarreras AlbertCarreras added the minor release Minor release label Aug 17, 2021
@netlify
Copy link

netlify bot commented Aug 17, 2021

✔️ Deploy Preview for gestalt ready!

🔨 Explore the source changes: 1b4f78a

🔍 Inspect the deploy log: https://app.netlify.com/sites/gestalt/deploys/611b080da27ac6000869ce5c

😎 Browse the preview: https://deploy-preview-1629--gestalt.netlify.app/

@netlify
Copy link

netlify bot commented Aug 17, 2021

✔️ Deploy Preview for gestalt ready!

🔨 Explore the source changes: d293baf

🔍 Inspect the deploy log: https://app.netlify.com/sites/gestalt/deploys/611ee012a1c71700084b4e20

😎 Browse the preview: https://deploy-preview-1629--gestalt.netlify.app/

@AlbertCarreras AlbertCarreras marked this pull request as ready for review August 17, 2021 18:45
@AlbertCarreras AlbertCarreras requested a review from a team as a code owner August 17, 2021 18:45
@AlbertCarreras AlbertCarreras force-pushed the preferBoxNoClassname branch 2 times, most recently from 556fc2c to 8e90f77 Compare August 17, 2021 18:51
newComponentName,
replaceRegexCallback = ({ input }) => input,
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit specific to dangerouslySetInlineStyle. I wonder if it would make more sense to build that prop (and any others) as a string outside of this function, then use RenameTagWithPropsFixerType's additionalPropsString arg to build it into the fixed component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the less "invasive" approach, I'm not just renaming, but adding the { __style: <>} first key value . Adding one additional props would require removing the previous style prop. I could also reconstruct all props and alphabetize, but that would make the PR review even more opaque to the important changes. I might change the approach when I work on other Eslints, there must be a more universal way. For now, I think I wanna keep this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of the approach I took with the Box->Flex rule?

Avoiding regex keeps the code more readable, and it seems a lot simpler to me to keep the rule-specific logic outside of these helpers. The helpers can remove a current prop or add a new one, and the logic within the rule can determine what needs to be removed and what needs to be added (and how the new prop(s) should be formatted).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Looks great. This arg can now be removed, right?

@@ -160,7 +181,7 @@ type GetComponentFromAttributeType = ({| nodeAttribute: GenericNode |}) => Gener
Example:
\<div {...props} \/\> returns div node for the spread props attribute
*/
export const getComponenFromAttribute: GetComponentFromAttributeType = ({ nodeAttribute }) =>
const getComponenFromAttribute: GetComponentFromAttributeType = ({ nodeAttribute }) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo, getComponentFromAttribute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

const isTag: IsTagType = ({ elementNode, tagName }) => elementNode?.name?.name === tagName;

type HasSpreadAttributesType = ({| elementNode: GenericNode |}) => boolean;
/** This function checks is a given node (elementNode) contains spread attributs
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

attributes: $ReadOnlyArray<string>,
|}) => boolean;

/** This function checks is a given tag (tagName) in a node (elementNode) contains a given attribute (attribute), and returns true if so.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo …checks if a given…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

newComponentName,
replaceRegexCallback = ({ input }) => input,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Looks great. This arg can now be removed, right?

@AlbertCarreras
Copy link
Contributor Author

AlbertCarreras commented Aug 19, 2021

#1629 (comment)

Yeah, I left it because I thought we could use it in the future, preoptimization... so not need it.

@AlbertCarreras AlbertCarreras force-pushed the preferBoxNoClassname branch 2 times, most recently from 4dcf395 to 35692f2 Compare August 19, 2021 22:45
@AlbertCarreras AlbertCarreras merged commit 20ce8e2 into pinterest:master Aug 19, 2021
@AlbertCarreras AlbertCarreras deleted the preferBoxNoClassname branch September 20, 2021 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor release Minor release
Projects
None yet
2 participants