-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 code formatting and linting. #952
Conversation
Deploy preview for cms-demo ready! Built with commit f8d1ad2 |
Deploy preview for netlify-cms-www ready! Built with commit f8d1ad2 |
9648718
to
f5d5380
Compare
Unfortunately, Prettier does not seem to have many options available. |
ea4e562
to
490344d
Compare
490344d
to
c229487
Compare
@tech4him1 I pushed updated commits and changed the config a bit - Prettier produces a lot of stacked args lists, and Babel gets rid of them in the output, so we should just use them everywhere. Let me know what you think. |
@erquhart What Prettier options did you change (I don't see the diff since it was a force-push)?
I don't particular like stacked args lists everywhere, but it's not horrible. |
That was the only difference, changing trailing commas to "all" instead of "es5". |
@Benaiah had a few suggestions in #1013:
Also, integration with ESLint could probably be done in a separate PR.
|
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've quickly highlighted just a handful of things that popped out at me.
As suggested in #1013 (comment), consider adopting just the ESLint and stylelint recommended configs, for now, to avoid the linting tools and Prettier conflicting.
package.json
Outdated
@@ -17,10 +17,16 @@ | |||
"lint:css": "stylelint 'src/**/*.css'", | |||
"lint:css:fix": "stylefmt --recursive 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.
I believe using Prettier to pretty-printing your CSS code will make stylefmt redundant. It can be safely removed.
package.json
Outdated
"deps": "npm-check -s", | ||
"deps:update": "npm-check -u", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"prettier": { | ||
"trailingComma": "all" | ||
}, | ||
"lint-staged": { |
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.
As lint-staged is already being used, I believe Prettier can be added here (alongside eslint --fix
).
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.
src/components/App/App.css
Outdated
@@ -1,5 +1,5 @@ | |||
@import "./NotFoundPage.css"; | |||
@import "./Header.css"; | |||
@import './NotFoundPage.css'; |
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.
Prettier seems to use double quotes by default (at least within the playground). It feels odd that it has converted these quotes to single ones. Is there a configuration option not shown in this PR that could be causing this?
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.
Prettier's default for quotes is double, so I'm not sure why they choose to change that for imports.
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 was wondering about that - the unwritten rule has been single quotes everywhere except JSX attributes, we should configure for that.
src/components/App/Header.css
Outdated
@@ -3,7 +3,7 @@ | |||
} | |||
|
|||
.nc-appHeader-main { | |||
@apply(--dropShadowMain); | |||
@apply (--dropShadowMain); |
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.
Even though the use of parentheses isn't mentioned in the @apply
spec, postcss-cssnext seems (at least within the playground) to be able to transpile it, including with the additional space introduced in this change.
Incidentally, I believe the @apply
feature has been abandoned. I can create a separate issue to discuss whether it should be refactored out if you like?
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'm aware of @apply
stalling out, I'm expecting to just drop it whenever we switch to a CSS-in-JS solution rather than migrating away from it under plain CSS.
Updated PR to use single quotes -- we will need to re-run Prettier before merge. |
Just holding off on this until we're ready to break every PR. We'll get it in soon. |
Updated ESLint/StyleLint to use only code (not style) checks. |
package.json
Outdated
@@ -14,17 +14,24 @@ | |||
"add-contributor": "all-contributors add", | |||
"generate-contributors": "all-contributors generate", | |||
"lint": "npm run lint:js & npm run lint:css", | |||
"lint:js": "eslint .", | |||
"lint:js": "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.
Do we need to lint everything, or just the source files?
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'd still want to lint other dirs like example and website, and top level files such as the webpack configs. If eslint knows to only hit js files and to ignore the dist
, this should work.
@jeddy3 Should we be running |
I don't believe any of the rules in the recommended config are autofixable. It's mainly the stylistic rules that can be autofixed in stylelint, which aren't included in the recommended config. So, I don't think there's any harm in using |
We should pull the trigger on this right before the v2 release. |
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.
Review content removed
Two blocking PRs left, then we're good to go! |
All blockers merged 🎉 🎉 Last call for anyone that wants to opine on this one - I'll review soon @tech4him1. |
Awesome, I'll work on rebasing! |
6fe4e73
to
7d8faa5
Compare
8e3cf80
to
0e2d2e4
Compare
Summary
Add ability to automatically format our code to maintain a consistent code style.
Linting and correct formatting is also enforced through the CI.
Closes #363.
Current Blocking PRs
These PRs will need to be merged first. See #363 (comment) for a simplified TODO list.
Test plan
CI should pass!