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

Add code formatter and linter #140

Merged
merged 4 commits into from
Jun 14, 2024
Merged

Add code formatter and linter #140

merged 4 commits into from
Jun 14, 2024

Conversation

Huulivoide
Copy link
Contributor

@Huulivoide Huulivoide commented Jun 12, 2024

Add Spotless with Palantir style for Java formatting

Add Cleanthat to Spotless config

Codebase is already following the wast majority of the enabled rules/mutators. Config uses Composite mutators, that map to the following list of mutators:

  • ArithmethicAssignment
  • ArraysDotStream
  • AvoidMultipleUnaryOperators
  • AvoidUncheckedExceptionsInSignatures
  • CastMathOperandsBeforeAssignement
  • CollectionIndexOfToContains
  • CollectionToOptional
  • ComparisonWithNaN
  • CreateTempFilesUsingNio
  • EmptyControlStatement
  • EnumsWithoutEquals
  • ForEachAddToStreamCollectToCollection
  • ForEachIfBreakElseToStreamTakeWhile
  • ForEachIfBreakToStreamFindFirst
  • ForEachIfToIfStreamAnyMatch
  • ForEachToIterableForEach
  • GuavaImmutableMapBuilderOverVarargs
  • GuavaInlineStringsRepeat
  • GuavaInlineStringsRepeat
  • GuavaStringsIsNullOrEmpty
  • LambdaIsMethodReference
  • LambdaReturnsSingleStatement
  • LiteralsFirstInComparisons
  • LocalVariableTypeInference
  • LoopIntRangeToIntStreamForEach
  • ModifierOrder
  • ObjectEqualsForPrimitives
  • ObjectsHashCodePrimitive
  • OptionalNotEmpty
  • OptionalWrappedIfToFilter
  • OptionalWrappedVariableToMap
  • PrimitiveWrapperInstantiation
  • RedundantLogicalComplementsInStream
  • RemoveAllToClearCollection
  • RemoveExplicitCallToSuper
  • SimplifyBooleanExpression
  • SimplifyBooleanInitialization
  • SimplifyStartsWith
  • StreamAnyMatch
  • StreamFlatMapStreamToFlatMap
  • StreamForEachNestingForLoopToFlatMap
  • StreamMapIdentity
  • StreamWrappedIfToFilter
  • StreamWrappedMethodRefToMap
  • StreamWrappedVariableToMap
  • StringIndexOfToContains
  • StringReplaceAllWithQuotableInput
  • StringToString
  • ThreadRunToThreadStart
  • UnnecessaryBoxing
  • UnnecessaryFullyQualifiedName
  • UnnecessaryImport
  • UnnecessaryLambdaEnclosingParameters
  • UnnecessaryModifier
  • UnnecessarySemicolon
  • UseCollectionIsEmpty
  • UseIndexOfChar
  • UseStringIsEmpty
  • UseTextBlocks

This change is Reviewable

Copy link
Contributor

@jarkkoka jarkkoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good change! Always preferred a consistent code style. The formatting of the comments is mostly ok, but there are also strange formatting in a few places. I left some remarks.

Reviewed 442 of 442 files at r1, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @Huulivoide)


src/main/java/fi/hsl/jore/importer/config/jooq/converter/date_range/DateRange.java line 29 at r1 (raw file):

        // See section 8.17.7:
        // > The built-in range types int4range, int8range, and daterange all use a canonical form
        // that includes the

This needs manual intervention. Use of > does not go as originally intended.


src/main/java/fi/hsl/jore/importer/feature/batch/line/support/LineImportRepository.java line 88 at r1 (raw file):

        // TODO: At the moment we don't have any updatable fields in the NETWORK_LINES tables,
        //       but this may change when we decide how to handle e.g. PublicTransportDestination
        // fields

inconsistent indentation


src/main/java/fi/hsl/jore/importer/feature/batch/route_link/RouteLinksReader.java line 108 at r1 (raw file):

                return ImmutableReaderState.copyOf(this)
                        // We _must_ update the attributes, because while some of the fields (joined
                        // from the

The lines could be joined in a better way. Only two short words on one line.


src/main/java/fi/hsl/jore/importer/feature/batch/route_link/RoutePointConstructor.java line 33 at r1 (raw file):

                entity.routeLinks()
                        // The order number property is NOT guaranteed to be strictly incremental by
                        // 1,

Here again. This could be more readable. Needs manual intervention.


src/main/java/fi/hsl/jore/importer/feature/mapmatching/dto/request/MapMatchingRequestBuilder.java line 91 at r1 (raw file):

                                                                                    + " the route"
                                                                                    + " point is"
                                                                                    + " stop point"

Whoops! Not the most readable form. :D


src/main/java/fi/hsl/jore/importer/feature/network/route_point/repository/RoutePointExportRepository.java line 76 at r1 (raw file):

                                                                .and(
                                                                        length(
                                                                                        SCHEDULED_STOP_POINTS

Feels a bit too sparse, but probably nothing can be done with this style configuration...


src/test/java/fi/hsl/jore/importer/feature/batch/link/support/TransitTypeToNetworkTypeMapperTest.java line 24 at r1 (raw file):

    public void testEachNetworkTypeSupported() {
        // Note that at the moment there is a comprehensive 1:1 mapping from
        // TransitType->NetworkType,

These lines could be joined in a better way.

@Huulivoide Huulivoide force-pushed the AddCodeFormatterAndLinter branch 3 times, most recently from daf9d90 to f62158a Compare June 13, 2024 10:43
Copy link
Contributor

@jarkkoka jarkkoka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Palantir" style :lgtm_strong:

Reviewed 286 of 286 files at r2, all commit messages.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @Huulivoide)


pom.xml line 712 at r2 (raw file):

                        </cleanthat>

                        <!-- Format the code according to Plantir code style. -->

typo => "Palantir"


.github/workflows/spotless.yml line 24 at r2 (raw file):

      - name: Cache Maven packages
        uses: actions/cache@v3

=> actions/cache@v4. v4 is the most recent version.

@Huulivoide Huulivoide force-pushed the AddCodeFormatterAndLinter branch from f62158a to 82aa5a5 Compare June 13, 2024 14:44
Copy link
Contributor Author

@Huulivoide Huulivoide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 445 of 449 files reviewed, 8 unresolved discussions (waiting on @jarkkoka)


.github/workflows/spotless.yml line 24 at r2 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

=> actions/cache@v4. v4 is the most recent version.

Done.


src/main/java/fi/hsl/jore/importer/feature/batch/line/support/LineImportRepository.java line 88 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

inconsistent indentation

Done.


src/main/java/fi/hsl/jore/importer/feature/batch/route_link/RouteLinksReader.java line 108 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

The lines could be joined in a better way. Only two short words on one line.

Done.


src/main/java/fi/hsl/jore/importer/feature/batch/route_link/RoutePointConstructor.java line 33 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

Here again. This could be more readable. Needs manual intervention.

Done.


src/main/java/fi/hsl/jore/importer/feature/mapmatching/dto/request/MapMatchingRequestBuilder.java line 91 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

Whoops! Not the most readable form. :D

Done.


src/main/java/fi/hsl/jore/importer/feature/network/route_point/repository/RoutePointExportRepository.java line 76 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

Feels a bit too sparse, but probably nothing can be done with this style configuration...

Done.


src/test/java/fi/hsl/jore/importer/feature/batch/link/support/TransitTypeToNetworkTypeMapperTest.java line 24 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

These lines could be joined in a better way.

Done.


src/main/java/fi/hsl/jore/importer/config/jooq/converter/date_range/DateRange.java line 29 at r1 (raw file):

Previously, jarkkoka (Jarkko Kaura) wrote…

This needs manual intervention. Use of > does not go as originally intended.

Done.

Copy link
Contributor Author

@Huulivoide Huulivoide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 161 of 442 files at r1, 284 of 286 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @jarkkoka)

Codebase is already following the wast majority of the enabled
rules/mutators. Config uses Composite mutators, that map to the
following list of mutators:

* ArithmethicAssignment
* ArraysDotStream
* AvoidMultipleUnaryOperators
* AvoidUncheckedExceptionsInSignatures
* CastMathOperandsBeforeAssignement
* CollectionIndexOfToContains
* CollectionToOptional
* ComparisonWithNaN
* CreateTempFilesUsingNio
* EmptyControlStatement
* EnumsWithoutEquals
* ForEachAddToStreamCollectToCollection
* ForEachIfBreakElseToStreamTakeWhile
* ForEachIfBreakToStreamFindFirst
* ForEachIfToIfStreamAnyMatch
* ForEachToIterableForEach
* GuavaImmutableMapBuilderOverVarargs
* GuavaInlineStringsRepeat
* GuavaInlineStringsRepeat
* GuavaStringsIsNullOrEmpty
* LambdaIsMethodReference
* LambdaReturnsSingleStatement
* LiteralsFirstInComparisons
* LocalVariableTypeInference
* LoopIntRangeToIntStreamForEach
* ModifierOrder
* ObjectEqualsForPrimitives
* ObjectsHashCodePrimitive
* OptionalNotEmpty
* OptionalWrappedIfToFilter
* OptionalWrappedVariableToMap
* PrimitiveWrapperInstantiation
* RedundantLogicalComplementsInStream
* RemoveAllToClearCollection
* RemoveExplicitCallToSuper
* SimplifyBooleanExpression
* SimplifyBooleanInitialization
* SimplifyStartsWith
* StreamAnyMatch
* StreamFlatMapStreamToFlatMap
* StreamForEachNestingForLoopToFlatMap
* StreamMapIdentity
* StreamWrappedIfToFilter
* StreamWrappedMethodRefToMap
* StreamWrappedVariableToMap
* StringIndexOfToContains
* StringReplaceAllWithQuotableInput
* StringToString
* ThreadRunToThreadStart
* UnnecessaryBoxing
* UnnecessaryFullyQualifiedName
* UnnecessaryImport
* UnnecessaryLambdaEnclosingParameters
* UnnecessaryModifier
* UnnecessarySemicolon
* UseCollectionIsEmpty
* UseIndexOfChar
* UseStringIsEmpty
* UseTextBlocks
@Huulivoide Huulivoide force-pushed the AddCodeFormatterAndLinter branch from 82aa5a5 to 6773353 Compare June 14, 2024 08:01
@Huulivoide Huulivoide merged commit 7b1e770 into main Jun 14, 2024
7 of 8 checks passed
@Huulivoide Huulivoide deleted the AddCodeFormatterAndLinter branch June 14, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants