realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.59k stars 2.22k forks source link

Add rule to detect duplicate code #682

Open steve21124 opened 8 years ago

steve21124 commented 8 years ago

since swiftlint use sourcekit, do you think it is possible to detect duplicate code through result from sourcekit?

jpsim commented 8 years ago

Yes, it'd be possible to some extent, but nothing is currently implemented. I'll keep this open as a rule request. Here's my comment from the duplicate issue you just opened up on SourceKitten (jpsim/SourceKitten#216):

You can find duplicate code just by doing regular text parsing. You don't need SourceKitten for that.

If you want to build a system that detects similar patterns, with heuristics accounting small variations in structure and naming, you could certainly do that using text parsing augmented by SourceKitten's Structure construct.

But SourceKitten doesn't ship a CLI command or API that will "show all duplicated code".

masters3d commented 8 years ago

@steve21124 probably better to use something like https://github.com/kucherenko/jscpd

jpsim commented 8 years ago

Doesn't look like jscpd supports Swift.

kucherenko commented 8 years ago

Swift language support added to jscpd jscpd@0.6.4

jpsim commented 8 years ago

Sweet, thanks @kucherenko for the quick turnaround on that!