Enforce code formatting via Prettier #44

Merged
tozh4728 merged 6 commits from prettier into develop 2024-12-02 14:18:04 +01:00
Owner

Fixes #43 by introducing Prettier.

Prettier is an extremely opinionated formatter. It will reformat every single line according to its style. There are virtually no configuration options so there can be no discussion about formatting rules.

There are two parameters that are configurable; indent length and line length. Indent length has been set to 4 because that's the Java standard.

Line length defaults to 80 but has been increased to 100. The rational for this is that Prettier was created for JavaScript which is much less verbose than Java. Not only does every Java line start with 8 spaces of indentation vs. JavaScripts 0 or 2, it also has types wile JavaScript does not and uses const for variable declarations. Compare the two below examples as well as an actual example from the source code that is too long for the default 80 characters. I have no problem dropping down to the default 80 if that is preferred I just felt that with the average length of a line of Java code being pretty long, excessive wrapping would reduce readability.

  const attributes = {
    ...
  };
        Map<String, String> attributes = Map.of(
            ...
        );

Or the following real code which is 97 characters long.

        Set<ProjectParticipant> contributors = daisyAPI.getContributors(project.getIdentifier());
Fixes #43 by introducing [Prettier](https://prettier.io/). Prettier is an extremely opinionated formatter. It will reformat every single line according to its style. There are virtually no configuration options so there can be no discussion about formatting rules. There are two parameters that are configurable; indent length and line length. Indent length has been set to 4 because that's the Java standard. Line length defaults to 80 but has been increased to 100. The rational for this is that Prettier was created for JavaScript which is much less verbose than Java. Not only does every Java line start with 8 spaces of indentation vs. JavaScripts 0 or 2, it also has types wile JavaScript does not and uses `const` for variable declarations. Compare the two below examples as well as an actual example from the source code that is too long for the default 80 characters. I have no problem dropping down to the default 80 if that is preferred I just felt that with the average length of a line of Java code being pretty long, excessive wrapping would reduce readability. ```javascript const attributes = { ... }; ``` ```java Map<String, String> attributes = Map.of( ... ); ``` Or the following real code which is 97 characters long. ```java Set<ProjectParticipant> contributors = daisyAPI.getContributors(project.getIdentifier()); ```
ansv7779 added 2 commits 2024-11-29 13:48:54 +01:00
The formatting is validated during the Maven phase `verify` (on the parent project so the absolute first thing that happens). There is no automated reformatting done in the default lifecycle but there are instructions on how to execute it.

Prettier is *very* opinionated with no configuration options.
Run Prettier on the entire project
All checks were successful
Build and test / build-and-test (push) Successful in 7m19s
98c5f51ffa
Owner

I agree that 100 characters is a good balance for readability and how much screen real estate it takes up in our development environments.

I agree that 100 characters is a good balance for readability and how much screen real estate it takes up in our development environments.
Owner

I suggest 120 characters, screens are big today, and Java is verbose.

I suggest 120 characters, screens are big today, and Java is verbose.
ansv7779 added 2 commits 2024-12-02 10:59:10 +01:00
Reformat with 120 line length
All checks were successful
Build and test / build-and-test (push) Successful in 11m52s
b599ab9a94
ansv7779 added 1 commit 2024-12-02 11:13:56 +01:00
Merge branch 'develop' into prettier
All checks were successful
Build and test / build-and-test (push) Successful in 9m48s
b2bcabdb55
# Conflicts:
#	core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmissionRepositoryImpl.java
ansv7779 added 1 commit 2024-12-02 12:41:32 +01:00
Merge branch 'develop' into prettier
All checks were successful
Build and test / build-and-test (push) Successful in 7m5s
b6e54c525e
# Conflicts:
#	core/src/main/java/se/su/dsv/scipro/daisyExternal/http/DaisyAPIImpl.java
#	daisy-integration/src/main/java/se/su/dsv/scipro/integration/daisy/workers/ProjectExporter.java
ansv7779 changed title from WIP: Enforce code formatting via Prettier to Enforce code formatting via Prettier 2024-12-02 12:49:11 +01:00
Author
Owner

Once merged, if anyone has work that will cause conflicts, since this is just formatting changes, discard the remote changes and keep your own and then re-run formatting to fix those files with your local changes intact.

Once merged, if anyone has work that will cause conflicts, since this is just formatting changes, discard the remote changes and keep your own and then re-run formatting to fix those files with your local changes intact.
tozh4728 approved these changes 2024-12-02 14:17:50 +01:00
tozh4728 merged commit 1554d4bc27 into develop 2024-12-02 14:18:04 +01:00
tozh4728 deleted branch prettier 2024-12-02 14:18:05 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: DMC/scipro#44
No description provided.