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

Spellchecker comments in multi-line string literals should not have any effect #3213

Open
tkw1536 opened this issue Apr 27, 2024 · 1 comment

Comments

@tkw1536
Copy link

tkw1536 commented Apr 27, 2024

Magic spellchecker:... comments in multi-line string literals incorrectly have an effect on the checking process.

As an example, consider the following python file.

# create a multi-line string literal.
# it should be checked for spelling correctness
# but no "spellchecker:..." comments should be parsed
# (reason being they're not comments at all, they're just part of the string).
SOMETHING="""
# spellchecker:words asdjkfasdhjgfasdjhgfhjasgfjasgfjhsg 
"""

# the following line should fail the spellcheck, but doesn't
# asdjkfasdhjgfasdjhgfhjasgfjasgfjhsg

I'm using plugin version 3.0.1 on vscodium 1.88.1.
I've used a python file in this example, but have reproduced the same problem with other languages that support multi-line literals, such as go and javascript.

@Nahor
Copy link

Nahor commented May 25, 2024

I don't think the extension can do anything about it, it's CSpell doing this interpretation. And I assume CSpell does a simple word extraction and has no notion of the language syntax.

For instance, this issue is not limited to multi-line strings, it will fail with single-line ones as well:

SOMETHING="spellchecker:words uiop "
# uiop

Note the extra space before the closing " otherwise that character will prevent the word from being added to the dictionary. Alternatively, more than one word could be in the string and all be the last would be added to the dictionary:

SOMETHING="spellchecker:words uiop hjkl"
# uiop is in the dictionary
# hjkl is not because of attached "

As a work around, you could use some hexadecimal encoding so that cspell wouldn't recognize the configuration, but convert to a valid one once saved to a file (note the \x65):

SOMETHING="""
# spellcheck\x65r:words asdjkfasdhjgfasdjhgfhjasgfjasgfjhsg
"""

That said, I don't understand why you think it's a problem in the first place. Without that behavior, spellchecking the python code will complain that your multi-line string has a spelling error:
image
which is probably not what you want.

And if you want spellchecking to be completely ignored in multi-line strings instead, you could use a pattern such as /("{3}|'{3})\n[\S\s]*?\n\1/gmx in the C Spell: Ignore Reg Exp List setting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants