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

Add prettier and eslint, .npmrc #28

Merged
merged 38 commits into from
Jun 27, 2018
Merged

Add prettier and eslint, .npmrc #28

merged 38 commits into from
Jun 27, 2018

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented May 21, 2018

This adds prettier and eslint with the github config, and runs the lint script on Travis.

This fails on Travis as of 5/21 and #21 being merged, so I'm going to see if I can fix it. Fixed!

@shawnbot shawnbot changed the title Add prettier and eslint, .npmrc [WIP] Add prettier and eslint, .npmrc May 21, 2018
@shawnbot
Copy link
Contributor Author

Well, this is super frustrating. Without a jsx-quotes rule, running npm run lint -- --fix (i.e. eslint src --fix) fixes all of the linting errors but changes all of the JSX attribute quotes to double. But if I add "jsx-quotes": ["warn", "prefer-single"] to the eslint config and then run eslint --fix, it treats all of the single quotes as errors and fails.

I'm going to close this for now, but I'd like to get linting working soon.

@shawnbot shawnbot closed this May 21, 2018
@shawnbot
Copy link
Contributor Author

If/when we decide to pick this up again, it appears that the issue is with Prettier:

I'm not sure what the solution is, other than to wrap all of the attributes in curly braces. 😠

@shawnbot shawnbot mentioned this pull request Jun 7, 2018
@emplums
Copy link

emplums commented Jun 8, 2018

@shawnbot how do you feel about merging this in as is? JSX prefers double quotes for attributes since that's similar to the HTML api for attributes, and several major linters & lint configs use this convention ex. airbnb's eslint config here. It is a little weird to switch between single quotes for JS and double quotes for attributes (which are also technically js lol), but I don't think it should hold us back from getting linting & formatting set up for all the other cases we want to lint/format. Plus, if you want to keep writing single quotes for attributes you can, and we can just run the eslint fix in CI 🤷‍♀️

I did see that there's a fork of prettier that we might be able to use with a a jsx-single-quotes rule but it's implementation seems a bit tricky https://github.com/arijs/prettier-miscellaneous

@shawnbot
Copy link
Contributor Author

shawnbot commented Jun 8, 2018

I’m down with that! JSX quotes should probably be a warning so that they don’t fail builds, right?

@shawnbot shawnbot reopened this Jun 8, 2018
Copy link
Contributor Author

@shawnbot shawnbot left a comment

Choose a reason for hiding this comment

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

Might need to undo some of the limiting linting fixes to avoid conflicts.

package.json Outdated
@@ -18,6 +18,7 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"lint": "eslint src",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, we should lint examples.

@shawnbot
Copy link
Contributor Author

@emplums I got this working and eslint --fix'd all of the things. As of 828d50c there are a ton of warnings, mostly related to prop-types) but zero errors!

@emplums
Copy link

emplums commented Jun 21, 2018

Oh awesome! Let's just go with this then instead of standard 🎉 Would you mind adding some documentation about the linter to the README as part of this?

@shawnbot
Copy link
Contributor Author

shawnbot commented Jun 21, 2018

@emplums How's this section look to you?

@shawnbot shawnbot requested a review from emplums June 21, 2018 20:54
@shawnbot shawnbot changed the title [WIP] Add prettier and eslint, .npmrc Add prettier and eslint, .npmrc Jun 21, 2018
.eslintrc.json Outdated
"plugin:github/react"
],
"rules": {
"jsx-a11y/no-autofocus": "warn",
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 left a note in the commit about this, but I wanted to flag it for @emplums because it has a11y implications. We'll need to remove support for autofocus from <TextInput> if we remove this line, which will fail any instance of it.

Copy link

Choose a reason for hiding this comment

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

Hmm... I think we might want to remove support for autofocus on TextInputs anyways, unless there's a strong case for it. It can have pretty bad a11y consequences. I'll open a separate issue for that . 👍

Copy link

Choose a reason for hiding this comment

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

Created an issue for discussion here: #89

"rules": {
"jsx-a11y/no-autofocus": "warn",
"react/prop-types": "warn",
"react/sort-prop-types": "warn"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we fix up prop types sorting we should remove this. It just didn't seem to be an error to me if prop type keys aren't sorted alphabetically.

className,
color && `text-${color}`,
fontSizeClass,
fontWeight === 'bold' && 'text-bold',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Linting uncovered the fact that we weren't actually using fontWeight anywhere, so I added support for fontWeight='bold' here. But maybe it should just be weight or a boolean prop bold?

Copy link

Choose a reason for hiding this comment

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

I like fontWeight since it follows the primer/primer api!

src/Dropdown.js Outdated
<div className="BtnGroup">
<Details className="details-reset BtnGroup-form d-flex">
{(
{open, toggle} // eslint-disable-line no-unused-vars
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In retrospect, it looks like we can just nix open from this destructure and kill the eslint-disable-line comment.

@shawnbot
Copy link
Contributor Author

@emplums It's green and I left a couple of notes. Do you mind doing one more pass over this before we merge? 🙇

@shawnbot
Copy link
Contributor Author

We have a ton of jsx-a11y rules! The ones in our config are just overrides so that certain ones don't fail our builds.

Copy link

@emplums emplums left a comment

Choose a reason for hiding this comment

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

Just left a few comments and questions! The only thing pending that I think we should include before merge is the full set of jsx-a11y rules. I'm also keen on adding a rule around spacing in objects, as it helps make the code more readable, IMO.

src,
...rest
} = props
const {alt, isChild, size = 20, src} = props
Copy link

Choose a reason for hiding this comment

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

Can we add the object-curly-spacing eslint rule for consistent spacing within objects 😬

Copy link
Contributor Author

@shawnbot shawnbot Jun 26, 2018

Choose a reason for hiding this comment

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

My personal preference is not to, and I feel like this is the type of deviation from the GitHub config that might make it weird for folks outside our team who want to contribute. How do we make a decision like this? Put it to a vote? 😬 /cc @broccolini

className,
color && `text-${color}`,
fontSizeClass,
fontWeight === 'bold' && 'text-bold',
Copy link

Choose a reason for hiding this comment

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

I like fontWeight since it follows the primer/primer api!

size,
value
}) => (
const TextInput = ({autocomplete, autofocus, block, disabled, id, name, placeholder, required, size, value}) => (
Copy link

Choose a reason for hiding this comment

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

Does this rule get enforced no matter how many object keys there are? Or is it only enforced if the line is less than a certain number of characters?

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 think it's a line length thing. 🙁

"jsx-a11y/no-autofocus": "warn",
"react/prop-types": "warn",
"react/sort-prop-types": "warn"
}
Copy link

Choose a reason for hiding this comment

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

Can we add the jsx-a11y/recommended plugin here so that we get the full set of a11y rules?

@shawnbot
Copy link
Contributor Author

@emplums I added the jsx-a11y recommended rules! 🎉 You cool punting on the curly spacing rule for now, merging this as-is, and discussing any changes at our API meeting?

@shawnbot shawnbot merged commit ce23d82 into release-0.0.6-beta Jun 27, 2018
@shawnbot shawnbot deleted the add-prettier branch June 27, 2018 18:58
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.

2 participants