Is it possible to disable duplicate code detection in Intellij?

Intellij Idea

Intellij Idea Problem Overview


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.

Intellij Idea Solutions


Solution 1 - Intellij Idea

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". intellij code duplication

Solution 2 - Intellij Idea

Add a hint to your code so that others will know your intent:

@SuppressWarnings("Duplicates")

Solution 3 - Intellij Idea

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

Solution 4 - Intellij Idea

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.

Solution 5 - Intellij Idea

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')

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzudduzView Question on Stackoverflow
Solution 1 - Intellij IdeaVojtech RuzickaView Answer on Stackoverflow
Solution 2 - Intellij IdeaMax BarrassView Answer on Stackoverflow
Solution 3 - Intellij IdeaKevin WrightView Answer on Stackoverflow
Solution 4 - Intellij IdeaEmdadul SawonView Answer on Stackoverflow
Solution 5 - Intellij Ideadanday74View Answer on Stackoverflow