Skip to content

Commit

Permalink
Feature/refactor formatter (#111)
Browse files Browse the repository at this point in the history
* refactor formatter

* add html files to spotless plugin

* run formatter

* update workflow and git hook

* update pretterrc

* remove old formatter

* Apply formatter

* Add prettier ignore to doctype tags to stop formatting

* Remove comments

* Format code

* Bring back upper case doctypes and add prettier ignore to them

* Add missing attributes to pages

* Format code and add missing attributs after rebase
  • Loading branch information
kcinay055679 authored Oct 3, 2024
1 parent f2a3e85 commit 5894cac
Show file tree
Hide file tree
Showing 33 changed files with 363 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate-formatting-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
java-version: '21'
distribution: 'oracle'
- name: Validate that the code is formatted correctly
run: mvn formatter:validate
run: mvn spotless:check
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tabWidth": 4,
"useTabs": false,
"printWidth": 80,
"htmlWhitespaceSensitivity": "ignore",
"bracketSameLine": true,
"endOfLine": "lf"
}
44 changes: 33 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,45 @@
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<configuration>
<compilerSource>21</compilerSource>
<compilerCompliance>21</compilerCompliance>
<compilerTargetPlatform>21</compilerTargetPlatform>
<lineEnding>LF</lineEnding>
<configFile>${project.basedir}/src/main/resources/formatting.xml</configFile>
</configuration>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
<executions>
<execution>
<goals>
<goal>format</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<formats>
<format>
<includes>
<include>src/main/resources/**/*.css</include>
<include>src/main/resources/**/*.html</include>
</includes>
<excludes>
<exclude>src/main/resources/static/styles/bootstrap.min.css</exclude>
</excludes>
<prettier>
<prettierVersion>3.3.3</prettierVersion>
<configFile>${project.basedir}/.prettierrc</configFile>
</prettier>
</format>
</formats>
<java>
<eclipse>
<version>4.26</version>
<file>${project.basedir}/src/main/resources/formatting.xml</file>
</eclipse>
<removeUnusedImports />
<importOrder>
<order>java|javax,ch.puzzle,org,com,com.diffplug,,\#com.diffplug,\#</order>
<semanticSort>true</semanticSort>
</importOrder>
<formatAnnotations />
</java>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

addedFiles=$(git diff --cached --name-only --diff-filter=d)
mvn formatter:format
mvn spotless:apply
git add $addedFiles
3 changes: 2 additions & 1 deletion src/main/java/ch/puzzle/eft/ExamFeedbackToolApplication.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ch.puzzle.eft;

import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;

@SpringBootApplication
public class ExamFeedbackToolApplication {

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/ch/puzzle/eft/controller/ExamController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ch.puzzle.eft.controller;

import java.io.ByteArrayOutputStream;
import java.io.File;

import ch.puzzle.eft.service.ExamService;

import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.io.ByteArrayOutputStream;
import java.io.File;

@RestController
@RequestMapping("/exams")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@


import ch.puzzle.eft.model.ErrorModel;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
Expand All @@ -14,6 +13,9 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.resource.NoResourceFoundException;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

@ControllerAdvice
@Controller
public class ExceptionController implements ErrorController {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/ch/puzzle/eft/controller/SiteController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ch.puzzle.eft.controller;

import java.time.Duration;
import java.util.Objects;

import ch.puzzle.eft.model.ExamNumberForm;
import ch.puzzle.eft.service.ExamService;
import jakarta.validation.Valid;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
Expand All @@ -15,8 +18,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.server.ResponseStatusException;

import java.time.Duration;
import java.util.Objects;
import jakarta.validation.Valid;

@Controller
public class SiteController {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/puzzle/eft/model/ExamModel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ch.puzzle.eft.model;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

import java.io.File;

public class ExamModel {
private final File file;
private static final Logger logger = LoggerFactory.getLogger(ExamModel.class);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/ch/puzzle/eft/service/ExamService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package ch.puzzle.eft.service;

import ch.puzzle.eft.model.ExamModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -17,6 +9,15 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import ch.puzzle.eft.model.ExamModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

@Service
public class ExamService {
private static final Logger logger = LoggerFactory.getLogger(ExamService.class);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/puzzle/eft/service/ValidationService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ch.puzzle.eft.service;

import org.springframework.stereotype.Service;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Service;

@Service
public class ValidationService {
private static final Pattern EXAM_NUMBER_PATTERN = Pattern.compile("^\\d{5}$");
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/static/styles/cookie-consent-popup.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.modal {
background-color: rgba(0, 0, 0, 0.5);
}
.modal-header{
.modal-header {
border-color: var(--primary-hex);
}
.modal-footer{
.modal-footer {
border-color: var(--primary-hex);
}
}
57 changes: 42 additions & 15 deletions src/main/resources/static/styles/custom_bootstrap.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
:root {
--primary-rgb: 229, 0, 125;
--primary-hex: rgba(var(--bs-primary-rgb),1);
--primary-hex: rgba(var(--bs-primary-rgb), 1);
/*bootstrap*/
--bs-primary-rgb: var(--primary-rgb);
--bs-secondary-rgb: 0, 0,0;
--bs-secondary-rgb: 0, 0, 0;


--bs-primary-link-hover-color-rgb: 0,0,0;
--bs-primary-link-hover-color-rgb: 0, 0, 0;
--bs-secondary-link-hover-color-rgb: var(--bs-primary-rgb);

--button-primary-color: var(--primary-hex);
--button-primary-hover-color:rgb( 240, 38, 144);
--button-primary-hover-color: rgb(240, 38, 144);
}

.btn-outline-primary {
Expand Down Expand Up @@ -48,19 +47,47 @@
/*Attention: The focus style must be defined before the hover style or it will break*/

.link-primary:focus {
color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-opacity, 1)) !important;
-webkit-text-decoration-color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
text-decoration-color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-opacity, 1)
) !important;
-webkit-text-decoration-color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
text-decoration-color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
}

.link-secondary:focus, .link-primary:hover {
color: RGBA(var(--bs-primary-link-hover-color-rgb), var(--bs-link-opacity, 1)) !important;
-webkit-text-decoration-color: RGBA(var(--bs-primary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
text-decoration-color: RGBA(var(--bs-primary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
.link-secondary:focus,
.link-primary:hover {
color: RGBA(
var(--bs-primary-link-hover-color-rgb),
var(--bs-link-opacity, 1)
) !important;
-webkit-text-decoration-color: RGBA(
var(--bs-primary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
text-decoration-color: RGBA(
var(--bs-primary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
}

.link-secondary:hover {
color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-opacity, 1)) !important;
-webkit-text-decoration-color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
text-decoration-color: RGBA(var(--bs-secondary-link-hover-color-rgb), var(--bs-link-underline-opacity, 1)) !important;
color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-opacity, 1)
) !important;
-webkit-text-decoration-color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
text-decoration-color: RGBA(
var(--bs-secondary-link-hover-color-rgb),
var(--bs-link-underline-opacity, 1)
) !important;
}
2 changes: 1 addition & 1 deletion src/main/resources/static/styles/header.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#logo {
height: 70px;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/static/styles/search.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.content {
padding-bottom: 6rem;
}
}
8 changes: 4 additions & 4 deletions src/main/resources/static/styles/styles.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@font-face {
font-family: 'OpenSans';
font-family: "OpenSans";
src:
local('OpenSans Regular'),
url('../fonts/Open_Sans/OpenSans-Regular.ttf') format('truetype'),
url('../fonts/Open_Sans/OpenSans-Regular.woff2') format('woff2');
local("OpenSans Regular"),
url("../fonts/Open_Sans/OpenSans-Regular.ttf") format("truetype"),
url("../fonts/Open_Sans/OpenSans-Regular.woff2") format("woff2");
font-weight: normal;
font-style: normal;
}
Expand Down
28 changes: 18 additions & 10 deletions src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<!--prettier-ignore-->
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout.html}" lang="">
<body>
<section layout:fragment="content">
<div th:replace="~{fragments/internal-server-error}"></div>
<div th:replace="~{fragments/not-found-error}"></div>
<a data-testid="back-to-main-page" href="/return" class="link-secondary">Zurück zur Startseite</a>
</section>
</body>
</html>
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout.html}"
lang="de">
<body>
<section layout:fragment="content">
<div th:replace="~{fragments/internal-server-error}"></div>
<div th:replace="~{fragments/not-found-error}"></div>
<a
data-testid="back-to-main-page"
href="/return"
class="link-secondary">
Zurück zur Startseite
</a>
</section>
</body>
</html>
Loading

0 comments on commit 5894cac

Please sign in to comment.