Skip to content

Run Prettier #7279

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

Closed
wants to merge 3 commits into from
Closed

Run Prettier #7279

wants to merge 3 commits into from

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Mar 18, 2021

New Pull Request Checklist

Issue Description

Just like #7172, this is just runs npm run prettier and then npm run lint-fix on the master branch.

Out of habit I run prettier and lint prior to submitting a PR, however there are a number of files that haven't had this process ran through on them.

The result is this PR.

Also adds the line to CONTRIBUTING:

Format your code by running npm run prettier followed by npm run lint-fix.

@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #7279 (5e85bc1) into master (a05e9b1) will decrease coverage by 0.00%.
The diff coverage is 70.00%.

❗ Current head 5e85bc1 differs from pull request most recent head ac6e2b0. Consider uploading reports for the commit ac6e2b0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7279      +/-   ##
==========================================
- Coverage   93.91%   93.91%   -0.01%     
==========================================
  Files         179      179              
  Lines       13154    13153       -1     
==========================================
- Hits        12353    12352       -1     
  Misses        801      801              
Impacted Files Coverage Δ
src/Adapters/Storage/Postgres/PostgresClient.js 70.00% <0.00%> (+3.33%) ⬆️
src/Security/Check.js 100.00% <ø> (ø)
src/Security/CheckGroups/CheckGroupDatabase.js 94.73% <ø> (ø)
src/Security/CheckGroups/CheckGroupServerConfig.js 95.23% <ø> (ø)
src/Security/CheckRunner.js 94.82% <83.33%> (ø)
src/Routers/SecurityRouter.js 100.00% <100.00%> (ø)
src/Utils.js 95.74% <100.00%> (ø)
src/batch.js 91.37% <0.00%> (-1.73%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a05e9b1...ac6e2b0. Read the comment docs.

CONTRIBUTING.md Outdated
@@ -114,6 +114,7 @@ Once you have babel running in watch mode, you can start making changes to parse
* Take testing seriously! Aim to increase the test coverage with every pull request. To obtain the test coverage of the project, run: `npm run coverage`
* Run the tests for the file you are working on with the following command: `npm test spec/MyFile.spec.js`
* Run the tests for the whole project to make sure the code passes all tests. This can be done by running the test command for a single file but removing the test file argument. The results can be seen at *<PROJECT_ROOT>/coverage/lcov-report/index.html*.
* Format your code by running `npm run prettier` followed by `npm run lint-fix`.
Copy link
Member

Choose a reason for hiding this comment

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

We could update the prettier command in package.json and add lint-fix to it so that this is one step instead of two.

Copy link
Member

@mtrezza mtrezza Mar 18, 2021

Choose a reason for hiding this comment

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

To chime in, we have had this discussion some time ago and I suggested to keep those two apart for the contributor's benefit to be able to run either one, because prettier can be quite opinionated. Maybe a clean script could execute both?

@dblythy
Copy link
Member Author

dblythy commented Mar 24, 2021

Added npm run clean

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

I think running this manually every time doesn't make much sense, nor does relying on the contributor to run it, and it obfuscates the blame lines.

Lint is currently a CI check, see check-lint action. Should we replace it with check-clean that includes prettier? Also we could think about a pre-commit hook that runs prettier, although I always find it irritating when there are automatic changes before commit.

@dblythy
Copy link
Member Author

dblythy commented Mar 29, 2021

I agree, I think that makes sense. The problem I see with having it run with the CI, is that prettier is often different to lint. So, prettier might throw an error because the format isn't right, when it's actually perfectly fine according to lint-fix (this often happens - prettier changes a file, lint changes it back). How would you see resolving that problem?

I think it makes sense to add prettier into the pre-commit hook, otherwise we're going to continually have contributions that forget to run prettier, even further obfuscating the blame lines as you've said. As far as I know too, a pre-commit hook would only run on affected files.

@mtrezza
Copy link
Member

mtrezza commented Mar 29, 2021

I am pretty sure we had pre-commit hooks at some point, and I didn't like it because it always reformatted the code and made it hard to read in some cases. Prettier is quite opinionated.

So I wonder if we can/should have a final clean up at the end as part of the CI "on merge" that makes a prettier commit.

@dblythy dblythy closed this Aug 4, 2021
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.

3 participants