DSM-168: Prettier setup, CI step and frontend format#72
Merged
Conversation
…licts between eslint and prettier
…ettier on routes and entrypoints subdirectories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket DSM-168
Overview
This PR adds the Prettier code formatter to the repository, includes it in a CI task, and formats the entire frontend app (
app/s3browserandapp/javascript/entrypointsdirectories).Prettier config
Prettier configuration is as follows:
{ "trailingComma": "all", // default; adds a trailing comma to multi-line arrays, function parameters and calls "tabWidth": 2, // default "useTabs": false, // default "semi": true, // default; adds a semicolon at the end of every statement. "singleQuote": true, // use single quotes, jsx/tsx keeps double quotes to maintain HTML-like formatting "printWidth": 100 // explained below }Some of these are Prettier defaults, but they were kept explicit for clarity, as we're testing the use of Prettier in our apps.
Print Width
Print width is probably the most discussed setting. Prettier docs recommend a width of 80; however, the team wanted to increase the width to prevent breaking up smaller pieces of code. Since
printWidthis treated by Prettier as a rough length of the line, not max length, a limit too high causes Prettier to merge lines that would more naturally be broken up.CI check
A Prettier check was added to an existing CI rake task. This is a check-only step (similar to how we use Rubocop in CI) and does not perform any actual formatting. Ideally, every developer should configure their code editor to format on save. We can also explore pre-commit hooks, though they can discourage frequent commits, which is worth avoiding.
Local Prettier settings
The following VSCode settings configure Prettier as the default formatter for .ts, .tsx, and .js files.