codeclimate / codeclimate-duplication

Code Climate engine for code duplication analysis
http://codeclimate.com
MIT License
113 stars 24 forks source link

Cannot exclude test files from duplication checks #340

Closed anthonyhastings closed 5 years ago

anthonyhastings commented 5 years ago

I've seen previous issues talking about this issue; https://github.com/codeclimate/codeclimate-duplication/issues/115 https://github.com/codeclimate/codeclimate-duplication/issues/113

One particular answer (https://github.com/codeclimate/codeclimate-duplication/issues/113#issuecomment-203964518) 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: https://github.com/codeclimate/codeclimate-duplication/blob/0646b13edc0e5b5f28512cf68a5e3ca500ca151f/lib/cc/engine/analyzers/file_list.rb#L37-L45

anthonyhastings commented 5 years ago

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.

mainameiz commented 3 years ago

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

I can't find it 😞

efueger commented 3 years ago

@mainameiz

zinkkrysty commented 2 years ago

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

mainameiz commented 2 years ago

Solution:

plugins:
  duplication:
    enabled: true
    exclude_patterns:
      - 'spec/**/*.rb'
zinkkrysty commented 2 years ago

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!