Skip to content
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

Feature/1135 formatter #1159

Merged
merged 78 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
0d372de
introduce spotless formatter
kcinay055679 Nov 15, 2024
51b41f9
update readme and pipeline
kcinay055679 Nov 15, 2024
f754da4
add typescript formatter
kcinay055679 Nov 18, 2024
19cd044
add frontedn config
kcinay055679 Nov 18, 2024
b9186b9
update tsconfig.json
kcinay055679 Nov 18, 2024
c837bdf
install eslint for formating
kcinay055679 Nov 18, 2024
51dc75a
update typescript-eslint to 8.15.0
Miguel7373 Nov 19, 2024
a7d6009
edit config
Miguel7373 Nov 19, 2024
d84ee2e
put unused-imports plugin into config
Miguel7373 Nov 19, 2024
0d760b3
change config for spec files
Miguel7373 Nov 19, 2024
a018423
add stylistic plugin to eslnt
kcinay055679 Nov 22, 2024
c92dbe9
add eslint stylistic rules
kcinay055679 Nov 22, 2024
cf05568
update config for eslint stylic
kcinay055679 Nov 22, 2024
7a87478
styling indent set to 2
kcinay055679 Nov 22, 2024
732ecc6
add html formatting
kcinay055679 Nov 22, 2024
54ca035
extract eslint format in seperated command
kcinay055679 Nov 22, 2024
91daa77
readd prettier for css json and yaml
kcinay055679 Nov 22, 2024
051c2e7
update eslint config
kcinay055679 Nov 22, 2024
174ee5b
disable check for multipline tenary
kcinay055679 Nov 22, 2024
b454489
refactor config to extract rules to apply only on ts files
kcinay055679 Nov 22, 2024
aa23608
allow arguments
kcinay055679 Nov 22, 2024
f70eafa
Update excluded eslint rules that we want to resolve in follow up ticket
RandomTannenbaum Nov 22, 2024
82a3e86
Fix sentence in readme
RandomTannenbaum Nov 22, 2024
7368658
Allow ts-ignores
RandomTannenbaum Nov 25, 2024
169469f
remove unnecessary comma
Miguel7373 Nov 25, 2024
71545de
Replace javax with jakarta in import order property of formatter
RandomTannenbaum Nov 27, 2024
de1b9d8
get all changes from apply branch
kcinay055679 Dec 9, 2024
ea79473
update precommit hook
kcinay055679 Dec 9, 2024
eeec780
update backend formatter
kcinay055679 Dec 9, 2024
aa20815
update java import order to alphabetically
kcinay055679 Dec 9, 2024
ef544a3
fix backend formatter for annotations
kcinay055679 Dec 9, 2024
567c2c3
update formatting config to fix indentation of annonation params
kcinay055679 Dec 9, 2024
08bf454
update formatter to improve parameter formatting
kcinay055679 Dec 9, 2024
24f16cb
update parameter formatting
kcinay055679 Dec 9, 2024
3fb9ef8
update formatter
kcinay055679 Dec 10, 2024
528811c
add space after array initializer
kcinay055679 Dec 10, 2024
da8aad6
update precommit hook
kcinay055679 Dec 10, 2024
e6a7b0a
precommit hook only updates changed files
kcinay055679 Dec 10, 2024
974932e
clean up pre-commit hook
kcinay055679 Dec 10, 2024
c14441b
remove accidently added fiels
kcinay055679 Dec 10, 2024
83cd400
remove objective from this pr
kcinay055679 Dec 10, 2024
acfcfbc
add verbose option to git add in precommit hook
kcinay055679 Dec 10, 2024
9ab17c9
remove objective model from pr
kcinay055679 Dec 10, 2024
a66f0ff
remove debug log
kcinay055679 Dec 10, 2024
6c79f0c
restore objective model
kcinay055679 Dec 10, 2024
73c99ce
add angular eslint config
kcinay055679 Dec 10, 2024
24ab36a
clean up frontend formatter config
kcinay055679 Dec 10, 2024
5837369
add scss to eslint config
kcinay055679 Dec 10, 2024
f3322bb
rename npm scripts
kcinay055679 Dec 10, 2024
889a8ac
use json eslint plugin and remove prettier
kcinay055679 Dec 10, 2024
e630a67
use prettier again to format scss
kcinay055679 Dec 12, 2024
6c5de0d
add prettierignore file
kcinay055679 Dec 12, 2024
80a9435
configure prettier
kcinay055679 Dec 12, 2024
1434bba
update precommit hook to use prettier
kcinay055679 Dec 12, 2024
f99a5ed
replace new lines with space to read changed files
kcinay055679 Dec 12, 2024
ebfa885
exclude files without extension from formatting
kcinay055679 Dec 12, 2024
26a6633
fix pre-commit hook
kcinay055679 Dec 12, 2024
c2e9a95
update name of package scripts and update workflow
kcinay055679 Dec 12, 2024
a6e33dc
readd ignored files to prettierrc
kcinay055679 Dec 13, 2024
f406925
clean up
kcinay055679 Dec 13, 2024
178b6da
clean up
kcinay055679 Dec 13, 2024
a4017d0
remove logs from pre-commit
kcinay055679 Dec 13, 2024
6614167
remove files from pr
kcinay055679 Dec 13, 2024
edaae05
update frontend config
kcinay055679 Dec 13, 2024
e9285a3
allow empty constructors
kcinay055679 Dec 13, 2024
a897a70
update config
kcinay055679 Dec 13, 2024
94e04f0
update prettirrc
kcinay055679 Dec 13, 2024
3ed2b96
update config
kcinay055679 Dec 13, 2024
0063826
use old html formatter
kcinay055679 Dec 13, 2024
4cbf376
rmeove xargs from precommit hook
kcinay055679 Dec 16, 2024
5cf16c1
update config for html files
kcinay055679 Dec 16, 2024
07de984
updat package lock
kcinay055679 Dec 18, 2024
b9fa2e3
clean up eslint config and packages
kcinay055679 Dec 19, 2024
bd35499
change formatting dependencies to dev dep and regen package-lock
kcinay055679 Dec 19, 2024
7de2ef5
update formatter
kcinay055679 Dec 20, 2024
7d457b7
update frontend formatter
kcinay055679 Dec 20, 2024
8378a80
update formatter
kcinay055679 Dec 20, 2024
7734450
Feature/1135 Apply Formatters (#1221)
RandomTannenbaum Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
47 changes: 8 additions & 39 deletions .github/workflows/format-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: 'Format'
on: [push]
jobs:

Frontend:
frontend:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -15,33 +15,19 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.10.0
node-version: ${{vars.NODE_VERSION}}

- name: Npm install
run: npm ci

- name: Format frontend
run: npm run format
run: npm run check-linting:all

- name: Commit and Push formated frontend
shell: bash
env:
COMMITPREFIX: '[FM]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add . || {
echo "No files were changed, so we did not commit anything"
exit 1
}
git commit -m "$COMMITPREFIX Automated formating frontend" || {
echo "No changes to commit, skipping push"
exit 0
}
git push -f

