一个保守的交互式拼写检查源代码。

scspell的Python项目详细描述


scspell是源代码的拼写检查程序。它不会试图成为 特别聪明–相反,它做的是最简单的事情,可能奏效:

  1. All alphanumeric strings (strings of letters, numbers, and underscores) are spell-checked tokens.
  2. Each token is split into one or more subtokens. Underscores and digits always divide tokens, and capital letters will begin new subtokens. In other words, ^{tt1}$ and ^{tt2}$ will both generate the subtoken list {^{tt3}$, ^{tt4}$}.
  3. All subtokens longer than three characters are matched against a set of dictionaries, and a match failure prompts the user for action. When matching against the included English dictionary, prefix matching is employed; this choice permits the use of truncated words like ^{tt5}$ as valid subtokens.

当应用于使用最流行的编程语言编写的代码时 典型的命名约定,该算法通常会捕获许多错误 没有令人讨厌的假阳性率。

为了捕获更多的拼写错误,scspell能够检查每个 针对特定于该文件的一组字典单词创建文件。向上 可以在三个不同的子词典中搜索任何给定的文件:

  1. A natural language dictionary. (scspell provides an American English dictionary as the default.)
  2. A programming language-specific dictionary, intended to contain oddly-spelled keywords and APIs associated with that language. (scspell provides small default dictionaries for a number of popular programming languages.)
  3. A file-specific dictionary, intended to contain uncommon strings which are not likely to be found in more than a handful of unique files.

用法

要开始拼写检查,请运行

$ scspell source_file1 source_file2 ...

对于每个拼写检查失败,您将看到如下输出:

filename.c:27: Unmatched 'someMispeldVaraible' -> {mispeld, varaible}

换句话说,在第27行找到了标记“someMispeldVaraible” ,它包含副标题“mispeld”和 “varaible”这两个都没有通过拼写检查算法。你会 提示您采取行动:

(i)gnore
Skip to the next unmatched token, without taking any action.
(I)gnore all
Skip over this token every time it is encountered, for the remainder of this spell check session.
(r)eplace
Enter some text to use as a replacement for this token, and replace only the token at this point in the file.
(R)eplace all
Enter some text to use as a replacement for this token, and replace every occurrence of the token until the end of the current file.
(a)dd to dictionary
Add one or more tokens to one of the dictionaries (see below).
show (c)ontext
Print out some lines of context surrounding the unmatched token.

如果意外选择替换操作,请输入空 要取消的字符串。

如果选择(a)dd to dictionary选项,则 为每个子菜单提示以下选项:

(b)ack
Return to the previous menu, without taking any action.
(i)gnore
Skip to the next subtoken, without taking any action.
add to (p)rogramming language dictionary
Add this subtoken to the dictionary associated with the programming language of the current file. scspell uses the file extension to determine the language, so you will only see this option for files which have an extension.
add to (f)ile-specific dictionary
Add this subtoken to the dictionary associated with the current file. scspell identifies unique files by scanning for an embedded ID string, so you will only see this option for files which have such an ID. See Creating File IDs for details.
add to (n)atural language dictionary
Add this subtoken to the natural language dictionary.

创建文件id

如果希望scspell能够唯一标识文件,则 启用创建特定于文件的词典,则必须插入 文件内容中某个地方的唯一ID。scspell将扫描每个 文件格式如下:

scspell-id: <unique ID>

唯一ID只能由字母、数字、下划线和破折号组成。 scspell可以使用--gen-id选项生成合适的唯一id字符串:

$ scspell --gen-id
scspell-id: e497803c-523a-11de-ae42-0017f2ee0f37

(很可能您希望将文件的唯一id放在源代码注释中。)

共享词典

在同一个源代码树上工作的开发团队可能希望共享 字典。您可以通过以下方式永久设置共享词典的位置 执行

$ scspell --set-dictionary=/path/to/dictionary_file.txt

字典的格式是一个简单的用换行符分隔的单词列表,因此 如果需要,可以由版本控制系统轻松管理。

通过执行可以将当前词典保存到文件中

$ scspell --export-dictionary=/path/to/output_file.txt

您还可以覆盖单个拼写检查会话的字典位置, 使用--override-dictionary选项:

$ scspell --override-dictionary=/path/to/dictionary_file.txt source_file1 ...

安装

如果你有setuptools 安装后,您可以通过:

$ easy_install scspell

或者,下载并解压缩源文件,切换到 存档根目录,并运行安装脚本:

$ python setup.py install

在类unix系统上,如果安装到 需要根权限的目录:

$ sudo python setup.py install

许可证

scspell是免费软件,在gnu general的版本2下授权 公共许可证;有关详细信息,请参见COPYING.txt

随scspell一起发行的英语词典是从 SCOWL word lists。见 SCOWL-LICENSE.txt用于应用于该词典的无数许可证。

错误等

scspellhosted on Launchpad; 这将是一个很好的地方来提交bug报告和特性请求或跟踪 通过bzr开发。如果这不是你的风格,就 发送电子邮件给paul pelzl<;pelzlpj at gmail dot com>;。

为流行编程语言添加最常用关键字/api的修补程序 非常欢迎。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Kafka在producer上流式传输自定义头   java ExecutorService:不需要输出   java并发读取不可修改的映射   如何匹配Java计算机的给定输出猜你的数字游戏;二进制搜索   java使用数据库创建新对象   javascript如何用spring mvc上传图像我尝试了这种方法,如何解决这个问题   java如何使用Quarkus Panache仅选择某些字段?   java如何通知其他对象(如何“关闭”队列)ArrayBlockingQueue中将不再有元素,   java使用JavaFX MediaPlayer从MP3读取ID3v2标记   当我们在Android上打开应用程序时,java仅在第三次显示toast   apache spark java。RuntimeException:java。lang.Integer不是bigint:java架构的有效外部类型。伊奥。IOException   模拟插座。用于测试Java的getOutputStream()   java在git对分期间,只运行失败的测试安全吗?或者我们应该运行所有测试?   java Android MediaPlayer音量非常低(已调整音量)   java组织。冬眠服务UnknownServiceException:请求的未知服务[org.hibernate.ogm.service.impl.OgmConfigurationService]   java扫描程序没有停止   java无法在JBoss EAP 6.2上调用远程EJB