在Python世界中,作为最广泛使用的静态代码分析工具之一,pylint
有一个special check ,检测注释和文档字符串中的拼写错误。
有没有办法使用静态代码分析检测 JavaScript 代码中的拼写错误?
为了使问题更具体,这里是我想要引起警告的示例代码:
// enter credntials and log in
scope.loginPage.logIn(browser.params.regularUser.login, browser.params.regularUser.password);
此处 credntials
拼写错误。
最佳答案
有一个 eslint
插件专门为这个任务构建 - eslint-plugin-spellcheck
:
eslint plugin to spell check words on identifiers, Strings and comments of javascript files.
它基于 hunspell-spellchecker
知道如何解析和使用 Hunspell
的库已知单词词典:
Hunspell is a spell checker and morphological analyzer designed for languages with rich morphology and complex word compounding and character encoding, originally designed for the Hungarian language.
这是问题中提供的示例代码的输出:
$ 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
该插件易于定制,可以检查注释、标识符和字符串。
关于javascript - 检测 JavaScript 代码中的拼写错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235963/