Code
Learn how Vale handles source code.
Vale lints the comments in source code, found with a tree-sitter grammar for each language below. Clojure and PowerShell have no bundled grammar and are read with comment patterns instead. A one-line comment is scoped text.comment.line and a comment spanning lines text.comment.block, each followed by the file's extension.
C
.c, .h
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Clojure
.clj, .cljs, .cljc, .cljd
; (text.comment.line.ext)
C#
.cs, .csx
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
C++
.cpp, .cc, .cp, .cxx, .c++, .hpp, .h++
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
CSS
.css
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Elixir
.ex, .exs
# (text.comment.line.ext),
@doc (text.comment.doc.line.ext),
@moduledoc (text.comment.doc.block.ext)
Go
.go
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Haskell
.hs
-- (text.comment.line.ext),
{- (text.comment.block.ext)
Java
.java, .bsh
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
JavaScript
.js, .jsx
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Julia
.jl
# (text.comment.line.ext),
#= (text.comment.block.ext)
LESS
.less
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Lua
.lua
-- (text.comment.line.ext),
--[[ (text.comment.block.ext)
Perl
.pl, .pm, .pod
# (text.comment.line.ext)
PHP
.php
// (text.comment.line.ext),
# (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
PowerShell
.ps1, .psm1, .psd1
# (text.comment.line.ext),
<#...#> (text.comment.line.ext),
<# (text.comment.block.ext)
Protobuf
.proto
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Python
.py, .py3, .pyw, .rpy, .cpy, SConstruct
# (text.comment.line.ext),
""" (text.comment.block.ext)
QML
.qml
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
R
.r, .R
# (text.comment.line.ext)
Ruby
.rb, Gemfile, Rakefile, Brewfile, .gemspec
# (text.comment.line.ext),
^=begin (text.comment.block.ext)
Rust
.rs
// (text.comment.line.ext)
Sass
.sass, .scss
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Scala
.scala, .sbt
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Swift
.swift
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
TypeScript
.ts, .tsx
// (text.comment.line.ext),
/.../ (text.comment.line.ext),
/* (text.comment.block.ext)
Documentation attributes
Elixir has no documentation comment syntax: its published API documentation lives in module attributes holding a string or a heredoc, and that is what mix docs renders.
Both comments and attributes are extracted. @moduledoc, @doc, @typedoc, and @shortdoc carry a doc scope—text.comment.doc.line and text.comment.doc.block—so published documentation can be held to a different standard than an implementation note, or excluded on its own via IgnoredScopes. @doc false and @doc since: "1.0.0" hold no prose, and neither is extracted.
Associations
In many languages, it’s common for comments to contain embedded markup (e.g., Markdown, reStructuredText, etc.) within them. For example, consider the following Rust doc comment:
If the embedded markup is one of the supported formats, you can associate the comment scope with a markup type. This will allow you to lint the embedded markup as if it were a standalone file.
Once a markup format has been assigned, you can make use of all the supported features of that format (such as ignore patterns and comment-based configuration) in your source code comments.
This includes TokenIgnores and BlockIgnores, which are otherwise unavailable in source code: they work by wrapping a match in the format's inline or block code delimiter, so they need a markup format to wrap it with. Associating one makes them available.
Block comment decoration
Block comments in C-style languages conventionally decorate each line with a leading asterisk:
That decoration is removed before the comment is handed to the markup parser, so the body above is read as a paragraph followed by a list—not as one long list, which is what the leading asterisks would otherwise make it.
Relative indentation is preserved, so indented code blocks inside a comment still work:
The fenced block is treated as code and left alone, exactly as it would be in a standalone Markdown file.
Last updated