-1

I am using https://github.com/tbroadley/spellchecker-cli.

I have a JSON file that I'd like to run spellChecker on and it looks like this:

{
  "abc.editGroupsMaxLengthError": "Maximum {{charLen}} characters"
}

I would like to know how can all words between {{ and }} be ignored by the spellchecker.

I tried with

[A-Za-z]+}}

as documented here https://github.com/tbroadley/spellchecker-cli#ignore-regexes to ignore regex.

but it doesn't seem to use }} or {{ for some reason.

How can this be fixed?

systemdebt
  • 4,589
  • 10
  • 55
  • 116
  • In regular expressions braces have a special meaning. To denote literal ones, you need to escape them with a backslash. – trincot Oct 28 '21 at 20:37
  • This seems to ignore incorrect spellings with just alphabets outside of {{}} as well @WiktorStribiżew – systemdebt Oct 28 '21 at 21:31
  • That sounds like the text is pretokenized first. What input does the regex engine "see"/get? – Wiktor Stribiżew Oct 28 '21 at 21:36
  • @WiktorStribiżew Could you elaborate on What input does the regex engine "see"/get, please? – systemdebt Oct 28 '21 at 21:38
  • Most probably, you will get help [here](https://github.com/tbroadley/spellchecker-cli/issues/79) some day. After the tool is enchanced, see [this](https://github.com/tbroadley/spellchecker-cli/issues/42#issuecomment-433032852): "*Dictionaries are intended to ignore single words, not longer blocks of text.*" – Wiktor Stribiżew Oct 28 '21 at 22:20
  • Or, try [this approach](https://github.com/tbroadley/spellchecker-cli/issues/42#issuecomment-637150577) with comments. – Wiktor Stribiżew Oct 28 '21 at 22:24

1 Answers1

1

You can wrap your {{...}} substrings with <!-- spellchecker-disable --> / <!-- spellchecker-enable --> tags, see this Github issue.

So, make sure your JSON looks like

{
  "abc.editGroupsMaxLengthError": "Maximum <!-- spellchecker-disable -->{{charLen}}<!-- spellchecker-enable --> characters"
}

And the result will be

C:\Users\admin\Documents\1>spellchecker spellchecker -f spellchecker_test.json
Spellchecking 1 file...

spellchecker_test.json: no issues found

To wrap the {{...}} strings in a certain file in Windows you could use PowerShell, e.g., for a spellchecker_test.json file:

powershell -Command "& {(Get-Content spellchecker_test.json -Raw) -replace '(?s){{.*?}}','<!-- spellchecker-disable -->$&<!-- spellchecker-enable -->' | Set-Content spellchecker_test.json}"

In *nix, Perl is preferable:

perl -0777 -i -pe 's/\{\{.*?}}/<!-- spellchecker-disable -->$&<!-- spellchecker-enable -->/s' spellchecker_test.json
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563