atc0005 / go-nagios

Shared Golang package for Nagios plugins
MIT License
8 stars 3 forks source link

RegexpWarnings in Goland #235

Closed Tommi2Day closed 8 months ago

Tommi2Day commented 9 months ago

just to let you know Jetbrains Goland raises serveral RegExp warnings in range.go, which are causing force commits with changed code

Warning:(83, 49) Redundant character escape '\@' in RegExp
Warning:(83, 53) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(83, 64) Redundant character escape '\.' in RegExp
Warning:(83, 73) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(83, 84) Redundant character escape '\.' in RegExp
Warning:(83, 98) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(83, 109) Redundant character escape '\.' in RegExp
Warning:(83, 118) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(83, 129) Redundant character escape '\.' in RegExp
Warning:(84, 44) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(84, 55) Redundant character escape '\.' in RegExp
Warning:(84, 64) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(84, 75) Redundant character escape '\.' in RegExp
Warning:(85, 37) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(85, 48) Redundant character escape '\.' in RegExp
Warning:(85, 57) Unnecessary non-capturing group '(?:[-+]?[\d\.]+)'
Warning:(85, 68) Redundant character escape '\.' in RegExp
atc0005 commented 9 months ago

@Tommi2Day Thanks for sharing this.

Does that IDE offer an option to automatically fix the regex patterns or an alternative?

Tommi2Day commented 9 months ago

partially yes. You can go through the positions complained and add "suggested Action"

image
Tommi2Day commented 9 months ago

this is a version with all suggestions adopted. Unit test ran sucessfully

digitOrInfinity := regexp.MustCompile([\d~]) optionalInvertAndRange := regexp.MustCompile(^@?([-+]?[\d.]+(?:e[-+]?[\d.]+)?|~)?(:([-+]?[\d.]+(?:e[-+]?[\d.]+)?)?)?$) firstHalfOfRange := regexp.MustCompile(^([-+]?[\d.]+(?:e[-+]?[\d.]+)?)?:) endOfRange := regexp.MustCompile(^[-+]?[\d.]+(?:e[-+]?[\d.]+)?$)

atc0005 commented 9 months ago

@Tommi2Day Thanks for sharing. That linting feature looks like it would really come in handy.