Comments (10)
The Kotlin coding conventions are clear:
If a Kotlin file contains a single class or interface (potentially with related top-level declarations), its name should be the same as the name of the class, with the .kt extension appended. It applies to all types of classes and interfaces.
https://kotlinlang.org/docs/coding-conventions.html#source-file-names
The rule's behaviour aligns. Why not rename the class or the file? If you can't, then you can suppress the rule on this file, or disable the rule in your project.
from detekt.
The Compose guidelines also say that the Kotlin coding conventions should be followed (see section "Baseline style guidelines"): https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md
You have a few options:
- Suppress the rule for the file
- Disable the rule for the module
- Move the class into its own file
As a general rule we avoid customising rules and behaviour for specific frameworks or libraries though I'll leave this open for a while for others to comment.
from detekt.
I think using
@Composable
fun CustomButton() {
//
}
data class CustomButtonData(
// ...
)
should fix the issue as there is a flag mustBeFirst
which is true
by default so if you move the function at the top then this rule will not check that file
from detekt.
@atulgpt,
I have changed the mustBeFirst
to false
.
But, it is still not working.
I do not want to reorder the method and classes.
from detekt.
The convention aligns only for non-compose code.
For Jetpack Compose code, the Composable method is the main aspect of the file and hence the name will match the Composable name.
from detekt.
I would prefer not to suppress or disable the rule as it is very helpful.
I also noticed that the issue is that the functions are not considered at all.
Example,
A file with the name - Test.kt
will not throw any error if there is a single top-level function with any other name.
Even rearranging the methods and classes does not help.
File name - CustomButton.kt
@Composable
fun CustomButton() {
//
}
data class CustomButtonData(
// ...
)
is also not compliant.
My proposal is that the top-level methods also have to be included in the checks.
from detekt.
That proposal would be a good one to raise in this third party rule set: https://mrmans0n.github.io/compose-rules/
If it doesn't already exist yet that is.
It's not a good fit for the standard detekt rules though.
from detekt.
The above link is not working.
Also, I am not using any third-party rule set.
from detekt.
@3flex,
I can see multiple compose rules libraries.
Is there any official one from detekt for the compose rules?
from detekt.
Sorry not sure what happened - the link is fixed now. There's no official detekt rule set for Compose rules but the one I linked to is reasonably popular and should be a good place to start.
from detekt.
Related Issues (20)
- False-positve `UnusedImports` when there are mutiple functions of the same name
- Create a property to store the `basePath`
- Alias ObjectPropertyNaming as ObjectPropertyName
- StringLiteralDuplication potential false positive with interpolated strings HOT 3
- NamedArguments: False positive on spread varargs
- Ignore / Suppress specific magic number warning in detekt baseline.xml for a Compose function HOT 1
- detekt-core shouldn't depend on detekt-psi-utils HOT 2
- ignoreFailures doesn't work when using gradle workers
- False positive `SwallowedException` when exception is used as a receiver
- Multiline strings may occur parse error HOT 3
- "Missing new line after {" is reported incorrectly in nested lambda
- Incorrect report of error - UnsafeOptInUsageError HOT 2
- The issue arises when I move the detekt-baseline.xml file from its default path (project/app/detekt-baseline.xml) to a new location (project/config/detekt/detekt-baseline.xml). HOT 3
- MissingPackageDeclaration - Incorrect issue reported.
- Add 2.0.0 language version compatibility to detekt-compiler-plugin
- Remove deprecated configuration items HOT 1
- autoCorrect not working without "buildUponDefaultConfig = true"
- Kotlin 2.0.0: `RuleExtensionsKt.compileAndLintWithContext` fails with `NoScopeRecordCliBindingTrace: method <init>()V not found` HOT 2
- Unable to setup `CoroutineLaunchedInTestWithoutRunTest` rule
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from detekt.