-
Notifications
You must be signed in to change notification settings - Fork 337
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
AlbertCarreras
merged 6 commits into
pinterest:master
from
AlbertCarreras:preferBoxNoClassname
Aug 19, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0df5588
Rename prefer-box
AlbertCarreras c137852
Rename prefer-box-lonely-ref
AlbertCarreras 8a3861c
added onClick to disallowed attributes
AlbertCarreras 1f3c058
add aria- to be ignored
AlbertCarreras dfca97e
biggest last change
AlbertCarreras d293baf
address final comments
AlbertCarreras File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
...fer-box-no-disallowed/invalid-no-disallowed/gestalt-import-with-box-inline-style-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<Box> | ||
<div onBlur={() => {}} style={{ marginTop: 200 }}> | ||
<Box /> | ||
</div> | ||
</Box> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
...er-box-no-disallowed/invalid-no-disallowed/gestalt-import-with-box-inline-style-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<Box> | ||
<Box onBlur={() => {}} dangerouslySetInlineStyle={{ __style: { marginTop: 200 } }}> | ||
<Box /> | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...xtures__/prefer-box-no-disallowed/invalid-no-disallowed/gestalt-import-with-box-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<Box> | ||
<Box onBlur={() => {}}> | ||
<Box /> | ||
</Box> | ||
</Box> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
..._/prefer-box-no-disallowed/invalid-no-disallowed/gestalt-import-with-renamed-box-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box as RenamedBox } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<RenamedBox> | ||
<div onBlur={() => {}}> | ||
<RenamedBox /> | ||
</div> | ||
</RenamedBox> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
.../prefer-box-no-disallowed/invalid-no-disallowed/gestalt-import-with-renamed-box-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box as RenamedBox } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<RenamedBox> | ||
<RenamedBox onBlur={() => {}}> | ||
<RenamedBox /> | ||
</RenamedBox> | ||
</RenamedBox> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
...ures__/prefer-box-no-disallowed/invalid-no-disallowed/gestalt-import-without-box-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Text, Flex } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<div onBlur={() => {}}> | ||
<Text>Test</Text> | ||
</div> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
...res__/prefer-box-no-disallowed/invalid-no-disallowed/gestalt-import-without-box-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Box, Flex, Text } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<Box onBlur={() => {}}> | ||
<Text>Test</Text> | ||
</Box> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/__fixtures__/prefer-box-no-disallowed/invalid-no-disallowed/no-gestalt-import-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function TestElement() { | ||
return ( | ||
<div onBlur={() => {}}> | ||
<button /> | ||
</div> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/__fixtures__/prefer-box-no-disallowed/invalid-no-disallowed/no-gestalt-import-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
return ( | ||
<Box onBlur={() => {}}> | ||
<button /> | ||
</Box> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
...es__/prefer-box-no-disallowed/invalid-no-disallowed/no-gestalt-import-selfclosed-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function TestElement() { | ||
return <div onBlur={() => {}} />; | ||
} |
4 changes: 4 additions & 0 deletions
4
...s__/prefer-box-no-disallowed/invalid-no-disallowed/no-gestalt-import-selfclosed-output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
return <Box onBlur={() => {}} />; | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/eslint-plugin-gestalt/src/__fixtures__/prefer-box-no-disallowed/valid/valid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Box } from 'gestalt'; | ||
export default function TestElement() { | ||
const props = { onBlur: () => {} }; | ||
return ( | ||
<Box> | ||
<Box ref={undefined} /> | ||
<div ref={undefined} className={undefined} /> | ||
<div ref={undefined} onClick={() => {}} /> | ||
<div ref={undefined} tabIndex={-1} /> | ||
<div ref={undefined} role="button" /> | ||
<div ref={undefined} onMouseOver={() => {}} /> | ||
<div ref={undefined} accessKey="test" /> | ||
<div ref={undefined} autoFocus /> | ||
<div ref={undefined} {...props} /> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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'sadditionalPropsString
arg to build it into the fixed component?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
There was a problem hiding this comment.
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?