18

I couldn't find this info anywhere else.

Variable shadowing is a great feature in my opinion, yet in Kotlin we get warned for it every single time, thus requiring us to use @Suppress("NAME_SHADOWING") in every instance of it, if we wouldn't like it to warn us.

Is there a way to disable variable shadowing verifications, or suppress the warning globally?

Roger Oba
  • 1,292
  • 14
  • 28
  • I assume you mean Android studio: [disabling inspections](https://www.jetbrains.com/help/idea/disabling-and-enabling-inspections.html) – Pawel Nov 01 '18 at 16:45
  • 1
    There isn't a generic variable shadowing inspection configuration for this, only "Nested lambda has shadowed implicit parameter" @Pawel – Roger Oba Nov 01 '18 at 23:20

1 Answers1

10

From Annotations in Kotlin

Put an annotation with the target file at the top level of a file, before the package directive or before all imports if the file is in the default package:

So right now the only solution is you can disable Suppress for file level. I don't find any way to disable for projects.

@file:Suppress("NAME_SHADOWING")
package com.your.package.name

import android.content.Context
import android.content.Intent
import android.os.Bundle

class SplashActivity : AppCompatActivity() {
    // Your class code here
}
Son Truong
  • 13,661
  • 5
  • 32
  • 58
  • 9
    Yeah, it can be disabled for different levels, like variable, function or file, but this is just cumbersome to do every time :( I'd be great to disable it for the entire project. Variable name shadowing is a definitely a feature, not something to be warned about, from my point of view. – Roger Oba Nov 02 '18 at 03:17