Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

feature_request(ignoring): ignoring words based on their context

未关闭
#3,679 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

Start by reviewing the related issues (#410, #2491, and #3673), then inspect how Codespell currently handles configuration and ignored words. Done means users can configure words to be ignored only for specified contexts and file extensions, while still receiving warnings in other cases; the issue gives four example cases to check.

由索引模型根据 Issue 内容生成。

描述

Related issues: #410, #2491, #3673.

1. Summary

It would be nice if Codespell will allow ignoring words based on their context.

2. Justification of the need of the feature

This was discussed in several issues of this repository. It would be nice to have behavior where Codespell ignore words solely in specific cases but continues to return warnings for all another cases.

3. Example of desired behavior

Example YAML configuration file with keys context and extensions. Examples in this file are false positives from my project.

# [OVERVIEW] Example of a Codespell configuration file for ignoring words based on their context:
#
#
# [KEYS] Both keys are optional, but at least one of them must exists.
#
# 1. “context” — the list of contexts in which the word is ignored. List items are case-sensitive.
# If the key doesn’t exist, Codespell will ignore the word in any context.
#
# 2. “extensions” — the list of extensions for which the word is ignored.
# If the key doesn’t exist, Codespell will ignore the word for any extension.


#############
# Example 1 #
#############
# [PURPOSE] I want to get Codespell warnings for the “colour” word
# except the case where this word is used in the phrase “Colour Contrast Checker”.
#
# [INFO] “Colour Contrast Checker” is the name of the online application:
# https://github.com/Pushedskydiver/Colour-Contrast-Checker
colour:
  context:
  - Colour Contrast Checker


#############
# Example 2 #
#############
# [PURPOSE] I want to get Codespell warnings for the “isnt” typo,
# but not for the CoffeeScript built-in operator “isnt”:
# https://coffeescript.org/#operators
isnt:
  extensions:
  - coffee


#############
# Example 3 #
#############
# [PURPOSE] I want to get Codespell warnings for the “nd” typo,
# but not for the class “.nd” from the Pygments library in my CSS and Stylus files:
#
# [NOTE] I preferred more informative class names than “.nd”, but Pygments developers have the another opinion:
# https://github.com/richleland/pygments-css/blob/146834e1f9476d517c10cee5f15381047866d93d/monokai.css#L34
nd:
  context:
  - .nd
  extensions:
  - css
  - styl


#############
# Example 4 #
#############
# [PURPOSE] I want to get Codespell warnings for the “whos” typo,
# but not for the IPython built-in magic command “%whos”:
# https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-whos
whos:
  context:
  - "%whos"
  extensions:
  - py

If this file exists, Codespell will ignore colour, isnt, nd and whos for contexts provided in the file.

It would be nice if Codespell will support something like this configuration file.

4. Alternatives of context+extension ignoring
4.1. Inline ignoring

I’m not sure that codespell:ignore comments is the best solution for users.

  1. If a user gets the same false positive multiple times, he needs to add codespell:ignore comments multiple times. If a configuration file as in my example would be allowed, it would be enough for a user to make one record in a configuration.
  2. I try not to use inline ignoring at all and prefer ignoring via the configuration if it’s possible. In my opinion, it would be nice if text files contains solely texts and code files contains solely code without records especially for checkers/linters/validators.
  3. Unfortunately, currently Codespell by default doesn’t provide an opportunity ignoring words based on their context. But I hope that someday it will become possible, and users can make pull requests based on their personal configurations for cases like %whos from my example.
4.2. Per-file ignoring

In my opinion, it would be nice, that the pull request #3675 allows ignoring based on extensions, but I’m not sure that ignoring per file is the best idea. The file may contain both false positives and real typos, and if a user activate the option --per-file-ignores, he may skip real typos. The context key from my example would allow more accurate ignoring.

Thanks.

主要语言
Python
星标
2.4k
派生
531
平均合并
15 小时 5 分钟
30 天内合并 PR
18

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codespell-project/codespell 的其他 Issue

查看 codespell-project/codespell 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。