suppress an unused variable warning - kotlin

How can I suppress the inspection in Kotlin for an unused variable
val xyz = abc
I get the squiggly line but ALT-ENTER is useless for this, I tried also to create in another method several variables unused and they also lack the ALT-ENTER ability to ignore the warning. Although I have definitely used ALT-ENTER for this in the past, although maybe it was only in java, can't remember.
So I must manually construct it by hand. I've been trying several variations but I can't get anything to work. Please tell me the correct //noinspection or #SupressWarnings to use, thanks

In IntelliJ IDEA, a right-side arrow on an ALT+ENTER context menu (like this: ) means that you can use your arrow keys to navigate further along the menu. In this case, it leads to your answer:
#Suppress("UNUSED_VARIABLE")
val unused = ""
If you do not get the initial context menu (Remove variable '...'), you may have disabled the "Unused assignment" inspection in your current project. You can fix this by going to Settings -> Editor -> Inspections.

Related

Where is the setting for highlighting unused variables and constants in Visual Studio 2022?

I am working in a C# project where this has been turned off.
I can't find out how to turn it on again.
It's pretty hard to google as it's default behavior, and no sane person would turn it off...
Did you perhaps change your compiler warning level?
Unused variables should have the warning of CS0168. If you look at that page, the title is "Compiler Warning (level 3) CS0168".
In solution explorer, right click your project and go to Build and check your Warning Level:
If you set it to anything lower than three, then the CS0168 warnings will never be shown. Also, just below the drop down is a suppress warnings text box. Make sure you don't have CS0168 in that text box.
Are you using an .editorconfig file?
If you are using an .editorconfig file, you may have suppressed this particular warning. Removing that suppression should resolve this as well. It would look something like this in your .editorconfig file:
[*.cs]
# CS0168: Variable is declared but never used
dotnet_diagnostic.CS0168.severity = none

How to suppress warnings regarding naming conventions?

For one of my enum classes I'd like to use non-standard naming:
enum class MyEnum {
I_like_to_use,
This_strange_naming_here
}
The IDE (and code inspection) rightfully complains with:
Enum entry name 'This_strange_naming_here' doesn't match regex '[A-Z]([A-Za-z\d]*|[A-Z_\d]*)'.
This inspection reports enum entry named that do not follow the recommended naming conventions.
However in this case, I would like to actively suppress this warning. I tried with #Suppress("naming"), but to no avail.
For Kotlin/Java add
#Suppress("LocalVariableName", "PropertyName")
above the class name to suppress naming conventions warnings for global and local variables.
#Suppress("EnumEntryName") use these
Please see Suppress inspections. You are not supposed to type it by hand.
Use Alt+Enter to invoke the pop-up menu for the light bulb, select the inspection or the suggested quick fix from the drop-down menu, press the right arrow on the keyboard to open the sub-menu on the right, choose the Suppress option.

CLion highlight settings (override)

I'm using CLion IDE, and I really enjoy it, but one thing is quite annoying and I can't get rid of it.
CLion highlights every function declaration that overrides another function in base class with "Annotate this function with override or (rarely) final". As far as I know override keyword is an optional keyword. I would use it, but I recently joined this big sized project and I want to stay consistent to its conventions - and they don't use override keyword.
But the problem is that I couldn't find anywhere in CLion's settings where to disable this highlight option (I've tried using search option in settings, but still nothing).
It is a bit annoying because it highlights most of functions in my derived classes, and I have to mouse over it to check if it is an important notice, or just this "Annotate this...".
You can find on this link from jetbrains.com some explanations on how to disable inspections.
One of these method is temporary : Use the widget in the top-right corner of the editor and select the level 'None' in the Highlight list.

Disable reporting erros for path checking in IntelliJ

IntelliJ show the squiggly red underline under require paths (node.js) that it can't find. In my case, I have a file that is copied to a particular place on installation. Their location in the source has nothing to do with their location in the installation. Its especially annoying because intelij shows that red underline for all folders in its file browser.
var x = require('./some/invalid/path')
I like that it has this check, but I want to disable it for this file since it doesn't make sense for that case. How can I do this, ideally in intelliJ 12?
That's how you suppress an inspection for a class, method or statement:
Place your cursor inside the warning statement, press Alt + Enter, choose the entry that describes your warning, and from the sub-menu select Suppress for class or statement.
You will find more info on the IDEA webhelp.
I found a dumb way to do it - make the require path an expression rather than a simple string literal like this:
var x = require('./some/invalid/path'+'')
I guess it confounds intellij enough that it just says "screw it its probably fine".

Disable IntelliJ Warnings

It really annoys me that IntelliJ highlights certain 'errors' (that don't prevent successful compilation) the same way that real errors are highlighted. For example, a magic number is not really an error, but it will be flagged in exactly the same way as an incompatible type error.
How can I change this?
Go to Settings -> Inspections. Then you need to search through the long list for the offending inspection, which you can get the name of by hovering on the warning marker in the margin. You can change the severity of the inspection, whether it's an error, warning, etc. or just disable it altogether.
Edit: if you search for "magic" in Settings, you get the following, which should be helpful:
Whenever you see an inspection warning/error you can place the caret on it and press Alt+Enter (a light bulb also appears that tells you that). A menu will appear with suggested quick fixes. You may need to open a submenu by pressing Right, and you'll find "Edit inspection settings" there. Having invoked that, you may proceed as in hvgotcodes's answer :), it's just a faster way of getting to those settings.
As Michael Calvin said you can use the SuppressWarnings annotation. For example:
#SuppressWarnings("OptionalUsedAsFieldOrParameterType")
See https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/OptionalUsedAsFieldOrParameterType.html
Usually searching the internet for the exact description leads me to this.
Not directly relevant to the OP, but may be of use to future Googlers
I got to this question while trying to figure out how to disable IntelliJ IDEA's warnings about Guava functionalities that have been replaced by Java 8 features. I'm not able to use the Java 8 versions of these features in my case because of a library we're using that was built with Guava (despite being a Java 8 project). So to solve that, I added a SuppressWarnings annotation before any class using Guava:
#SuppressWarnings(Guava)
public final class...