创建 linter 时,预期的输出格式是什么?

When creating a linter, what is the expected output format?

在编写代码时,linting 是一种非常宝贵的技术。然而,我发现自己想要更多地了解 linting 的过程。为此,我正在使用 node 构建一个基本的静态代码分析工具。

linter 应该做的是执行正则表达式检查,如果正则表达式匹配,则抛出错误(或警告,具体取决于用户的配置)。

我知道 linters 传统上解析代码,有些甚至在 AST 上执行检查,但我想完全避免这种情况。我也明白我的方法通过完全避免解析语法来绕过 linting 的几乎每个重要部分。


目标是能够编写一些非常简单的检查,并将其作为快速原型制作的附件 linter。 (例如:将 ^$\n^$ 放入我的 linter 配置中,两个连续的空白行将引发错误)

过程中似乎未记录的部分是命令行预期的输出类型。这是 xo:

的示例输出
/Users/dawsonbotsford/code/regexLinter/cli.js
  42:9   error  Expected indentation of 6 space characters but found 8   indent
  43:9   error  Expected indentation of 6 space characters but found 8   indent
  43:32  error  Missing semicolon                                        semi

和 eslint 示例输出:

/Users/dawsonbotsford/code/regexLinter/cli.js
  3:1  error  Parsing error: The keyword 'const' is reserved

我如何使用正确类型的 shell errors/warnings 模拟此输出,以便它可以插入 sublime-contrib 插件、CI 服务器等?

如果你希望它是可插拔的,你可以做的最简单的事情就是为 ESLint if you need to capture formatting issues. If you want to transform code use Putout 编写一个插件,我正在使用的工具,它还有一个用于 ESLint[= 的插件14=] 所以你要显示的消息可以在终端中访问,IDE、CI 等