question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule idea: detect code duplication

See original GitHub issue

I’d like eslint to produce a warning when I have pieces of duplicated code.

Precisely, I’d like no n- (default 3) line chunk to be repeated more then k (default 2) times. If it happens, the k+1-th occurrence should trigger a warning: “These n lines are duplicated for k+1-th time”.

Quite possibly we will also need to only take into account lines containing alpha-numeric characters, because we don’t want to detect chunks like:

    return this;
},
<empty line>

This rule does not prevent errors, but helps maintain overall code quality. I think that (in its simplest version) it’s generic enough to be useful for any code, regardless of JS dialect or framework.

Do you think it’s a good idea to have this rule in core ESLint, or shall it be a plugin?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lo1tumacommented, Sep 28, 2015

ESLint rules only operate on the context of a single file. So you won’t be able to detect duplicated code across multiple files.

I suggest to use tools like jscpd or jsinspect.

0reactions
nzakascommented, Sep 29, 2015

As @lo1tuma suggested, this isn’t an area where ESLint is the best tool, as each file is looked at separately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analyze duplicates | IntelliJ IDEA Documentation - JetBrains
In the search field of the Inspections dialog, type duplicated code fragment to locate the inspection in the list. Once you click the...
Read more >
Chapter 4. Working with duplicate code - SonarQube in Action
When you start a new project, you have a clean code base with no duplications, unless you copied another project to start with....
Read more >
The key to eliminating duplicated code patterns - Medium
However, there is one key concept that will solve all semantic code duplication (as well as structural duplication), namely “abstraction”.
Read more >
How to detect code duplication during development? [closed]
Simian detects duplicate code in C++ projects. Update: Also works with Java, C#, C, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy...
Read more >
Duplicate code - Wikipedia
In computer programming, duplicate code is a sequence of source code that occurs more than once, either within a program or across different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found