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

Suppress Warnings in Generated Code with @file:Suppress("REDUNDANT_VISIBILITY_MODIFIER") #459

Open
leinardi opened this issue Dec 27, 2024 · 4 comments

Comments

@leinardi
Copy link

When using Kotlin Inject in a project configured with stricter compiler options, such as:

tasks.withType<KotlinCompilationTask<*>>().configureEach {
    compilerOptions {
        extraWarnings.set(true)
    }
}

The following warning is generated for Kotlin Inject-generated code:

w: file:///path/to/generated/file.kt:line:column Redundant visibility modifier.

This warning appears because the generated code includes unnecessary visibility modifiers, which the stricter compiler options flag as redundant.


Proposed Solution

Add the annotation @file:Suppress("REDUNDANT_VISIBILITY_MODIFIER") at the top of each generated file to suppress this specific warning in generated code.

This change would prevent these warnings from appearing when stricter compiler options like extraWarnings.set(true) are enabled, while not impacting other aspects of the generated code or its functionality.


Example: Generated Code with Suppression

Here’s an example of how the annotation could be included in a generated file:

@file:Suppress("REDUNDANT_VISIBILITY_MODIFIER")

package com.example.generated

public class InjectAppComponent {
    // Generated code here...
}

Benefits

  • Keeps the project clean and free of compiler warnings, especially in projects using stricter compiler configurations.
  • Does not require developers to modify generated files manually or disable the extraWarnings setting for the entire project.

This small change will improve developer experience by ensuring Kotlin Inject-generated code does not cause unnecessary warnings in projects with stricter compiler settings.

@evant
Copy link
Owner

evant commented Dec 27, 2024

I attempted to add suppression annotations before but couldn't get them to work, PR welcoming if you can get this to work #267 (comment)

@evant
Copy link
Owner

evant commented Dec 27, 2024

As a more minor note your issue description is overly verbose. Would be quicker and easier to understand without the extra fluff.

@leinardi
Copy link
Author

I attempted to add suppression annotations before but couldn't get them to work, PR welcoming if you can get this to work #267 (comment)

Sure, I'll give it a try after the holidays.

As a more minor note your issue description is overly verbose. Would be quicker and easier to understand without the extra fluff.

I'll keep it in mind for the next time.

@leinardi
Copy link
Author

leinardi commented Jan 2, 2025

@evant PR created: #460

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