diff --git a/internal/lint/code.go b/internal/lint/code.go index 07ae7260..6db7ab58 100755 --- a/internal/lint/code.go +++ b/internal/lint/code.go @@ -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) diff --git a/internal/lint/data.go b/internal/lint/data.go index d0e1cfb2..48b6ca08 100644 --- a/internal/lint/data.go +++ b/internal/lint/data.go @@ -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 diff --git a/testdata/e2e/lint.yaml b/testdata/e2e/lint.yaml index fff2649a..644ecf92 100644 --- a/testdata/e2e/lint.yaml +++ b/testdata/e2e/lint.yaml @@ -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 diff --git a/testdata/e2e/views.yaml b/testdata/e2e/views.yaml index 421c4085..b991fe13 100644 --- a/testdata/e2e/views.yaml +++ b/testdata/e2e/views.yaml @@ -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'?