This extension uses regex to find the characters undesired characters and a regex to replace. The following example is a linting rule that would be added to a settings.json file:
"unicodesubsitutions.rules": [
{
"invalid": "\\u058A",
"valid": "\\u002D",
"message": "Armenian hyphen should be a hyphen."
}
]
Invalid is the character the is be searched for by the linter.
Valid is the character that will replace the invalid character during document formatting or a code action.
Message is the text that will appear in the problems window and code action tool tip.
Firstly you will need the UTF-16BE values for the character that you want to find and the UTF-16 value for the character you want to replace it with.
-
Install the extension Unicode code point of current character
-
Type or copy the good and bad characters into Visual Studio code.
-
Replace characters to \uFFFF form using the above extension.
Press: Control + Shift + P Type: CursorCharCode: Replace character to \uFFFF form Press: Enter
You will now have a pair of strings in the format \uXXXX One for the "Bad" or invalid character and one for the "Good" or valid character. Insert them into the JSON below remembering to escape the backslash.
"unicodesubsitutions.rules": [
{
"invalid": "[INSERT_INVALID_uFFFF]",
"valid": "[INSERT_VALID_uFFFF]",
"message": "[INSERT_RULE_DESCRIPTION_HERE]"
}
]
The following example is based on the above animation:
"unicodesubsitutions.rules": [
{
"invalid": "\\ud83d\\ude42",
"valid": "\\u003a\\u0029",
"message": "Smiling face should be a Colon and Bracket."
},
{
"invalid": "\\u2012",
"valid": "\\u002D",
"message": "Figure Dash should be a hyphen."
}
]
Note the double back slashes. Note the smiling face is a double UTF-16.
-
Open Settings.json
Press: Control + Shift + P Type: Preferences: Open Settings (JSON)
-
Paste in the rules