Detecting typos in JavaScript code

£可爱£侵袭症+ 提交于 2019-12-14 03:43:38

问题


In Python world, one of the most widely-used static code analysis tools, pylint has a special check, that detects typos in comments and docstrings.

Is there a way to detect typos in JavaScript code using static code analysis?


To make the question more specific, here is an example code I want to cause a warning:

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

Here credntials is misspelled.


回答1:


There is a eslint plugin built specifically for the task - eslint-plugin-spellcheck:

eslint plugin to spell check words on identifiers, Strings and comments of javascript files.

It is based on the hunspell-spellchecker library that knows how to parse and use Hunspell dictionaries of known words:

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.

Here is what it outputs for the example code provided in the question:

$ 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

The plugin is easily customizable and can check in comments, identifiers and strings.



来源:https://stackoverflow.com/questions/31235963/detecting-typos-in-javascript-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!