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 code formatting and linting. #952

Merged
merged 18 commits into from
Aug 7, 2018
Merged

Add code formatting and linting. #952

merged 18 commits into from
Aug 7, 2018

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Dec 20, 2017

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!

@verythorough
Copy link
Contributor

verythorough commented Dec 20, 2017

Deploy preview for cms-demo ready!

Built with commit f8d1ad2

https://deploy-preview-952--cms-demo.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Dec 20, 2017

Deploy preview for netlify-cms-www ready!

Built with commit f8d1ad2

https://deploy-preview-952--netlify-cms-www.netlify.com

@tech4him1 tech4him1 changed the title WIP: Add automatic code formatting with Prettier Add automatic code formatting with Prettier Jan 2, 2018
@tech4him1 tech4him1 changed the title Add automatic code formatting with Prettier WIP: Add automatic code formatting with Prettier Jan 2, 2018
@tech4him1 tech4him1 force-pushed the add-prettier branch 2 times, most recently from 9648718 to f5d5380 Compare January 3, 2018 21:15
@tech4him1 tech4him1 changed the title WIP: Add automatic code formatting with Prettier Add automatic code formatting with Prettier Jan 3, 2018
@tech4him1
Copy link
Contributor Author

tech4him1 commented Jan 3, 2018

Unfortunately, Prettier does not seem to have many options available.

@erquhart
Copy link
Contributor

@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.

@tech4him1
Copy link
Contributor Author

tech4him1 commented Feb 28, 2018

@erquhart What Prettier options did you change (I don't see the diff since it was a force-push)?

Prettier produces a lot of stacked args lists, and Babel gets rid of them in the output, so we should just use them everywhere.

I don't particular like stacked args lists everywhere, but it's not horrible.

@erquhart
Copy link
Contributor

erquhart commented Mar 2, 2018

That was the only difference, changing trailing commas to "all" instead of "es5".

@tech4him1
Copy link
Contributor Author

tech4him1 commented Mar 2, 2018

@Benaiah had a few suggestions in #1013:

  • --trailing-commas all
  • --print-width <something wider than 80>

Also, integration with ESLint could probably be done in a separate PR.

  • Integrate prettier with eslint:
    • Make prettier run through eslint --fix
    • Use prettier-compatible eslint config
    • Make eslint check for proper code formatting in test suite.

@erquhart erquhart mentioned this pull request Mar 2, 2018
28 tasks
Copy link

@jeddy3 jeddy3 left a 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/",
Copy link

@jeddy3 jeddy3 Mar 3, 2018

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": {
Copy link

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).

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.

@@ -1,5 +1,5 @@
@import "./NotFoundPage.css";
@import "./Header.css";
@import './NotFoundPage.css';
Copy link

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?

Copy link
Contributor Author

@tech4him1 tech4him1 Mar 3, 2018

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.

Copy link
Contributor

@erquhart erquhart Mar 5, 2018

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.

@@ -3,7 +3,7 @@
}

.nc-appHeader-main {
@apply(--dropShadowMain);
@apply (--dropShadowMain);
Copy link

@jeddy3 jeddy3 Mar 3, 2018

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?

Copy link
Contributor

@erquhart erquhart Mar 5, 2018

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.

@tech4him1
Copy link
Contributor Author

Updated PR to use single quotes -- we will need to re-run Prettier before merge.

@erquhart
Copy link
Contributor

Just holding off on this until we're ready to break every PR. We'll get it in soon.

@tech4him1
Copy link
Contributor Author

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",
Copy link
Contributor Author

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?

Copy link
Contributor

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.

@tech4him1
Copy link
Contributor Author

@jeddy3 Should we be running stylelint --fix along with Prettier and eslint --fix?

@jeddy3
Copy link

jeddy3 commented Apr 12, 2018

Should we be running stylelint --fix along with Prettier and eslint --fix

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 stylelint --fix, but at it won't (at this time) do anything for you.

@erquhart
Copy link
Contributor

We should pull the trigger on this right before the v2 release.

Copy link

@argus777 argus777 left a comment

Choose a reason for hiding this comment

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

Review content removed

@tech4him1
Copy link
Contributor Author

Two blocking PRs left, then we're good to go!

@erquhart
Copy link
Contributor

erquhart commented Aug 7, 2018

All blockers merged 🎉 🎉

Last call for anyone that wants to opine on this one - I'll review soon @tech4him1.

@tech4him1
Copy link
Contributor Author

Awesome, I'll work on rebasing!

@tech4him1 tech4him1 force-pushed the add-prettier branch 2 times, most recently from 6fe4e73 to 7d8faa5 Compare August 7, 2018 18:26
@tech4him1 tech4him1 force-pushed the add-prettier branch 2 times, most recently from 8e3cf80 to 0e2d2e4 Compare August 7, 2018 19:51
@erquhart erquhart merged commit f801b19 into master Aug 7, 2018
@erquhart erquhart deleted the add-prettier branch August 7, 2018 20:46
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.

6 participants