'no-irregular-whitespace' catching zero-width non-breaking spaces (UTF8 BOM)
See original GitHub issueWhat version of ESLint are you using? 2.3.0
What configuration and parser (Espree, Babel-ESLint, etc.) are you using?
- configuration: eslint-config-xo
- parser: XO
What did you do? Please include the actual source code causing the issue.
I ran ESLint (via XO) on the following code:
/* eslint-disable new-cap */
var CKEDITOR = CKEDITOR || {};
What did you expect to happen?
I expected nothing to happen, since that block of code doesn’t violate any of my linting rules.
What actually happened? Please include the actual, raw output from ESLint.
I got the following error:
1:1 error Irregular whitespace not allowed no-irregular-whitespace
The issue here, is that even though the source code file looks clean, and there is no unusual whitespace, (that can be removed in the editor), there is actually a zero-width non-breaking spaces lurking in the raw file data.
You can see the result of the command od -c plugin.js
:
0000000 357 273 277 / * e s l i n t - d i s 0000020 a b l e n e w - c a p * / 0000040 \n v a r C K E D I T O R = 0000060 C K E D I T O R | | { } ; \n
(notice the first three values 357 273 277
)
Or if you like, the output of hexdump plugin.js
:
0000000 ef bb bf 2f 2a 20 65 73 6c 69 6e 74 2d 64 69 73
(notice the first three values ef bb bf
)
When inspecting the code in my code editor, there is no way to remove these characters, since technically, they don’t exist in the editor (nor can they be discovered even when I tell my editor to show all whitespace characters).
I can’t see these values, nor edit them in my source code, but they exist in the file’s raw data, so should the linter even be looking for these values and catching them, or am I missing something?
I ended up removing the invalid characters with this script:
awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' plugin.js > plugin.nobom.js
but I wanted to post my findings here for discovery, and in case I found something that needs to be fixed.
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I am adding this note in for discovery:
My issue was solved by simply updating to the latest version of XO. There was a bug in the
0.12.x
release of XO that was causing this strange behavior, but it’s not possible to reproduce in the latest versions.👍
Thanks. Since it doesn’t seem to be directly related to eslint, I’m closing this for now.