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

Prepare gestalt for eslint 5 via bump to plugins #273

Merged
merged 9 commits into from Jul 11, 2018

Conversation

pfarejowicz
Copy link
Contributor

@pfarejowicz pfarejowicz commented Jul 11, 2018

ESLINT 5 is out, but we cannot upgrade because the eslint-plugin-airbnb latest version has a peer dependency on eslint 4.19.1 still. Trying to upgrade straight to eslint 5 leads to lots of peer dep errors from yarn. The fix has already landed on the airbnb master but it has not been released yet.

Tracking airbnb/javascript#1834 for when we can finally update to eslint 5!

In the meantime, this change:

  1. Upgrades all other eslint related packages to the latest versions to be ready for eslint 5
  2. Fixes the errors that came from the upgrades
  3. Disables the react/destructuring-assignment rule temporarily as that one is a big offender ~80 times so I will handle it on its own
  4. Disables the button-has-type rule on Button because apparently the creators want developers to hard code values and duplicate code instead of using the dynamic type. See button-has-type does not allow for dynamic assignment jsx-eslint/eslint-plugin-react#1555 for more info
  5. For places that needed a new button type I used the submit value as that is what the default behavior is if the attribute is ignored according to HTML docs

@christianvuerings
Copy link
Contributor

Deploy preview for gestalt ready!

Built with commit 97ebed4

https://deploy-preview-273--gestalt.netlify.com

@christianvuerings
Copy link
Contributor

christianvuerings commented Jul 11, 2018

Deploy preview for gestalt ready!

Built with commit 0bdccd7

https://deploy-preview-273--gestalt.netlify.com

@ghost
Copy link

ghost commented Jul 11, 2018

Warnings
⚠️

📁 Bundlesize - Bundle size increase detected, please review

Filename Size Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip
gestalt.js 🔺 0.2% 🔺 0.1% 254.56 KB 255 KB 56.73 KB 56.8 KB
gestalt.es.js 🔺 0.2% 🔺 0.1% 251.93 KB 252.37 KB 56.35 KB 56.42 KB

Generated by 🚫 dangerJS

@@ -54,6 +54,7 @@ export default function Button(props: Props) {
[styles.block]: !inline,
});

/* eslint-disable react/button-has-type */
Copy link
Contributor

Choose a reason for hiding this comment

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

@pfarejowicz Any idea why we need to disable this even though we set it below? Is it because type is dynamic?

type={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.

@christianvuerings exactly! the rule does not like us using the dynamic value type={type} even if it is Flow typed and prop typed to match the possible values. There's more discussion in jsx-eslint/eslint-plugin-react#1555 and the recommendation is to fork the component and render two different JSX components but to me that feels like overkill, what are your thoughts? For reference:

I'd say that the rule should be forcing a single, hardcoded type value - and that you should conditionally render two different elements if you want two types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Disabling it here seems fine - thanks for clarifying

@@ -6,7 +6,11 @@ import Flyout from './Flyout.js';
it('Flyout renders', () => {
const wrapper = shallow(
<Flyout
anchor={<button onClick={() => null}> test </button>}
anchor={
<button onClick={() => null} type="submit">
Copy link
Contributor

Choose a reason for hiding this comment

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

@pfarejowicz we should probably change this to type="button". A flyout inside of a form should not be submitting the form. Also button is the default for <Button>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change

@@ -36,6 +36,7 @@ export default function SegmentedControl(props: Props) {
key={i}
onClick={e => onChange({ event: e, activeIndex: i })}
role="tab"
type="submit"
Copy link
Contributor

Choose a reason for hiding this comment

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

@pfarejowicz could we change this to type="button"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make the change, I agree button is better than submit. My goal was to introduce the minimal amount of changes and since this is a <button /> and not a <Button /> the default here was actually always setting this to type="submit" since we were not specifying it explicitly. See the Mozilla docs for reference. Making this change now, but just making a not here for future readers that the behavior is changing from our released version.

type
The type of the button. Possible values are:

submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.

@@ -48,6 +48,7 @@ export default class Item extends Component {
<button
id={`add-more-${itemIdx}`}
onClick={() => fetchMore().then(addRelatedItems)}
type="submit"
Copy link
Contributor

Choose a reason for hiding this comment

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

@pfarejowicz same here - change to type="button"

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, same comment as above but this is a test component so Im not too concerned

@codecov-io
Copy link

codecov-io commented Jul 11, 2018

Codecov Report

Merging #273 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #273   +/-   ##
=======================================
  Coverage   70.24%   70.24%           
=======================================
  Files          46       46           
  Lines         820      820           
  Branches      189      189           
=======================================
  Hits          576      576           
  Misses        172      172           
  Partials       72       72
Impacted Files Coverage Δ
packages/gestalt/src/TextField.js 42.1% <ø> (ø) ⬆️
packages/gestalt/src/Button.js 100% <ø> (ø) ⬆️
packages/gestalt/src/SegmentedControl.js 100% <ø> (ø) ⬆️
packages/gestalt/src/Tabs.js 47.05% <ø> (ø) ⬆️
packages/gestalt/src/RadioButton.js 33.33% <ø> (ø) ⬆️
packages/gestalt/src/Checkbox.js 46.15% <ø> (ø) ⬆️
packages/gestalt/src/IconButton.js 30% <ø> (ø) ⬆️
packages/gestalt/src/TextArea.js 35% <ø> (ø) ⬆️
packages/gestalt/src/Video.js 34.16% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08480e1...0bdccd7. Read the comment docs.

Copy link
Contributor

@chrislloyd chrislloyd left a comment

Choose a reason for hiding this comment

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

The ordering with components seems nicer (it never really made much sense to me before).

@@ -56,7 +56,8 @@ export default function transformer(file, api) {
if (convertSizes[value]) {
attribute.value.value = convertSizes[value];
return attribute;
} else if (invalidSizes.includes(value)) {
}
if (invalidSizes.includes(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wow huh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrislloyd same reaction haha, its this rule https://eslint.org/docs/rules/no-else-return which does not like an else if clause after a return

}

Button.defaultProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm so torn on this one. None of our tools really introspect defaultProps and it's not a required part of the React API so this definitely feels like extra typing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed - I started off by playing with the typing and defaulting, hoping to fix the type={type} error but to no avail since I found the github thread linked above saying it needs to be hardcoded to "button" or "submit". Figured I would keep the defaultProps that I created anyways since it is a common pattern. Thoughts? I can revert the defaulting since the rule needs to be disabled anyways

@pfarejowicz pfarejowicz merged commit 990f132 into pinterest:master Jul 11, 2018
@pfarejowicz pfarejowicz deleted the bump_eslint branch July 11, 2018 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants