derision-test / go-mockgen

MIT License
57 stars 7 forks source link

Update goIdentifierPattern regex #49

Closed BolajiOlajide closed 6 months ago

BolajiOlajide commented 6 months ago

It seems the regex for identifying valid Go identifiers is wrong.

According to the Go source code,

An identifier is a non-empty string made up of letters, digits, and underscores, where the first character is not a digit. Keywords are not identifiers.

The regex defined in the library currently expects an identifier to begin and end with a letter.

^[A-Za-z]([A-Za-z0-9_]*[A-Za-z])?$

I switched the regex usage to fit the description of an identifier defined in Go. That way, v1 can be identified as a valid package name.

I wonder if it is better to switch to using the IsIdentifier method from go/token instead of relying on a regex, let me know if this works so I can update the pull request to make use of this method instead of the regex.

CleanShot 2024-01-04 at 04 14 53@2x

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud