在编写代码时,Linting 是一项非常宝贵的技术。然而,我发现自己想要更多地了解 linting 的过程。为此,我正在使用 node.js 构建一个基本的静态代码分析工具。
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
Run Code Online (Sandbox Code Playgroud)
和 eslint 示例输出:
/Users/dawsonbotsford/code/regexLinter/cli.js
3:1 error Parsing error: The keyword 'const' is reserved
Run Code Online (Sandbox Code Playgroud)
我将如何使用正确类型的 shell 错误/警告来模拟此输出,以便它可以插入到 sublime-contrib 插件、CI 服务器等中?
String.prototype使用参数数组调用函数时,我会遇到意外行为.
'foo'.concat.apply(this, ['bar','faz']);
//actual=> [object global]barfaz
//expected=> foobarfaz
'foo'.repeat.apply(this, [3]);
//actual=> [object global][object global][object global]
//expected=> foofoofoo
Run Code Online (Sandbox Code Playgroud)
我只收到原型函数调用的这些问题,这些调用具有我正在调用的参数apply:
'FOO'.toLowerCase();
//actual & expected=> foo
Run Code Online (Sandbox Code Playgroud)
我试图手动传入参数没有apply,但在我的最终代码中我需要apply一个数组参数,所以似乎没有办法apply.