datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
80 stars 12 forks source link

Add code formatting tests to CI #314

Closed antidipyramid closed 4 months ago

antidipyramid commented 1 year ago

Background

We've added code formatting and linting in the form of pre-commit hooks. Whether a developer would like to use these hooks to automatically format/lint their code is a personal choice. But for uniformity, in PRs we should still test whether new code conforms to the formatting we've agreed to.

This would also ensure our codebases remain uniform in the case that a developer's local formatting tools malfunction.

Proposal

Add black and prettier tests to scripts/run-tests.sh.

Doc Snippets

Prettier:

If you have a CI setup, run the following as part of it to make sure that everyone runs Prettier. This avoids merge conflicts and other collaboration issues!

npx prettier --check .

--check is like --write, but only checks that files are already formatted, rather than overwriting them. prettier --write and prettier --check are the most common ways to run Prettier.

Black:

Writeback and reporting

By default Black reformats the files given and/or found in place. Sometimes you need Black to just tell you what it would do without actually rewriting the Python files.

There’s two variations to this mode that are independently enabled by their respective flags. Both variations can be enabled at once.

Exit code

Passing --check will make Black exit with:

code 0 if nothing would change;

code 1 if some files would be reformatted; or

code 123 if there was an internal error

Deliverables

I'll update the Django and Wagtail templates.

Timeline

Less than one day.