Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the purple "duplicated code fragment" highlighting in PhpStorm?

Tags:

phpstorm

I just clicked "Show all duplicates like this" in the "Duplicated code fragment" context menu:

Duplicated code fragment

Now the duplicated code is permanently highlighted with a purple background, even if I close the "Duplicates" toolbar at the bottom of the IDE.

How do I remove this highlighting?

like image 776
BenMorel Avatar asked Sep 07 '19 09:09

BenMorel


People also ask

How to unhighlight duplicates in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Duplicates. Select file types to which the analysis should apply and select the checkboxes next to the constructs that you want to anonymize.

What does duplicated code fragment mean?

Code Inspection: Duplicated code fragmentReports duplicated blocks of code from the selected scope: the same file or the entire project. The inspection features quick-fixes that help you to set the size of detected duplicates, navigate to repetitive code fragments, and compare them in a tool window.

How do I refactor duplicate code in IntelliJ?

From the main or context menu, select Refactor | Find and Replace Code Duplicates. In the dialog that opens, select the scope where IntelliJ IDEA shall look for code duplicates. For each found code duplicate, IntelliJ IDEA will prompt you to confirm the replacement.


2 Answers

  • Simply hit the ESC key to remove that highlighting.

  • If the IDE is finding "Duplicate code fragments" between your source code and a copy of it in an output directory (like Python setup.py creates in a build/ directory; I don't know how this goes in PHP), then mark the output directory as excluded from source directories.

    Right-click the output directory in the Project View, then Mark Directory As > Excluded.

BTW, this works in PyCharm and IntelliJ as well, and presumably in all the JetBrains IDEs.

like image 185
Jerry101 Avatar answered Sep 20 '22 03:09

Jerry101


Just re-open the file/project - it will remove the highlighting. If you don't like the "Duplicate code fragment" violation to be reported for your code fragment, try suppressing inspection for statement by adding // noinspection DuplicatedCode before it.

There is a request for making the duplicates highlighting less aggressive, IDEA-210614, please feel fre to vote for it

like image 44
lena Avatar answered Sep 19 '22 03:09

lena