-
Notifications
You must be signed in to change notification settings - Fork 534
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
Conversation
Well, this is super frustrating. Without a I'm going to close this for now, but I'd like to get linting working soon. |
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 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 |
I’m down with that! JSX quotes should probably be a warning so that they don’t fail builds, right? |
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.
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", |
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.
Also, we should lint examples
.
@emplums I got this working and |
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? |
@emplums How's this section look to you? |
.eslintrc.json
Outdated
"plugin:github/react" | ||
], | ||
"rules": { | ||
"jsx-a11y/no-autofocus": "warn", |
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.
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.
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.
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 . 👍
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.
Created an issue for discussion here: #89
"rules": { | ||
"jsx-a11y/no-autofocus": "warn", | ||
"react/prop-types": "warn", | ||
"react/sort-prop-types": "warn" |
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.
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', |
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.
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
?
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.
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 |
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.
In retrospect, it looks like we can just nix open
from this destructure and kill the eslint-disable-line
comment.
@emplums It's green and I left a couple of notes. Do you mind doing one more pass over this before we merge? 🙇 |
We have a ton of |
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.
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 |
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.
Can we add the object-curly-spacing eslint rule for consistent spacing within objects 😬
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.
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', |
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.
I like fontWeight since it follows the primer/primer api!
size, | ||
value | ||
}) => ( | ||
const TextInput = ({autocomplete, autofocus, block, disabled, id, name, placeholder, required, size, value}) => ( |
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.
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?
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.
I think it's a line length thing. 🙁
"jsx-a11y/no-autofocus": "warn", | ||
"react/prop-types": "warn", | ||
"react/sort-prop-types": "warn" | ||
} |
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.
Can we add the jsx-a11y/recommended plugin here so that we get the full set of a11y rules?
@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? |
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!