Checkstyle - How to exclude any file, but the ones ending with 'Impl.java', with a regex?

StackOverflow https://stackoverflow.com/questions/21851615

  •  13-10-2022
  •  | 
  •  

Domanda

I have been thinking some time about this problem.

I have a huge Maven multi module project and using build-tools I share a custom set of rules for all modules (no problem around here).

The problem comes when I want to apply one rule to just one set of files in just one of the modules. By using checkstyle suppressions file I can easyly exclude all files that I don't want the rule to apply, but it has its limitations. Lets put this into an example:

Files:

a/b/c/d/FileImpl.java
a/b/c/d/File.java
a/b/c/d/e/FileImpl.java
a/b/c/FileImpl.java
...

What regex would you write that assures you that all files (including future files that may be introduced) get excluded but just the ones that end with Impl.java under package a.b.c.d? in terms of regex, it has to be a regex that matches anything but the file ending I want.

It would be easyer if I could just set an "includes" referring only to the set of files to apply the rule to, but as far as I know that's not possible. It has to be using suppressions, so that it suppresses all files but the ones I want.

I have tried using capturing groups, lookahead and lookbehind but had no success at all.

Any ideas?

È stato utile?

Soluzione 2

Found the right solution to the not so clear question, hope it helps anyone interested.

http://fiddle.re/9wvfg

Regex Goal --> match any chain but the ones that match the internal regex.

Regex --> ^((?!d/\w+Impl\.java).)*$

Using negative lookahead and the template: ^((?!regexp).)*$

Thanks for the support!!

Altri suggerimenti

What regex would you write that assures you that all files (including future files that may be introduced) get excluded but just the ones that end with Impl.java under package a.b.c.d?

Try this regex:

a/b/c/d/.+Impl\.java$

Demo

http://fiddle.re/rpqgg

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top