palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
427 stars 46 forks source link

Plugin does not respect IntelliJ's formatter markers #900

Closed jamesdh closed 1 year ago

jamesdh commented 1 year ago

What happened?

IntelliJ (via Settings -> Editor -> Code Style -> Formatter) supports temporarily disabling/enabling code formatting with markers, the default being @formatter:off and @formatter:on. We were evaluating replacing Spotless w/ palantir-java-format, but we have numerous code blocks which we disable code formatting. Spotless respected the default IntelliJ format markers, but PJF does not appear to do so and formats the code anyways.

E.g.

// @formatter:off
http.authorizeHttpRequests(authorize -> authorize
    .requestMatchers(HttpMethod.GET, "/health").permitAll()
    .requestMatchers(HttpMethod.GET, "/providers/searchByUser").hasRole("user")
    .requestMatchers(HttpMethod.GET, "/providers/findByUser").hasRole("user")
);
// @formatter:on

becomes...

// @formatter:off
http.authorizeHttpRequests(authorize -> authorize
        .requestMatchers(HttpMethod.GET, "/health")
        .permitAll()
        .requestMatchers(HttpMethod.GET, "/providers/searchByUser")
        .hasRole("user")
        .requestMatchers(HttpMethod.GET, "/providers/findByUser")
        .hasRole("user"));
// @formatter:on

What did you want to happen?

Standard IntelliJ format markers are respected.

iamdanfox commented 1 year ago

Some existing discussion on https://github.com/palantir/palantir-java-format/issues/653