pinterest / ktlint

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

wrong report corresponding to function-naming in Test #2508

Closed soudai-s closed 5 months ago

soudai-s commented 5 months ago

A function naming violation is reported in the test file, is this behavior correct? Apparently it didn't happen with v0.47.1.

Expected Behavior

Nothing.

Observed Behavior

Be Reported as function-naming.

Steps to Reproduce


package com.example.presentation.viewmodel

import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.serialization.ExperimentalSerializationApi
import org.junit.Test
import org.junit.runner.RunWith
// and more packages...

@ExperimentalSerializationApi
@RunWith(AndroidJUnit4::class)
class ViewModelTest {
  @Test
  fun fetch_条件1() {
    // do something
  }
}

↑ this example is reported by ktlint as function-naming violation, is it correct?

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Version of ktlint used: 1.0.0 and also the same as 1.1.1
* Relevant parts of the `.editorconfig` settings
* Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
* Version of Gradle used (if applicable):
* Operating System and version: Mac OS
paul-dingemans commented 5 months ago

this example is reported by ktlint as function-naming violation, is it correct?

The rule is based on https://kotlinlang.org/docs/coding-conventions.html#function-names. This guideline has been loosened so that underscores are allowed in names of test cases. Also diacritics and stokes on letters (for example è or ŷ) are allowed.

Characters like 条件 do not comply with this rule. In your case it might be best to disable this entire rule or to start using function names wrapped between backticks.

soudai-s commented 5 months ago

Could you change the behavior for multi-byte characters of function-naming in test similar to the snake case? I think the base rule https://kotlinlang.org/docs/coding-conventions.html#function-names does apply to the code except test, since ktlint permit the snake case in the test. The same rule above already apply to Android Studio as default (no matter what in the test with the function whose name has multi-byte characters).

The proposed behavior is also applied by default in Android Studio (there is no warning in the test even if the function name contains multibyte characters).

paul-dingemans commented 5 months ago

Could you change the behavior for multi-byte characters of function-naming in test similar to the snake case? I think the base rule https://kotlinlang.org/docs/coding-conventions.html#function-names does apply to the code except test, since ktlint permit the snake case in the test.

Based on references below, I do not agree with this.

https://kotlinlang.org/docs/coding-conventions.html#names-for-test-methods

In tests (and only in tests), you can use method names with spaces enclosed in backticks. Note that such method names are currently not supported by the Android runtime. Underscores in method names are also allowed in test code.

https://developer.android.com/kotlin/style-guide#naming_2

Identifiers use only ASCII letters and digits, and, in a small number of cases noted below, underscores. Thus each valid identifier name is matched by the regular expression \w+.

Special prefixes or suffixes, like those seen in the examples name_, mName, s_name, and kName, are not used except in the case of backing properties (see Backing properties).

soudai-s commented 5 months ago

Ok, Thank you for the consideration.