检测JavaScript代码中的拼写错误 [英] Detecting typos in JavaScript code

查看:341
本文介绍了检测JavaScript代码中的拼写错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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);

此处 credntials 拼写错误。

推荐答案

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

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


eslint插件拼写检查javascript文件的标识符,字符串和注释的单词。

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

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

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


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

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.

这篇关于检测JavaScript代码中的拼写错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