Backend:
backend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -55,21 +41,4 @@ jobs:
settings-path: ${{github.workspace}}

- name: Format backend
run: mvn formatter:format -f backend/pom.xml

- name: Commit and Push formated backend
shell: bash
env:
COMMITPREFIX: '[FM]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add . || {
echo "No files were changed, so we did not commit anything"
exit 1
}
git commit -m "$COMMITPREFIX Automated formating backend" || {
echo "No changes to commit, skipping push"
exit 0
}
git push -f
run: mvn spotless:check
18 changes: 12 additions & 6 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ USING DOCKER
- backend/target

Formatting:
- Check code formatting: `mvn formatter:validate`
- Format the code: `mvn formatter:format`
- Check code formatting: `mvn spotless:check`
- Format the code: `mvn spotless:apply`
Miguel7373 marked this conversation as resolved.
Show resolved Hide resolved

The `compile` goal execute also a `formatter:format` goal.
We also run the formatter with `spotless:apply` in the `compile` goal.

Verify the Backend for coverage check:
- `mvn clean verify`

## Formatting
We use the **formatter-maven-plugin** Plugin for formatting the Java code:
https://code.revelc.net/formatter-maven-plugin/

We use the ***spotless*** Plugin for formatting the Java code:
https://github.com/diffplug/spotless

