codeclimate/codeclimate-duplication

Cannot exclude test files from duplication checks

anthonyhastings opened this issue ยท 6 comments

I've seen previous issues talking about this issue;
#115
#113

One particular answer (#113 (comment)) mentions going to a documentation page but it doesn't seem to have relevant information anymore. It contains a hash / fragment in the URL (#section-exclude-paths-for-specific-engines) that doesn't link to anywhere on the page.

It also gives this code snippet, which I believe is old as the codeclimate validate-config CLI command tells me the engines key is unrecognised.

engines:
  duplication:
    enabled: true
    exclude_paths:
      - spec/

The current documentation mentions custom file name patterns but it doesn't mention how this could be used to, for example, target all JS files that don't have a spec suffix, e.g.

src/app.js ##TARGET
src/components/app/index.js ##TARGET
src/components/app/tests/index.spec.js ##IGNORE

Any help would be appreciated. I've tried engines, and then using various connotations of regexes/globs within patterns.duplication.config.languages.javascript.patterns. If this is indeed the right approach, then I'm assuming the pattern needs to be a single magic pattern that does everything in one go, as from examining the code I see that if a file name matches any single pattern in the array, it's included:

def matches?(path)
patterns.any? do |p|
File.fnmatch?(
relativize(p),
relativize(path),
File::FNM_PATHNAME | File::FNM_EXTGLOB,
)
end
end

Ignore this. Apologies. I've read the newer documentation and see that there's an exclude_patterns property at the top level of a plugin config. I think where I'd got confused was that I was placing exclude_patterns down in config.languages.javascript.

@anthonyhastings Could you please provide a link (to documentation or code) with exclude_patterns option?

I can't find it ๐Ÿ˜ž

I still can't get this to work. Anybody got a working example?

Solution:

plugins:
  duplication:
    enabled: true
    exclude_patterns:
      - 'spec/**/*.rb'

thanks, I think I figured it out eventually. But how come this is not on this page? https://docs.codeclimate.com/docs/duplication-concept I have tried many things with checks: similar-code but didn't try plugins: duplication . it's so counter intuitive!