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

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工作的Android KitKat代码在棒棒糖设备上崩溃   java Android以长变量存储文件大小   JavaSpring请求映射映射唯一端点中的所有GET请求   java为什么我的代码告诉我初始化一个已经初始化的变量?   使用IntelliJ IDEA部署java多模块项目   如何让eclipse为Java使用不同的编译器版本?   如何在将行导出到Excel Java时替换默认jtable列值   表达式使用faker生成java姓氏,但只需要字母   Lisp链表仿真Java   java将泛型类型放在何处   java useDelimiter,读取第一个分隔符,然后更改行   java如何正确处理文件中的数字输入?   java组织。springframework。数据领域无法将PageImpl强制转换为   有没有可能让SpringMVCWeb应用程序作为嵌入Java和Tomcat的“独立可执行文件”运行?   java Log4j,可在不同文件中写入   java如何设置只在安卓首次发布时出现的活动?   java JFreeChart AutoRange不适用于同一绘图上的多个系列   用汉字声明字符串的java