Is it possible to disable duplicate code detection in Intellij? - intellij-idea

Is it possible to disable duplicate code detection in Intellij?
I haven't found this feature to be useful and it continues to distract me.

Only available in IntelliJ Ultimate:
To disable duplicate code detection, go to
File → Settings → Editor → Inspections → General → Duplicated code fragment
and uncheck box "Duplicate code fragment".

Add a hint to your code so that others will know your intent:
#SuppressWarnings("Duplicates")

Yes, it's possible, but I would strongly advise against it!
Duplicate code is a form of technical debt. Any duplicated code that contains a bug means you now have a duplicated bug - you then run the risk that when you fix it, you'll only fix it in one place and the duplicate will remain...
If duplicate code warnings are distracting you, then the best strategy for getting rid of them is to remove the code duplication... Your codebase and future maintainers will thank you for it

This answer may be little irrelevant, but I found this helpful,
From this answer if you want to disable it for a specific code block, not the entire method or class or ide, then just add the following line just before that code block
//noinspection Duplicates
Note: You can not put any other comment after this line.

Could not get any of these answers to work in Webstorm.
To work around this without turning this feature off, I added this line of code:
if (Math.random() === 1) console.info('suppress duplicate code warning')
This makes the warning disappear if you add it in 1 of the 2 dupe files since they are not dupe anymore.
Another alternative if you are using lodash is:
noop('suppress duplicate code warning')

Related

How to Remove Unnecessary Line Spacing in Code Editor?

How can I get rid of the unnecessary line breaks in the Java code editor (see screenshot). This formatting seems to apply just to one project. When I create new projects, there is no extra line spacing.
Thanks!
I believe this is related to Inlay Hints. I had the same issue and it was driving me nuts, then after a restart a bunch of code hints showed up. While useful in the right circumstance, it was a bit baffling when all I could see were these ghost lines.
After disabling "Code vision" the issue resolved itself.
Go to settings (Ctrl-Alt-S), under Editor-Inlay Hints there is a checkbox for Code vision. Uncheck that and see if that helps.
This appears to be an issue with the 2022.1 version of IDEA. I had the same symptoms and downgraded to 2021.3. Poof, problem solved. Hopefully they fix this in a newer version soon.
This is indeed related to Editor -> Inlay Hints -> Code vision settings, but for me, it is the Code author option specifically that is adding the seemingly-needless lines.
It seems like IntelliJ creates affordance for the Code author value, but (for me) the value is empty so there is actually nothing showing.
I leave the other Code vision options enabled and just disable the Code author and this appears to be working well so far.

How can I stop IntelliJ IDEA printing an empty new line?

I am following the Atomic Kotlin course. I have understood the concept and my output is correct, however Intellij IDEA complains that the outputs are different. Even when I copy and paste from the answer. Please see screenshot.
I have tried using the print() method instead of println(), but it didn't help.
Go to Settings->Editor->General and uncheck the Ensure an empty line.. property.
see the following screenshot:
There is a straightforward workaround on how one can avoid this problem. Changing the AtomicKotlin/Programming Basics/Data Types/Exercise 2/test/output.txt manually to add a new line at the end of the text should fix the test.I've also found a YouTrack ticket with the problem description. According to it, EduTools 4.2 version release should fix it. Maybe it worth to upvote or comment on the ticket.

AppCode Indent After Comment

I'm using AppCode for Objective-C development. It seems like one of the recent updates has changed the behavior of how indents work after a comment.
Now, when I add a comment and then hit return to enter code on the next line I get this:
Hitting return again will keep the same level of indent, and hitting delete just returns the cursor to the comment line.
What I want is:
// Comment
self.theCodeStartsHere;
which I thought used to be the default.
I have also noticed that when I try to break a statement into multiple lines they no longer line up on the colons. I'm not sure if it's related, but the behavior seemed to start around the same time.
Any help would be appreciated!
After posting on YouTrack, this issue seems to be fixed in AppCode 2018.2 EAP.
EDIT: YouTrack Issue Link.

Set breakpoint in VBA code programmatically

I have a very large piece of code written in VBA (>50,000 lines - numerous modules). There is one array of interest to me, and I'd like to find all the conditions under which the value of any element of this array changes. The values can change in any module. Running the script line by line is not the most efficient option due to the size of the code.
I am looking for better ways to solve this problem. Two ways that come to my mind is to programmatically set a breakpoint (which I am not sure if can be done) or programmatically insert an if-block after each assignment that somehow alerts me that the value has changed. (not preferred).
So my question boils down to:
Is it possible to programmatically set breakpoints in VBA code?
If the answer to the above question is No, what is an efficient way to solve this problem?
UPDATE:
Thanks for the comments/replies. As I had implied, I am interested in the least amount of modification to the current code (i.e. inserting if-blocks, etc) and most interested in the break-point idea. I'd like to know if it's doable.
Use the keyword STOP to break te code if a certain condition is true.
There are Two Ways to do that:
Use Stop Key word. Example as given below, set a break point at Stop
if (x = 21 ) Then
Stop
End If
Using Add Watch
Go to Debug -> Select Add Watch
NB:I know this is an old topic but this could help others.
You could use Watches:
Right click on the variables you wish to monitor -> Add Watch...
In Watch Type: 'Break when value changes'
While you run your code, you can check the status of your Watches thanks to the Watch Window (accessible from the 'View' menu)
in the hope someone can benefit from this :
In such situations regardless of the programming language used - writing a few lines of code either in Perl, AWK or even shell scripts can solve the problem :
search for a regular expression containing the array name (ignoring case).
Once you export all modules and classes in the Workbook(s) into a given directory - the scripts can search those for you.

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...