2 title: no-irregular-whitespace
6 - https://es5.github.io/#x7.2
7 - https://web.archive.org/web/20200414142829/http://timelessrepo.com/json-isnt-a-javascript-subset
12 Invalid or irregular whitespace causes issues with ECMAScript 5 parsers and also makes code harder to debug in a similar nature to mixed tabs and spaces.
14 Various whitespace characters can be inputted by programmers by mistake for example from copying or keyboard shortcuts. Pressing Alt + Space on macOS adds in a non breaking space character for example.
16 A simple fix for this problem could be to rewrite the offending line from scratch. This might also be a problem introduced by the text editor: if rewriting the line does not fix it, try using a different editor.
18 Known issues these spaces cause:
21 * Is NOT considered a separator for tokens and is often parsed as an `Unexpected token ILLEGAL`
22 * Is NOT shown in modern browsers making code repository software expected to resolve the visualization
24 * Is NOT a valid character within JSON which would cause parse errors
28 This rule is aimed at catching invalid whitespace that is not a normal tab and space. Some of these characters may cause issues in modern browsers and others will be a debugging issue to spot.
30 This rule disallows the following characters except where the options allow:
33 \u000B - Line Tabulation (\v) - <VT>
34 \u000C - Form Feed (\f) - <FF>
35 \u00A0 - No-Break Space - <NBSP>
37 \u1680 - Ogham Space Mark
38 \u180E - Mongolian Vowel Separator - <MVS>
39 \ufeff - Zero Width No-Break Space - <BOM>
42 \u2002 - En Space - <ENSP>
43 \u2003 - Em Space - <EMSP>
48 \u2008 - Punctuation Space - <PUNCSP>
51 \u200B - Zero Width Space - <ZWSP>
52 \u2028 - Line Separator
53 \u2029 - Paragraph Separator
54 \u202F - Narrow No-Break Space
55 \u205f - Medium Mathematical Space
56 \u3000 - Ideographic Space
61 This rule has an object option for exceptions:
63 * `"skipStrings": true` (default) allows any whitespace characters in string literals
64 * `"skipComments": true` allows any whitespace characters in comments
65 * `"skipRegExps": true` allows any whitespace characters in regular expression literals
66 * `"skipTemplates": true` allows any whitespace characters in template literals
70 Examples of **incorrect** code for this rule with the default `{ "skipStrings": true }` option:
75 /*eslint no-irregular-whitespace: "error"*/
77 function thing() /*<NBSP>*/{
81 function thing( /*<NBSP>*/){
85 function thing /*<NBSP>*/(){
89 function thing/*<MVS>*/(){
94 return 'test'; /*<ENSP>*/
98 return 'test'; /*<NBSP>*/
102 // Description <NBSP>: some descriptive text
106 Description <NBSP>: some descriptive text
110 return / <NBSP>regexp/;
115 return `template <NBSP>string`;
121 Examples of **correct** code for this rule with the default `{ "skipStrings": true }` option:
126 /*eslint no-irregular-whitespace: "error"*/
129 return ' <NBSP>thing';
133 return '<ZWSP>thing';
137 return 'th <NBSP>ing';
145 Examples of additional **correct** code for this rule with the `{ "skipComments": true }` option:
150 /*eslint no-irregular-whitespace: ["error", { "skipComments": true }]*/
153 // Description <NBSP>: some descriptive text
157 Description <NBSP>: some descriptive text
165 Examples of additional **correct** code for this rule with the `{ "skipRegExps": true }` option:
170 /*eslint no-irregular-whitespace: ["error", { "skipRegExps": true }]*/
173 return / <NBSP>regexp/;
181 Examples of additional **correct** code for this rule with the `{ "skipTemplates": true }` option:
186 /*eslint no-irregular-whitespace: ["error", { "skipTemplates": true }]*/
190 return `template <NBSP>string`;
196 ## When Not To Use It
198 If you decide that you wish to use whitespace other than tabs and spaces outside of strings in your application.