Skip to content

Commit

Permalink
feat: add SkippedScopes and 'blockquote'
Browse files Browse the repository at this point in the history
This commit add the ability to tell Vale which scopes it should skip outright
and introduces a new 'blockquote' scope.
  • Loading branch information
jdkato committed Jan 14, 2019
1 parent 28a3015 commit 95601cd
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/config.go
Expand Up @@ -53,6 +53,7 @@ type Config struct {
GBaseStyles []string // Global base style
GChecks map[string]bool // Global checks
IgnoredScopes []string // A list of HTML tags to ignore
SkippedScopes []string // A list of HTML blocks to ignore
BlockIgnores map[string][]string // A list of blocks to ignore
TokenIgnores map[string][]string // A list of tokens to ignore
MinAlertLevel int // Lowest alert level to display
Expand Down Expand Up @@ -166,6 +167,8 @@ func LoadConfig(cfg *Config, upath string) (*Config, error) {
cfg.IgnoredScopes = core.Key(k).Strings(",")
} else if k == "WordTemplate" {
cfg.WordTemplate = core.Key(k).String()
} else if k == "SkippedScopes" {
cfg.SkippedScopes = core.Key(k).Strings(",")
}
}

Expand Down
17 changes: 17 additions & 0 deletions features/scopes.feature
@@ -1,4 +1,21 @@
Feature: Scopes

Scenario: Blockquote
When I test scope "blockquote"
Then the output should contain exactly:
"""
test.adoc:5:12:rules.Quote:Don't use 'here' in a blockquote.
test.md:3:20:rules.Quote:Don't use 'here' in a blockquote.
test.rst:3:22:rules.Quote:Don't use 'here' in a blockquote.
"""

Scenario: Skip
When I test scope "skip"
Then the output should contain exactly:
"""
test.md:3:1:vale.Annotations:'TODO' left in text
"""

Scenario: Attr
When I test scope "attr"
Then the output should contain exactly:
Expand Down
5 changes: 5 additions & 0 deletions fixtures/scopes/blockquote/.vale.ini
@@ -0,0 +1,5 @@
StylesPath = ../../scopes
MinAlertLevel = suggestion

[*]
rules.Quote = YES
6 changes: 6 additions & 0 deletions fixtures/scopes/blockquote/test.adoc
@@ -0,0 +1,6 @@
We can say here outside of a quote.

[quote]
____
We can say here outside of a quote.
____
3 changes: 3 additions & 0 deletions fixtures/scopes/blockquote/test.md
@@ -0,0 +1,3 @@
We can say here outside of a quote.

> But we can't say here inside of one!
3 changes: 3 additions & 0 deletions fixtures/scopes/blockquote/test.rst
@@ -0,0 +1,3 @@
We can say here outside of a quote.

But we can't say here inside of one!
7 changes: 7 additions & 0 deletions fixtures/scopes/rules/Quote.yml
@@ -0,0 +1,7 @@
message: "Don't use '%s' in a blockquote."
extends: existence
ignorecase: true
scope: blockquote
level: error
tokens:
- here
7 changes: 7 additions & 0 deletions fixtures/scopes/skip/.vale.ini
@@ -0,0 +1,7 @@
StylesPath = ../../scopes
MinAlertLevel = suggestion

SkippedScopes = script, style, pre, figure, blockquote

[*]
vale.Annotations = YES
5 changes: 5 additions & 0 deletions fixtures/scopes/skip/test.md
@@ -0,0 +1,5 @@
## An example of custom scoping

TODO: This should be flagged.

> TODO: This should NOT be flagged.
12 changes: 9 additions & 3 deletions lint/markup.go
Expand Up @@ -66,9 +66,10 @@ var inlineTags = []string{
"b", "big", "i", "small", "abbr", "acronym", "cite", "dfn", "em", "kbd",
"strong", "a", "br", "img", "span", "sub", "sup", "code", "tt"}
var tagToScope = map[string]string{
"th": "text.table.header",
"td": "text.table.cell",
"li": "text.list",
"th": "text.table.header",
"td": "text.table.cell",
"li": "text.list",
"blockquote": "text.blockquote",
}

func (l Linter) lintHTMLTokens(f *core.File, ctx string, fsrc []byte, offset int) {
Expand All @@ -81,6 +82,11 @@ func (l Linter) lintHTMLTokens(f *core.File, ctx string, fsrc []byte, offset int
buf := bytes.NewBufferString("")
act := bytes.NewBufferString("")

// The user has specified a custom list of tags to ignore.
if len(l.Config.SkippedScopes) > 0 {
skipTags = l.Config.SkippedScopes
}

// queue holds each segment of text we encounter in a block, which we then
// use to sequentially update our context.
queue := []string{}
Expand Down

0 comments on commit 95601cd

Please sign in to comment.