Open a-t-0 opened 2 years ago
This is a feature we would really like to have. The current approach of only allowing a global ignore list has many disadvantages:
ignore-words-list
will result in merge conflictsIt seems it would be so easy to implement and support such a feature. A suggestion from @markcmiller86 in https://github.com/betterscientificsoftware/bssw.io/pull/1874 is ...
Since codespell
operates on ascii files only, it just needs to look of a magic ascii phrase of some kind (unlikely to ever appear in any real ascii content) that can be used as a sort of meta-escape character so that when it is encountered, data following it (or perhaps bracketed by it, etc.) can then be passed to codespell. That doesn't rely on any knowledge of the particular ascii format in use. It just requires some ingenuity and creativity...
@codespell-ignore-words{...}
Then, anyone wanting to use that needs to find their own way to harmlessly embed it in their ascii files...
<!-- @codespell-ignore-words{...} -->
// @codespell-ignore-words{...}
..
_@codespell-ignore-words{...}
# @codespell-ignore-words{...}
[//]: # @codespell-ignore-words{...}
c @codespell-ignore-words{...}
This is a more common feature for spell checkers and less intrusive than the inline ignore feature discussed in:
I have different approaches to this issue:
We currently can specify a file that has line that when matched exactly are excluded (-x
option).
I suggest to add the possibility to add a yaml configuration file that allows to specify a regex expression for the file name and a regex for lines/groups of lines to exclude for matched files. To allow this configuration to evolve, I add a key
Example:
regex_excludes:
- files: (?x)^(.*/file1.*php|.*/.*-group-.*)$
regex: \b\$varname\b
multiline_regex: \bcodespell:disable\b.*?\bcodespell:enable\b
- files: (?x)^(.*/file2.*php|.*/.*-othergroup-.*)$
regex: \b\$othervarname\b
multiline_regex: \bcodespell:disable\b.*?\bcodespell:enable\b
- files: \.cpp$
multiline_regex: \bcodespell:disable\b.*?\bcodespell:enable\b
At least one key would be required (regex or multiline_regex). If 'files' is missing, the regex expression apply to all files.
I imagine the algorithm could be the following for the multine_regex:
I created a script that helps maintain the file of exceptions. It can be run once codespell only reports exceptions that you do not want to exclude in a different way.
https://gist.github.com/mdeweerd/edecd82d542b150859f65e6b73bdef79
Context
Suppose one wants to ignore the word:"cips" in a file
latex/references.bib
, yet one would not want to ignore that word in other files.Example
Normally, one could ignore spelling mistakes in file
latex/references.bib
with an ignore list of words in file:codespell/ignore_references_bib.txt
using:However, this applies that list of ignored words, to all files.
Question
(How) is it possible to only apply a file with ignored words, to a specific file only?