errata-ai / vale

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
https://vale.sh
MIT License
4.44k stars 153 forks source link

Ruby format treats interpolated strings as comments. #818

Closed reitermarkus closed 4 months ago

reitermarkus commented 5 months ago

Check for existing issues

Environment

Using the Ruby format, strings with interpolation are treated as comments.

macOS/Homebrew/3.4.1

Describe the bug / provide steps to reproduce it

Running vale with the style rule

---
extends: existence
message: "'%s' should have one space."
link: "https://github.com/Homebrew/brew/blob/HEAD/docs/Prose-Style-Guidelines.md#typographical-conventions"
level: error
nonword: true
tokens:
  - "[a-z][.?!][A-Z]"
  - "[.?!] {2,}[A-Z]"

on a Ruby file containing

"#{args.HEAD?}"

results in

 1:7  error  's.H' should have one space.  Homebrew.Spacing 
reitermarkus commented 5 months ago

A similar issue occurs with multi-line strings containing #, e.g.

<<~EOS
# Not a Comment
EOS
reitermarkus commented 5 months ago

And another issue, cause by the shebang line and a ruby: Ruby rule.

#!/usr/bin/env ruby
reitermarkus commented 5 months ago

And yet another issue, also with the ruby: Ruby rule, caused by a regex being treated as a comment:

%r{https://example\.org/#compatibility-with-ruby-mri\.},
jdkato commented 5 months ago

All of these issues are a product of trying to identify comments using only regex. This is (obviously) not the right way to do this.

I have two branches currently exploring other solutions, tree-sitter and chroma, so this will eventually be fixed.

jdkato commented 4 months ago

These issues should be fixed now on the v3 branch, if you'd like to try it out.