Skip to content
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

How to match backticks in styles? #43

Closed
abingham opened this issue May 24, 2017 · 6 comments
Closed

How to match backticks in styles? #43

abingham opened this issue May 24, 2017 · 6 comments

Comments

@abingham
Copy link

I think I'm just being dense, but I can't figure out how to match backticks ("`" characters) in a swap rule. I'm linting a book on Python, and we want to standardize how we spell e.g. "for-loop". So I want a rule like this (simplified from what we really want):

swap:
  'for loop': for-loop
  '`for` loop': for-loop

But this doesn't seem to work. The first rule works just fine, but the second one with backticks doesn't seem to fire. How can I make this work?

@abingham
Copy link
Author

Does vale actually just ignore the backticks, quotation marks, and other "surrounding stuff"?

@jdkato
Copy link
Member

jdkato commented May 24, 2017

By default, Vale ignores the syntax equivalent of <pre> and <code> tags in markup and everything but comments in source code. You can disable this behavior by passing --ignore-syntax, but you'll then also lose the ability to target things like headings and lists individually.

For example, given a Markdown file with the following contents:

This is a for loop. This is also a `for` loop.

and this rule definition:

# Named Back.yml
extends: substitution
message: Consider using '%s' instead of '%s'
level: warning
nonword: true # "`" is a non-word character
swap:
  'for loop': for-loop
  '`for` loop': for-loop

Running vale --output=line test.md yields:

test.md:1:11:test.Back:Consider using 'for-loop' instead of 'for loop'

And vale --ignore-syntax --output=line test.md gives the desired:

test.md:1:11:test.Back:Consider using 'for-loop' instead of 'for loop'
test.md:1:36:test.Back:Consider using 'for-loop' instead of '`for` loop'

In a future build, I'd like to add an IgnoredScopes setting to the config file to make this a little more flexible. I also should expand on this more in the docs probably.

@abingham
Copy link
Author

OK, thanks for the details. That works well for me. Should I close this out, or do you want to keep it open?

@jdkato
Copy link
Member

jdkato commented May 25, 2017

I'll leave it open until I get around to improving the documentation on the command line flags.

jdkato added a commit that referenced this issue May 28, 2017
This allows rules to target text inside code spans.

Closes #44; related to #43
@jdkato
Copy link
Member

jdkato commented May 28, 2017

I've added a new option to make code spans available on a per-rule basis (see #44). So, the updated definition would be:

extends: substitution
message: Consider using '%s' instead of '%s'
level: warning
nonword: true
code: true
swap:
  'for loop': for-loop
  '`for` loop': for-loop

And you can run normally (without --ignore-syntax).

(Updated docs are also forthcoming.)

@jdkato jdkato closed this as completed May 28, 2017
@abingham
Copy link
Author

Brilliant, thanks!

abingham pushed a commit to sixty-north/style-guide that referenced this issue May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants