Repository: mgechev/revive
Pull request #1132 (2024-11-16 11:50:56)

Filename-format rule: fix filename extension regex: ".go" to "\\.go".
Just a quick fix for an obvious issue with the filename regex. Filename extension's dot wasn't escaped so, for example, "awesome$go" was considered a valid filename.

denarced: True, very hard to find a victim. I've seen this type of slip-ups (not escaping filename extension dots in regex) many times before and in all cases, no one ever found the defect in production. I don't know the project so there was a chance that the fix was somehow useful, it was suppose to be quick (it actually wasn't), so I just fixed it. If I ended up breaking something, please just revert the commit :).
ccoVeille: I'll let other people provide feedbacks.

But for me, you "bug fix" is legitimate
chavacava: Hi @denarced, thanks for the fix.

Patch:
diff --git a/RULES_DESCRIPTIONS.md b/RULES_DESCRIPTIONS.md
index f741224..06e5272 100644
--- a/RULES_DESCRIPTIONS.md
+++ b/RULES_DESCRIPTIONS.md
@@ -521,7 +521,7 @@ Example:
 ```
 
 ## filename-format
-_Description_: enforces conventions on source file names. By default, the rule enforces filenames of the form `^[_A-Za-z0-9][_A-Za-z0-9-]*.go$`: Optionally, the rule can be configured to enforce other forms.
+_Description_: enforces conventions on source file names. By default, the rule enforces filenames of the form `^[_A-Za-z0-9][_A-Za-z0-9-]*\.go$`: Optionally, the rule can be configured to enforce other forms.
 
 _Configuration_: (string) regular expression for source filenames.
 
@@ -529,7 +529,7 @@ Example:
 
 ```toml
 [rule.filename-format]
-    arguments=["^[_a-z][_a-z0-9]*.go$"]
+    arguments=["^[_a-z][_a-z0-9]*\\.go$"]
 ```
 
 ## flag-parameter
diff --git a/revive.toml b/revive.toml
index 304909d..298dd71 100644
--- a/revive.toml
+++ b/revive.toml
@@ -21,7 +21,7 @@ warningCode = 1
 [rule.exported]
 [rule.filename-format]
     # Override the default pattern to forbid .go files with uppercase letters and dashes.
-    arguments=["^[_a-z][_a-z0-9]*.go$"]
+    arguments=["^[_a-z][_a-z0-9]*\\.go$"]
 [rule.increment-decrement]
 [rule.indent-error-flow]
 [rule.line-length-limit]
diff --git a/rule/filename_format.go b/rule/filename_format.go
index 9d80478..dbdb42d 100644
--- a/rule/filename_format.go
+++ b/rule/filename_format.go
@@ -53,7 +53,7 @@ func (*FilenameFormatRule) Name() string {
 	return "filename-format"
 }
 
-var defaultFormat = regexp.MustCompile("^[_A-Za-z0-9][_A-Za-z0-9-]*.go$")
+var defaultFormat = regexp.MustCompile(`^[_A-Za-z0-9][_A-Za-z0-9-]*\.go$`)
 
 func (r *FilenameFormatRule) configure(arguments lint.Arguments) {
 	argsCount := len(arguments)


Test patch:
diff --git "a/testdata/filenam\320\265_with_non_ascii_char.go" "b/testdata/filenam\320\265_with_non_ascii_char.go"
index d6cf886..d70d2bf 100644
--- "a/testdata/filenam\320\265_with_non_ascii_char.go"
+++ "b/testdata/filenam\320\265_with_non_ascii_char.go"
@@ -1,3 +1,3 @@
 package main
 
-// MATCH:1 /Filename filenamе_with_non_ascii_char.go is not of the format ^[_A-Za-z0-9][_A-Za-z0-9-]*.go$. Non ASCII character е (U+0435) found./
+// MATCH:1 /Filename filenamе_with_non_ascii_char.go is not of the format ^[_A-Za-z0-9][_A-Za-z0-9-]*\.go$. Non ASCII character е (U+0435) found./