### How to update the spotless configuration using intelij:
- Open `Go to Settings -> Editor -> Code styles -> Java`
- Select the default project config and export it to a file
- Then make the changes you want to the code style config ***HIT APPLY*** and then export it to a file
- Then run the following command `git --no-pager diff --no-index -U0 default.xml changed.xml | egrep '^\+' | diff-so-fancy` to see the changes
- then copy all additions to the formatter file in the backend project
## Build
_tbd_
31 changes: 18 additions & 13 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,29 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
</plugin>

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<configuration>
<compilerSource>${maven.compiler.source}</compilerSource>
<compilerCompliance>${maven.compiler.source}</compilerCompliance>
<compilerTargetPlatform>${maven.compiler.source}</compilerTargetPlatform>
</configuration>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<executions>
<execution>
<id>code-format</id>
<goals>
<goal>format</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<java>
<eclipse>
<version>4.26</version>
<file>${project.basedir}/src/main/resources/formatting.xml</file>
<!-- <file>${project.basedir}/src/main/resources/formatters/default.xml</file>-->
</eclipse>
<removeUnusedImports />
<importOrder />
</java>
</configuration>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -305,9 +310,9 @@
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<executions>
<execution>
<id>code-format</id>
Expand Down
17 changes: 8 additions & 9 deletions backend/src/main/java/ch/puzzle/okr/Constants.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ch.puzzle.okr;

import static java.util.Map.entry;

import ch.puzzle.okr.dto.checkin.*;
import ch.puzzle.okr.dto.keyresult.*;

import java.util.Map;

import static java.util.Map.entry;

public class Constants {
private Constants() {
}
Expand All @@ -29,11 +28,11 @@ private Constants() {
public static final String CHECK_IN_KEY_RESULT_ID_ATTRIBUTE_NAME = "keyResultId";
public static final String KEY_RESULT_TYPE_ATTRIBUTE_NAME = "keyResultType";

public static final Map<String, Class<? extends KeyResultDto>> KEY_RESULT_MAP = Map.ofEntries(
entry(KEY_RESULT_TYPE_METRIC, KeyResultMetricDto.class),
entry(KEY_RESULT_TYPE_ORDINAL, KeyResultOrdinalDto.class));
public static final Map<String, Class<? extends KeyResultDto>> KEY_RESULT_MAP = Map
.ofEntries(entry(KEY_RESULT_TYPE_METRIC, KeyResultMetricDto.class),
entry(KEY_RESULT_TYPE_ORDINAL, KeyResultOrdinalDto.class));

public static final Map<String, Class<? extends CheckInDto>> CHECK_IN_MAP = Map.ofEntries(
entry(KEY_RESULT_TYPE_METRIC, CheckInMetricDto.class),
entry(KEY_RESULT_TYPE_ORDINAL, CheckInOrdinalDto.class));
public static final Map<String, Class<? extends CheckInDto>> CHECK_IN_MAP = Map
.ofEntries(entry(KEY_RESULT_TYPE_METRIC, CheckInMetricDto.class),
entry(KEY_RESULT_TYPE_ORDINAL, CheckInOrdinalDto.class));
}
22 changes: 18 additions & 4 deletions backend/src/main/java/ch/puzzle/okr/ErrorKey.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package ch.puzzle.okr;

public enum ErrorKey {
ATTRIBUTE_NULL, ATTRIBUTE_CHANGED, ATTRIBUTE_SET_FORBIDDEN, ATTRIBUTE_NOT_SET, ATTRIBUTE_CANNOT_CHANGE,
ATTRIBUTE_MUST_BE_DRAFT, KEY_RESULT_CONVERSION, ALREADY_EXISTS_SAME_NAME, CONVERT_TOKEN, DATA_HAS_BEEN_UPDATED,
MODEL_NULL, MODEL_WITH_ID_NOT_FOUND, NOT_AUTHORIZED_TO_READ, NOT_AUTHORIZED_TO_WRITE, NOT_AUTHORIZED_TO_DELETE,
TOKEN_NULL, TRIED_TO_DELETE_LAST_ADMIN, TRIED_TO_REMOVE_LAST_OKR_CHAMPION
ATTRIBUTE_NULL,
ATTRIBUTE_CHANGED,
ATTRIBUTE_SET_FORBIDDEN,
ATTRIBUTE_NOT_SET,
ATTRIBUTE_CANNOT_CHANGE,
ATTRIBUTE_MUST_BE_DRAFT,
KEY_RESULT_CONVERSION,
ALREADY_EXISTS_SAME_NAME,
CONVERT_TOKEN,
DATA_HAS_BEEN_UPDATED,
MODEL_NULL,
MODEL_WITH_ID_NOT_FOUND,
NOT_AUTHORIZED_TO_READ,
NOT_AUTHORIZED_TO_WRITE,
NOT_AUTHORIZED_TO_DELETE,
TOKEN_NULL,
TRIED_TO_DELETE_LAST_ADMIN,
TRIED_TO_REMOVE_LAST_OKR_CHAMPION
}
5 changes: 1 addition & 4 deletions backend/src/main/java/ch/puzzle/okr/ForwardFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;

import java.io.IOException;
import java.util.Arrays;

public class ForwardFilter extends GenericFilterBean {

private static final Logger logger = LoggerFactory.getLogger(ForwardFilter.class);
Expand Down
3 changes: 1 addition & 2 deletions backend/src/main/java/ch/puzzle/okr/OkrErrorAttributes.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ch.puzzle.okr;

import ch.puzzle.okr.exception.OkrResponseStatusException;
import java.util.Map;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

@Component
public class OkrErrorAttributes extends DefaultErrorAttributes {

Expand Down
12 changes: 9 additions & 3 deletions backend/src/main/java/ch/puzzle/okr/OpenAPI30Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ public class OpenAPI30Configuration {
@Bean
public OpenAPI customizeOpenAPI() {
final String securitySchemeName = "bearerAuth";
return new OpenAPI().addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
.components(new Components().addSecuritySchemes(securitySchemeName, new SecurityScheme()
.name(securitySchemeName).type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")));
return new OpenAPI()
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
.components(new Components()
.addSecuritySchemes(securitySchemeName,
new SecurityScheme()
.name(securitySchemeName)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")));
}

}
56 changes: 29 additions & 27 deletions backend/src/main/java/ch/puzzle/okr/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package ch.puzzle.okr;

import static org.springframework.security.web.header.writers.CrossOriginEmbedderPolicyHeaderWriter.CrossOriginEmbedderPolicy.REQUIRE_CORP;
import static org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter.ReferrerPolicy.NO_REFERRER;
import static org.springframework.security.web.header.writers.XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK;

import com.nimbusds.jose.proc.SecurityContext;
import com.nimbusds.jwt.proc.ConfigurableJWTProcessor;
import com.nimbusds.jwt.proc.DefaultJWTProcessor;
Expand Down Expand Up @@ -33,10 +37,6 @@
import org.springframework.security.web.header.writers.CrossOriginResourcePolicyHeaderWriter;
import org.springframework.security.web.header.writers.StaticHeadersWriter;

import static org.springframework.security.web.header.writers.CrossOriginEmbedderPolicyHeaderWriter.CrossOriginEmbedderPolicy.REQUIRE_CORP;
import static org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter.ReferrerPolicy.NO_REFERRER;
import static org.springframework.security.web.header.writers.XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK;

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
Expand All @@ -58,10 +58,12 @@ public SecurityFilterChain apiSecurityFilterChain(HttpSecurity http, @Value("${c
http.addFilterAfter(new ForwardFilter(), BasicAuthenticationFilter.class);
logger.debug("*** apiSecurityFilterChain reached");
setHeaders(http);
return http.cors(Customizer.withDefaults())
return http
.cors(Customizer.withDefaults())
.authorizeHttpRequests(e -> e.requestMatchers("/api/**").authenticated().anyRequest().permitAll())
.exceptionHandling(e -> e.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED)))
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults())).build();
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
.build();
}

@Bean
Expand All @@ -75,14 +77,15 @@ JWTProcessor<SecurityContext> jwtProcessor(JWTClaimsSetAwareJWSKeySelector<Secur
JwtDecoder jwtDecoder(JWTProcessor<SecurityContext> jwtProcessor, OAuth2TokenValidator<Jwt> jwtValidator) {
NimbusJwtDecoder decoder = new NimbusJwtDecoder(jwtProcessor);
OAuth2TokenValidator<Jwt> validator = new DelegatingOAuth2TokenValidator<>(JwtValidators.createDefault(),
jwtValidator);
jwtValidator);
decoder.setJwtValidator(validator);
return decoder;
}

private HttpSecurity setHeaders(HttpSecurity http) throws Exception {
return http
.headers(headers -> headers.contentSecurityPolicy(c -> c.policyDirectives(okrContentSecurityPolicy()))
.headers(headers -> headers
.contentSecurityPolicy(c -> c.policyDirectives(okrContentSecurityPolicy()))
.crossOriginEmbedderPolicy(c -> c.policy(REQUIRE_CORP))
.crossOriginOpenerPolicy(c -> c.policy(OPENER_SAME_ORIGIN))
.crossOriginResourcePolicy(c -> c.policy(RESOURCE_SAME_ORIGIN))
Expand All @@ -96,32 +99,31 @@ private HttpSecurity setHeaders(HttpSecurity http) throws Exception {

private String okrContentSecurityPolicy() {
return "default-src 'self';" //
+ "script-src 'self' 'unsafe-inline';" //
+ " style-src 'self' 'unsafe-inline';" //
+ " object-src 'none';" //
+ " base-uri 'self';" //
+ " connect-src 'self' " + connectSrc + ";" //
+ " font-src 'self';" //
+ " frame-src 'self';" //
+ " img-src 'self' data: ;" //
+ " manifest-src 'self';" //
+ " media-src 'self';" //
+ " worker-src 'none';"; //
+ "script-src 'self' 'unsafe-inline';" //
+ " style-src 'self' 'unsafe-inline';" //
+ " object-src 'none';" //
+ " base-uri 'self';" //
+ " connect-src 'self' " + connectSrc + ";" //
+ " font-src 'self';" //
+ " frame-src 'self';" //
+ " img-src 'self' data: ;" //
+ " manifest-src 'self';" //
+ " media-src 'self';" //
+ " worker-src 'none';"; //
}

private String okrPermissionPolicy() {
return "accelerometer=(), ambient-light-sensor=(), autoplay=(), "
+ "battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), "
+ "execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(),"
+ " geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), "
+ "midi=(), navigation-override=(), payment=(), picture-in-picture=(),"
+ " publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(self), "
+ "usb=(), web-share=(), xr-spatial-tracking=()";
+ "battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), "
+ "execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(),"
+ " geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), "
+ "midi=(), navigation-override=(), payment=(), picture-in-picture=(),"
+ " publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(self), "
+ "usb=(), web-share=(), xr-spatial-tracking=()";
}

@Bean
public AuthenticationEventPublisher authenticationEventPublisher(
ApplicationEventPublisher applicationEventPublisher) {
public AuthenticationEventPublisher authenticationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
return new DefaultAuthenticationEventPublisher(applicationEventPublisher);
}

Expand Down
3 changes: 1 addition & 2 deletions backend/src/main/java/ch/puzzle/okr/UserKeyGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import ch.puzzle.okr.models.User;
import ch.puzzle.okr.multitenancy.TenantContext;
import org.springframework.cache.interceptor.KeyGenerator;

import java.lang.reflect.Method;
import java.text.MessageFormat;
import org.springframework.cache.interceptor.KeyGenerator;

public class UserKeyGenerator implements KeyGenerator {
@Override
Expand Down
Loading
Loading