Skip to content

Fix readme comment example #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

craigfurman
Copy link
Contributor

Regex special characters like . must be escaped for the whole comment
string to be treated as one group, otherwise the comment is truncated.


Ironically, the example I introduced in my last PR (#11) doesn't work! I'll look into PR'ing the golangci-lint docs site too.

Regex special characters like `.` must be escaped for the whole comment
string to be treated as one group, otherwise the comment is truncated.
@ashanbrown
Copy link
Owner

Is there any way we can make it so special characters (other than ( and )) don't need to be escaped?

@ashanbrown ashanbrown merged commit 7e48566 into ashanbrown:master Feb 19, 2022
@ashanbrown
Copy link
Owner

@craigfurman I didn't see an easy answer to my question. I did make a change at #13 so that at least we don't truncate these strings, but I don't see an easy way to recover the original string prior to regexp parsing.

@craigfurman craigfurman deleted the fix-readme-comment-example branch February 20, 2022 17:11
@craigfurman
Copy link
Contributor Author

I haven't tested #13 yet, but that looks like it would do the trick!

@craigfurman
Copy link
Contributor Author

I just tried your PR out, I see what you mean now. Off the top of my head (I've not thought long about this), as long as we're parsing the regex it'll be awkward and error-prone to try to reconstruct a string.

If we want the comment to be treated as an opaque string (and not a regex), we might have to double-parse the input, to extract the forbidden regex and the comment as two capture groups, and then compile the regex portion again. IIRC that was the original implementation of #11, but that had some downsides too.

After #13, I think we're in quite a good place now that the comment isn't truncated. Users might be more likely to figure out what's going on, and hopefully escape the special characters. That's also now documented here, and my PR to update https://golangci-lint.run/usage/linters/ was recently merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants