6

在 Python 世界中,最广泛使用的静态代码分析工具之一pylint有一个特殊的检查,可以检测注释和文档字符串中的拼写错误。

有没有办法使用静态代码分析来检测 JavaScript 代码中的拼写错误?


为了使问题更具体,这是我想引起警告的示例代码:

// enter credntials and log in
scope.loginPage.logIn(browser.params.regularUser.login, browser.params.regularUser.password);

这里credntials拼写错误。

4

2 回答 2

5

有一个eslint专门为该任务构建的插件 - eslint-plugin-spellcheck

eslint 插件,用于对 javascript 文件的标识符、字符串和注释进行拼写检查。

它基于hunspell-spellchecker知道如何解析和使用Hunspell已知单词字典的库:

Hunspell 是一个拼写检查器和形态分析器,专为具有丰富形态和复杂单词复合和字符编码的语言设计,最初是为匈牙利语设计的。

以下是它为问题中提供的示例代码输出的内容:

$ node_modules/eslint/bin/eslint.js -c eslint.json showCase.spec.js
25:8   warning  You have a misspelled word: credntials on Comment  spellcheck/spell-checker

该插件易于定制,可以签入注释、标识符和字符串。

于 2015-07-05T23:24:31.247 回答
3

您可以使用cspell。它是一个非常方便的命令行工具,可以发现 JavaScript、TypeScript、Python、PHP、C#、C++、LaTex、Go、HTML 和 CSS 源代码中的拼写错误。

您的示例的输出

cspell ./src/code.js
code.js:1:10 - Unknown word (credntials)

./src/code.js

// enter credntials and log in
scope.loginPage.logIn(browser.params.regularUser.login, browser.params.regularUser.password);
于 2020-04-07T14:54:02.223 回答