cspell icon indicating copy to clipboard operation
cspell copied to clipboard

FR/RFC: Expand flagWords to support default replacement

Open samthecodingman opened this issue 4 years ago • 2 comments

Would it be possible to expand the flagWords configuration to support a default replacement word (or words)?

When you flag a word using the flagWords property, it simply marks that word as being spelt incorrectly and the suggested replacements to correct it are those that are similarly spelt. Here, I propose expanding this configuration property so that you can specify the desired replacement word manually. Not only would this allow correcting "calender" to "calendar" as covered in streetsidesoftware/vscode-spell-checker#706, it would also permit term replacement such as swapping whitelist with allowlist and blacklist with denylist/blocklist (for those who wish to do so).

The proposed way to do this is to make cSpell.flagWords accept a type of (string|string[])[] where the string[] is of the form [WORD, ...SUGGESTED_REPLACEMENTS]. Alternatively, a syntax of "WORD->CORRECTED_WORD" could be used.

Examples:

// VS Code Settings File
{
  "cSpell.flagWords": [
    ["calender", "calendar"], // corrects "calender" to "calendar"
    // other words
  ]
}
// VS Code Settings File
{
  "cSpell.flagWords": [
    ["whitelist", "allowlist"],
    ["blacklist", "denylist"],
    // other words
  ]
}

A regex replacement may also be desirable, where cSpell.flagWords accepts a (string|string[])[] type where the string[] is of the form [REGEXP_OR_WORD, ...SUGGESTED_REPLACEMENTS].

As an example:

// VS Code Settings File
{
  "cSpell.flagWords": [
    ["/whitelist(ed|ing|s)?/", "allowlist$1"],
    ["/blacklist(ed|ing|s)?/", "denylist$1"],
    /* ... other words ... */
  ]
}

samthecodingman avatar Jul 09 '21 02:07 samthecodingman

I think this is a good concept.

Jason3S avatar Jul 09 '21 08:07 Jason3S

Very good advice and necessary questions。 I think we're always constrained by regex or whatever, and if we can find a way to provide a callback to the user, and the user can do something special with the callback before the processing, after the processing, PrePost and afterPost may provide users with an Option that can be effectively extended:

prePost callback for :To deal with a one-to-one recommendation similar scenarios afterPost callback for: For sorting results, filtering some irrelevant content, etc

is this possible?

image

SilvaQ avatar Jan 10 '22 07:01 SilvaQ

@samthecodingman,

The initial implementation has been completed.

cspell.config.yaml

flagWords:
  - blacklist->denylist
  # `:` is also ok
  - "blacklists: denylists, deny list"
  - |
    whitelist->allowlist
    whitelists->allowlists
    whitelisted->allowlisted
    whitelisting->allowlisting
    whitelistings->allowlistings
  - wont->won't, will not
  - hte->the
ignorePaths:
  - cspell.config.yaml

.vscode/settings.json

"cSpell.flagWords": [
  "whitelist->allowlist",
  "whitelists->allowlists",
  "whitelisted->allowlisted",
  "whitelisting->allowlisting",
  "whitelistings->allowlistings",
  "blacklist: denylist",
  "blacklists: denylists"
  "wont->won't, will not",
  "hte->the"
]

Jason3S avatar Dec 06 '22 18:12 Jason3S

flagWords and suggestWords support the <word>:<suggestion> format. Both : or -> work to specify suggestions.

Jason3S avatar Feb 15 '23 13:02 Jason3S

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Mar 18 '23 05:03 github-actions[bot]