Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Prettier #4012

Merged
merged 12 commits into from
Jul 23, 2018
Merged

Prettier #4012

merged 12 commits into from
Jul 23, 2018

Conversation

reichhartd
Copy link
Contributor

@reichhartd reichhartd commented Jul 3, 2018

PR checklist

  • Addresses an existing issue: #0000
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

Overview of change:

  • Change "npm run" to "yarn" in docs/develop/docs/index.md
  • Added the code formatter prettier (https://prettier.io/)
  • Added a precommit hook: To run prettier pre commit over every staged file

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @danielreichhart! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

package.json Outdated
"json-stringify-pretty-compact": "^1.0.3",
"mocha": "^3.2.0",
"npm-run-all": "^4.0.2",
"nyc": "^10.2.0",
"prettier": "^1.13.7",
Copy link
Contributor

Choose a reason for hiding this comment

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

Like the documentation pointed out https://prettier.io/docs/en/install.html
Use exact version instead of ^ or ~
Only use 1.13.7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I changed it.

@@ -26,3 +26,6 @@ docs/formatters/*/index.html

/coverage/
/.nyc_output

# ide
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge problem here, but try to do only one thing in a PR
The repository owner can not cerry-pick like in GitLab (in the GitHub GUI)

@pablobirukov
Copy link
Contributor

Why is prettier needed? From my expirience it makes development less convenient (I'm talking only about typescript):

  • in some cases it reduces readabiility

  • maked PR management more complicated because it puts arguments and imported members on a single line or multiple lines depending on line length. For example, if you just rename an argument and change its name's length, instead of changing one line, prettier will change several lines, as

    function foo(
      does,
      not,
      fit,
    )
    // ↓
    function foo(do, fit, now)

@reichhartd
Copy link
Contributor Author

reichhartd commented Jul 4, 2018

Okay, that’s right. But in my opinion, it reduces the readability only in few edge cases. In general, it improves it. For the few cases, we could open an issue or a pull request at the prettier project.

You can define the line length in the .prettierrc config file. The current print width is 120 chars. If it makes the PR management more complicated, we could increase the length.

@johnwiseheart
Copy link
Contributor

johnwiseheart commented Jul 5, 2018

I agree that prettier is a good idea to add here: in the majority of cases, it simplifies code style and makes it easier to review PRs - there no longer needs to be checks of code layout/formatting as prettier enforces this. @danielreichhart any idea why the tests are failing after this change? It might not be an issue with this PR but we should figure it out before merging.

@reichhartd
Copy link
Contributor Author

reichhartd commented Jul 9, 2018

It is a issue with some older pull requests, the failing tests are fixed here #4011 #4019

@johnwiseheart
Copy link
Contributor

I merged the PR for the failing tests - could you merge master into your PR and re-push?

Reichhart, Daniel added 2 commits July 12, 2018 14:59
@reichhartd
Copy link
Contributor Author

@johnwiseheart done

.prettierrc.json Outdated
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"printWidth": 120
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 not sure about having a print width of 120 - the prettier docs specifically mention why the default of 80 makes sense. @giladgray do you have any comments here? Maybe we could set it to 100 so its in the middle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnwiseheart @giladgray are there any news?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO 100 is a good choice because you can see the changes in a commit side by side without scrolling (on a 1080p monitor)

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’ve always worked with 120, but 100 is a good compromise.

Also, the point the commit changes without scrolling is a good point.

@johnwiseheart johnwiseheart merged commit 3617be0 into palantir:master Jul 23, 2018
@johnwiseheart
Copy link
Contributor

Thanks for contributing!

aboyton pushed a commit to aboyton/tslint that referenced this pull request Oct 9, 2018
palantir#4012 added prettier support but then didn't run it over everything and turned it on for YAML files despite using a version that doesn't support YAML.

This:
* Upgrades Prettier to  1.14 whic adds yml support.
* Turns on `trailing commas = all` as that seems to be what most of the code is doing.
* Runs prettier over everything

This also has the bonus of making future PRs much smaller.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants