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

Ktlint 3 does not recognize a lower-case letter starting the function "approxE^X" #2339

Closed
binkley opened this issue Oct 31, 2023 · 2 comments

Comments

@binkley
Copy link

binkley commented Oct 31, 2023

Expected Behavior

Ktlint should not be concerned with a function named "approxE^X". It starts with a lower-case letter contrary to the below error message. Perhaps it violates "camel case" because of non-alphabetic characters.

However I get this ERROR in a Maven build:

[ERROR] src/main/kotlin/demo/KotlinMain.kt:206:9: Function name should start with a lowercase letter (except factory methods) and use camel case (standard:function-naming)

for https://github.com/binkley/kotlin-rational/blob/9706d9763236a9adda4454d46590431383ad650e/src/main/kotlin/demo/KotlinMain.kt#L206. The function is:

fun `approxE^X`(exponent: FloatingBigRational, limit: Int = 5) {
    println(
       (0..limit).map {
            e(exponent, it)
        }.joinToString(prefix = "APPROX E^$exponent -> ") {
            it.toString()
        }
    )
}

Observed Behavior

Instructions ask for --log-level=debug, however that is a syntax error. I assume you meant -X or --debug. Output for the Ktlint sections from my Maven build:

[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <android default-value="false">${ktlint.android}</android>
  <basedir default-value="${project.basedir}"/>
  <experimental default-value="false">${ktlint.experimental}</experimental>
  <includeScripts default-value="true">${ktlint.includeScripts}</includeScripts>
  <includeSources default-value="true">${ktlint.includeSources}</includeSources>
  <includeTestSources default-value="true">${ktlint.includeTestSources}</includeTestSources>
  <packaging default-value="${project.packaging}"/>
  <scriptRoots default-value="${project.basedir.path}">${ktlint.scriptRoots}</scriptRoots>
  <scriptsIncludes default-value="*.kts"/>
  <skip default-value="false">${ktlint.skip}</skip>
  <sourceRoots default-value="${project.compileSourceRoots}"/>
  <sourcesIncludes default-value="**/*.kt"/>
  <testSourceRoots default-value="${project.testCompileSourceRoots}"/>
  <testSourcesIncludes default-value="**/*.kt"/>
</configuration>
[DEBUG] Goal:          com.github.gantsign.maven:ktlint-maven-plugin:3.0.0:check (default)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <android default-value="false">${ktlint.android}</android>
  <basedir default-value="${project.basedir}"/>
  <experimental default-value="false">${ktlint.experimental}</experimental>
  <failOnViolation default-value="true">${ktlint.failOnViolation}</failOnViolation>
  <includeScripts default-value="true">${ktlint.includeScripts}</includeScripts>
  <includeSources default-value="true">${ktlint.includeSources}</includeSources>
  <includeTestSources default-value="true">${ktlint.includeTestSources}</includeTestSources>
  <packaging default-value="${project.packaging}"/>
  <scriptRoots default-value="${project.basedir.path}">${ktlint.scriptRoots}</scriptRoots>
  <scriptsIncludes default-value="*.kts"/>
  <skip default-value="false">${ktlint.skip}</skip>
  <sourceRoots default-value="${project.compileSourceRoots}"/>
  <sourcesIncludes default-value="**/*.kt"/>
  <testSourceRoots default-value="${project.testCompileSourceRoots}"/>
  <testSourcesIncludes default-value="**/*.kt"/>
  <verbose default-value="false">true</verbose>
</configuration>

Here's where it gets ugly, and I'm only showing output for the file where the issue cropped up:

[DEBUG] Discovered RuleSetProviderV3 'RuleSetId(value=standard)'
[DEBUG] checking format: src/main/kotlin/demo/KotlinMain.kt
[DEBUG] Starting with formatting file 'KotlinMain.kt'
[DEBUG] Effective editorconfig properties for file '/home/binkley/src/kt/kotlin-rational/src/main/kotlin/demo/KotlinMain.kt':
        end_of_line: lf
        max_line_length: 80
        ktlint_code_style: intellij_idea
        ktlint_standard_discouraged-comment-location: disabled
        ktlint_standard_filename: disabled
        ktlint_standard_import-ordering: disabled
        ktlint_standard_trailing-comma-on-call-site: disabled
        ktlint_standard_trailing-comma-on-declaration-site: disabled
[DEBUG] Rule with id 'standard:argument-list-wrapping' should run after the rule with id 'standard:class-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:indent' should run after the rule with id 'standard:class-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:indent' should run after the rule with id 'standard:trailing-comma-on-call-site'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:indent' should run after the rule with id 'standard:trailing-comma-on-declaration-site'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:max-line-length' should run after the rule with id 'standard:trailing-comma-on-call-site'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:max-line-length' should run after the rule with id 'standard:trailing-comma-on-declaration-site'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rule with id 'standard:argument-list-wrapping' should run after the rule with id 'standard:class-signature'. However, the latter rule is not loaded and is allowed to be ignored. For best results, it is advised load the rule.
[DEBUG] Rules will be executed in order below:
           - internal:ktlint-suppression,
           - standard:annotation-spacing,
           - standard:chain-wrapping,
           - standard:class-naming,
           - standard:colon-spacing,
           - standard:comma-spacing,
           - standard:comment-spacing,
           - standard:comment-wrapping,
           - standard:context-receiver-wrapping,
           - standard:curly-spacing,
           - standard:dot-spacing,
           - standard:double-colon-spacing,
           - standard:enum-entry-name-case,
           - standard:enum-wrapping,
           - standard:final-newline,
           - standard:fun-keyword-spacing,
           - standard:function-naming,
           - standard:function-return-type-spacing,
           - standard:function-start-of-body-spacing,
           - standard:function-type-reference-spacing,
           - standard:kdoc-wrapping,
           - standard:keyword-spacing,
           - standard:modifier-list-spacing,
           - standard:modifier-order,
           - standard:multiline-if-else,
           - standard:no-blank-line-before-rbrace,
           - standard:no-blank-lines-in-chained-method-calls,
           - standard:no-consecutive-blank-lines,
           - standard:no-empty-class-body,
           - standard:no-empty-file,
           - standard:no-empty-first-line-in-method-block,
           - standard:no-line-break-after-else,
           - standard:no-line-break-before-assignment,
           - standard:no-wildcard-imports,
           - standard:nullable-type-spacing,
           - standard:op-spacing,
           - standard:package-name,
           - standard:parameter-list-spacing,
           - standard:parameter-list-wrapping,
           - standard:parameter-wrapping,
           - standard:paren-spacing,
           - standard:property-naming,
           - standard:property-wrapping,
           - standard:range-spacing,
           - standard:spacing-around-angle-brackets,
           - standard:spacing-between-declarations-with-annotations,
           - standard:spacing-between-declarations-with-comments,
           - standard:spacing-between-function-name-and-opening-parenthesis,
           - standard:statement-wrapping,
           - standard:string-template,
           - standard:type-argument-list-spacing,
           - standard:type-parameter-list-spacing,
           - standard:unary-op-spacing,
           - standard:unnecessary-parentheses-before-trailing-lambda,
           - standard:annotation,
           - standard:wrapping,
           - standard:argument-list-wrapping,
           - standard:no-semi,
           - standard:function-signature,
           - standard:indent,
           - standard:block-comment-initial-star-alignment,
           - standard:max-line-length
[DEBUG] Format could not fix > src/main/kotlin/demo/KotlinMain.kt:207:9: Function name should start with a lowercase letter (except factory methods) and use camel case

Steps to Reproduce

Latest commit to this repo is binkley/kotlin-rational@e4de9a4 where I suppressed numerous Ktlint 3.0.0 complaints.

Your Environment

  • Version of ktlint used: 3.0.0
  • Relevant parts of the .editorconfig settings
[**]
end_of_line = lf
max_line_length = 80

[*.{kt,kts}]
# TODO: Decide if an Android mix makes more sense
ktlint_code_style = intellij_idea
ktlint_standard_discouraged-comment-location = disabled
ktlint_standard_filename = disabled
# Oh, the irony.  IntelliJ insists on sorting java* imports last
ktlint_standard_import-ordering = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): Maven 3.8.4 via Maven wrapper
  • Operating System and version: Linux Hobbiton 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux using WSL under Windows 11 Home latest
@paul-dingemans
Copy link
Collaborator

Your function name starts with a "`" which is not a lowercase character.

According to Kotlin Coding conventions:

In tests (and only in tests), you can use method names with spaces enclosed in backticks.

Android Kotlin style guide does not mention anything about backticks. But I think it is a commonly accepted guideline to not use method names enclosed in backticks.

@binkley
Copy link
Author

binkley commented Nov 1, 2023

@paul-dingemans Thanks for the helpful explanation!

I'll update my non-test code accordingly.

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

No branches or pull requests

2 participants