Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/lint/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (l *Linter) skipsComment(scope string) bool {
}

func (l *Linter) lintCode(f *core.File) error {
lang, err := code.GetLanguageFromExt(f.RealExt)
lang, err := code.GetLanguageFromExt(f.NormedExt)
if err != nil {
// No tree-sitter grammar available for this file type.
return l.lintCodeOld(f)
Expand Down
2 changes: 1 addition & 1 deletion internal/lint/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (l *Linter) lintData(f *core.File) error {
// lintDataComments lints the comments of a data file that has a grammar --
// YAML or TOML -- and does nothing for one that has no comments to read.
func (l *Linter) lintDataComments(f *core.File) error {
if _, err := code.GetLanguageFromExt(f.RealExt); err == nil {
if _, err := code.GetLanguageFromExt(f.NormedExt); err == nil {
return l.lintCode(f)
}
return nil
Expand Down
76 changes: 76 additions & 0 deletions testdata/e2e/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,82 @@ cases:
test.pl:5:21:vale.Annotations:'XXX' left in text
test.pl:8:7:vale.Annotations:'TODO' left in text

- name: perl-format-mapping
about: a `.nix` file has no grammar, so under `nix = pl` Vale reads its
comments as Perl comments
files:
.vale.ini: |
StylesPath = styles
MinAlertLevel = suggestion

[formats]
nix = pl

[*]
T.Tok = YES
styles/T/Tok.yml: |
extends: existence
message: "'%s' found"
level: error
tokens:
- ZQX
default.nix: |
# A ZQX in a comment.
{ value = "ZQX"; }
args: default.nix
exit: 1
want: |
default.nix:1:5:T.Tok:'ZQX' found

- name: perl-ext-flag
about: a `.nix` file has no grammar, so under `--ext=.pl` Vale reads its
comments as Perl comments
files:
.vale.ini: |
StylesPath = styles
MinAlertLevel = suggestion

[*]
T.Tok = YES
styles/T/Tok.yml: |
extends: existence
message: "'%s' found"
level: error
tokens:
- ZQX
default.nix: |
# A ZQX in a comment.
{ value = "ZQX"; }
args: "--ext=.pl default.nix"
exit: 1
want: |
default.nix:1:5:T.Tok:'ZQX' found

- name: ext-flag-overrides-grammar
about: "`--ext=.c` parses a `.ts` file as C even though TypeScript has a
grammar, so `//` in a template literal starts a comment"
files:
.vale.ini: |
StylesPath = styles
MinAlertLevel = suggestion

[*]
T.Tok = YES
styles/T/Tok.yml: |
extends: existence
message: "'%s' found"
level: error
tokens:
- ZQX
test.ts: |
const s = `// ZQX in a template literal`;
// ZQX in a comment.
args: "--ext=.c test.ts"
exit: 1
want: |
test.ts:1:15:T.Tok:'ZQX' found
test.ts:2:4:T.Tok:'ZQX' found

- name: php
args: test.php
exit: 0
Expand Down
31 changes: 31 additions & 0 deletions testdata/e2e/views.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,34 @@ cases:
site.yml:1:7:Vale.Spelling:Did you really mean 'defalt'?
site.yml:2:23:Vale.Spelling:Did you really mean 'storag'?
site.yml:3:29:Vale.Spelling:Did you really mean 'trailng'?

- name: data-comments-format-mapping
about: a `.conf` file has no grammar, so under `conf = yml` Vale reads its
comments as YAML comments
files:
.vale.ini: |
StylesPath = styles
MinAlertLevel = suggestion

[formats]
conf = yml

[*.conf]
BasedOnStyles = Vale
Vale.Terms = NO
Vale.Avoid = NO
Vale.Repetition = NO
View = Data
styles/config/views/Data.yml: |
engine: dasel
scopes:
- name: title
expr: title
site.conf: |
# The defalt settings.
title: A guide to the storag layer
args: site.conf
exit: 1
want: |
site.conf:1:7:Vale.Spelling:Did you really mean 'defalt'?
site.conf:2:23:Vale.Spelling:Did you really mean 'storag'?
Loading