relint icon indicating copy to clipboard operation
relint copied to clipboard

Add a negate flag

Open petemounce opened this issue 5 years ago • 4 comments

I would like to add a rule that fails when a regex is not matched, for example a VERSION file containing a v1.0.0 and a pattern like ^v (because a v prefix on a semver is not valid).

petemounce avatar Mar 27 '20 16:03 petemounce

---
# https://semver.org/#is-v123-a-semantic-version
- name: VERSION files must contain semver.
  # LOLWAT? https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
  pattern: '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
  hint: "https://semver.org/#is-v123-a-semantic-version"
  filePattern: '.*VERSION'

- name: VERSION file contents must not be prefixed with a v
  pattern: '^v'
  hint: "https://semver.org/#is-v123-a-semantic-version"
  filePattern: '.*VERSION'

cmd/VERSION:

v0.1.1

I want that file to fail both rules, not just the 2nd one.

petemounce avatar Mar 27 '20 16:03 petemounce

(and the LOLWAT refers to the regex itself ;) )

petemounce avatar Mar 27 '20 16:03 petemounce

Hi @petemounce thanks for reaching out. I see your point, how this might come in handy. However, I am not 100% sure on how to integrate this, since we currently work with matches, that have line numbers and snippets, that are being displayed. Inverse matches would mean we only had file names.

Anyhow, I still think it's possible to come up with a good solution. How about you propose a solution. Preferably as a pull-request and I will gladly review and release it.

Best -Joe

codingjoe avatar Mar 30 '20 07:03 codingjoe

Hi @petemounce , did you try this? (I know it doesn't cover everything, just to get a hang of it)

^(?!\d+\.\d+\.\d+).*$

This won't match the correct versioning string but will trigger everything else.

viktorkertesz avatar Dec 14 '22 15:12 viktorkertesz