pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.23k stars 507 forks source link

(Type?)ParameterListSpacingRule false positive "Expected a single space" #2322

Closed bjoernmayer closed 1 year ago

bjoernmayer commented 1 year ago

Expected Behavior

ktlint should not report this or should at least give me a hint on what is wrong

Observed Behavior

ktlint does not like the part in code. Even formatting the file using ktlint, does not fix it

Steps to Reproduce

Max line length: 120

 class CachedExternalServiceRepository(
    private val conceptDistancesCache: AsyncLoadingCache<AccommodationNsid, Optional<ClosestConcept>>,
    private val accommodationCache: AsyncLoadingCache<AccommodationNsid, Optional<GeoConcept<AccommodationNsid>>>,
    private val destinationCache: AsyncLoadingCache<DestinationNsid, Optional<GeoConcept<DestinationNsid>>>,
    private val pointsOfInterestCache:
        AsyncLoadingCache<PointOfInterestNsid, Optional<GeoConcept<PointOfInterestNsid>>>,
)

Your Environment

Version of ktlint used: 1.0.1

Relevant parts of the .editorconfig settings

max_line_length             = 120
ktlint_standard_multiline-expression-wrapping      = disabled
ktlint_standard_max-line-length                    = disabled
ktlint_standard_parameter-list-wrapping            = disabled
ktlint_standard_trailing-comma-on-call-site        = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_string-template-indent             = disabled
ktlint_function_signature_body_expression_wrapping = default

Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): 11.6.1 with ktlintCheck

Version of Gradle used (if applicable): 8.3

Operating System and version: Ventura 13.6 22G120

bjoernmayer commented 1 year ago

There is more:

suspend fun <ConceptDealsSearchRequest : ConceptDealsSearchRequestInterface<SearchEngineGrpcRequest>, SearchEngineGrpcRequest : Proto> querySearchEngineAndBuildResponse(
        inputParams: AccommodationSearchResponseBuilderCommonInputs,
        context: GatewayGraphQLContext,
        pollData: String?,
        validateAndInto:
            (context: GatewayGraphQLContext, pollData: String?, uivs: List<AccommodationSearchUivInput>?) -> ConceptDealsSearchRequest,
        metrics: GqlSubgraphServiceMetrics,
        searchAction: suspend RegionSearchEmulatorClient.(SearchEngineGrpcRequest) -> ProtoSearchResult,
    )

also gives me Expected a single space after validateAndInto

paul-dingemans commented 1 year ago
   private val conceptDistancesCache: AsyncLoadingCache<AccommodationNsid, Optional<ClosestConcept>>,
   private val accommodationCache: AsyncLoadingCache<AccommodationNsid, Optional<GeoConcept<AccommodationNsid>>>,
   private val destinationCache: AsyncLoadingCache<DestinationNsid, Optional<GeoConcept<DestinationNsid>>>,
   private val pointsOfInterestCache:
       AsyncLoadingCache<PointOfInterestNsid, Optional<GeoConcept<PointOfInterestNsid>>>,
)

The violation reported is:

YourFile.kt:5:39: Expected a single space (standard:parameter-list-spacing)

The message might be a bit cryptic, but it together with the offset 5:39 it should be clear that a space was expected instead of a newling after pointsOfInterestCache:. As was mentioned in the slack channel, the type should be on the same line as the variable declaration. So it is not a false positive.

But instead of looking at the lint violations and fixing them manually, I would advise just another workflow which might save a lot of time in the long run. First commit your changes, and then run ktlint format, and review the changes made. In this way you do not have to make changes manually (unless autocorrect is not possible). If statisfied you can ammend your last commit to integrate the changes.

In your .editorconfig, you have set:

max_line_length             = 120
ktlint_standard_max-line-length                    = disabled

Did you set it like this intentionally? Althoug the max-line-length rule is disabled, rules below in ktlint will still wrap lines when the line exceeds the length of 120 characters: