var-naming: regex support for custom package naming conventions#1592
var-naming: regex support for custom package naming conventions#1592Acollie wants to merge 18 commits intomgechev:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for custom package naming conventions through regex patterns in the var-naming rule. Users can now specify a validPackageRule parameter with a regex pattern to enforce their own package naming standards, which takes precedence over the default checks when configured.
Key changes:
- Added
validPackageNameRegexfield toVarNamingRulestruct to store the compiled regex pattern - Implemented regex-based package name validation that short-circuits default checks when configured
- Added comprehensive test coverage with positive and negative test cases
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rule/var_naming.go | Added regex configuration parsing, compilation, and validation logic for custom package naming rules |
| test/var_naming_test.go | Added test cases for valid and invalid package names using regex patterns |
| testdata/var_naming_valid_package_name_by_regex.go | Test data with a camelCase package name that passes the regex validation |
| testdata/var_naming_invalid_package_name_by_regex.go | Test data with an underscore-containing package name that fails regex validation |
| RULES_DESCRIPTIONS.md | Added detailed documentation for the new validPackageRule configuration option with examples |
| README.md | Added usage example showing how to configure custom package naming with regex patterns |
Comments suppressed due to low confidence (1)
rule/var_naming.go:146
- The
skipPackageNameCollisionWithGoStdcheck is placed outside theswitchstatement, which means it will execute for every iteration of the loop regardless of the key. This should be acasewithin theswitchstatement to only execute when the key matches. This causes the check to run for unrelated option keys likevalidPackageRule,extraBadPackageNames, etc.
if isRuleOption(k, "skipPackageNameCollisionWithGoStd") {
r.skipPackageNameCollisionWithGoStd = true
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
alexandear
left a comment
There was a problem hiding this comment.
Please resolve conflicts.
rule/var_naming.go
Outdated
| } | ||
| r.extraBadPackageNames[strings.ToLower(n)] = struct{}{} | ||
| } | ||
| case isRuleOption(k, "validPackageRule"): |
There was a problem hiding this comment.
I propose naming the option packageNamePattern. What do you think?
There was a problem hiding this comment.
Sure happy with that :)
README.md
Outdated
| This rule accepts two slices of strings, an allowlist and a blocklist of | ||
| initialisms. By default, the rule behaves exactly as the alternative | ||
| in `golint` but optionally, you can relax it | ||
| (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89)) |
There was a problem hiding this comment.
Please do not modify lines that are not related to the PR.
There was a problem hiding this comment.
Sorry about this I must have been trying to fix the markdown linter
# Conflicts: # rule/var_naming.go
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
…nto feat/1588-package-name-regex # Conflicts: # README.md
|
Sorry for the delay, I have been ill. Thanks for the reviews @alexandear & @chavacava I have updated PR now |
|
Let's wait before merging. I think we should move the package-naming-related checks out of the We already have #1603, and this PR will further complicate Give me three or four days to think about what we should do. |
Agree. But the new rule will be a mix of golint checks and new checks. Do we abandon the "golint drop-in replacement" promise? Do we make the new rule to do golint-checks by default but add a conf flag to activate newer checks? |
|
Do we still need to follow the drop-in replacement promise? It can be the right time to diverge and go our own way ;) |
|
@chavacava Should I close this PR? |
Hi @Acollie, no need to close the PR. Thanks for the work and the patience. |
No problem happy to migrate to a new rule if needed :) |
|
Happy new year! What do you want me todo with this PR? |

#1588