一个保守的交互式拼写检查源代码。
scspell的Python项目详细描述
scspell是源代码的拼写检查程序。它不会试图成为 特别聪明–相反,它做的是最简单的事情,可能奏效:
- All alphanumeric strings (strings of letters, numbers, and underscores) are spell-checked tokens.
- 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}$}.
- 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能够检查每个 针对特定于该文件的一组字典单词创建文件。向上 可以在三个不同的子词典中搜索任何给定的文件:
- A natural language dictionary. (scspell provides an American English dictionary as the default.)
- 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.)
- 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放在源代码注释中。)
安装
如果你有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用于应用于该词典的无数许可证。
错误等
scspell是hosted on Launchpad; 这将是一个很好的地方来提交bug报告和特性请求或跟踪 通过bzr开发。如果这不是你的风格,就 发送电子邮件给paul pelzl<;pelzlpj at gmail dot com>;。
为流行编程语言添加最常用关键字/api的修补程序 非常欢迎。