Skip to content

Cannot exclude test files from duplication checks #340

Closed
@anthonyhastings

Description

@anthonyhastings

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions