Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inline directive to ignore a given line #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ Spell-checking Options
see the tokens "``lpha``", "``eta``", "``amma``", and "``elta``".


--disable-nospell\
By default, **scspell** will ignore any lines in a file which contain the
string ``# nospell``. This inline directive allows users to select lines to
ommit from spell checking at their discretion.

The ``--disable-nospell`` will disable this functionality, and ``# nospell``
directives will be ignored by **scspell**.

Creating File IDs
-----------------

Expand Down
21 changes: 18 additions & 3 deletions scspell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
# File-id specifiers take this form
FILE_ID_REGEX = re.compile(r'scspell-id:[ \t]*([a-zA-Z0-9_\-]+)')

# No spell-checking directive (ignores line)
NO_SPELL = "# nospell"


class MatchDescriptor(object):

Expand Down Expand Up @@ -542,7 +545,8 @@ def spell_check_token(
False)


def spell_check_file(filename, dicts, ignores, report_only, c_escapes):
def spell_check_file(filename, dicts, ignores, report_only, c_escapes,
disable_nospell):
"""Spell check a single file.

:param filename: name of the file to check
Expand Down Expand Up @@ -580,6 +584,12 @@ def spell_check_file(filename, dicts, ignores, report_only, c_escapes):
else:
token_regex = TOKEN_REGEX

if not disable_nospell:
# Remove lines with the '# nospell' directive
source_text = "".join(
[l for l in source_text.splitlines(True) if NO_SPELL not in l]
)

# Search for tokens to spell-check
data = source_text
pos = 0
Expand Down Expand Up @@ -711,7 +721,7 @@ def find_dict_file(override_dictionary):
def spell_check(source_filenames, override_dictionary=None,
base_dicts=[],
relative_to=None, report_only=False, c_escapes=True,
test_input=False,
disable_nospell=False, test_input=False,
additional_extensions=None):
"""Run the interactive spell checker on the set of source_filenames.

Expand All @@ -732,7 +742,8 @@ def spell_check(source_filenames, override_dictionary=None,
dicts.register_extension(*extension)
ignores = set()
for f in source_filenames:
if not spell_check_file(f, dicts, ignores, report_only, c_escapes):
if not spell_check_file(f, dicts, ignores, report_only, c_escapes,
disable_nospell):
okay = False
return okay

Expand Down Expand Up @@ -845,6 +856,10 @@ def main():
'--no-c-escapes', dest='c_escapes',
action='store_false', default=True,
help='treat \\label as label, for e.g. LaTeX')
spell_group.add_argument(
'--disable-nospell', action='store_true',
help='Disable the effect of "# nospell". This will spell check lines '
'with "# nospell" in.')

dict_group.add_argument(
'--override-dictionary', dest='override_filename',
Expand Down