question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'no-irregular-whitespace' catching zero-width non-breaking spaces (UTF8 BOM)

See original GitHub issue

What version of ESLint are you using? 2.3.0

What configuration and parser (Espree, Babel-ESLint, etc.) are you using?

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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
radiovisualcommented, May 4, 2016

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.

👍

0reactions
albertocommented, Apr 3, 2016

Thanks. Since it doesn’t seem to be directly related to eslint, I’m closing this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Zero-width non-breaking space - html - Stack Overflow
The No-Break Space is very similar to a Word-Joiner, just as it's very similar to a Space. But each, has very different usages....
Read more >
Unicode Character 'ZERO WIDTH NO ... - FileFormat.info
image of Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF ... Every character has a story #4: U+feff (alternate title: UTF-8 is the BOM, ......
Read more >
Fixing and removing irregular white spaces
How to fix them ? It works by replacing all non breaking space from your code with a normal space.
Read more >
Code Issues - Embold Help Center
CatchBlocksShouldRethrow, Any catch block should rethrow or throw and not eat ... no-irregular-whitespace, Invalid or irregular whitespace causes issues ...
Read more >
What are some problems caused by the Unicode character ...
... as a zero-width no-break space (ZWNBSP) and a UTF-16 byte order mark (BOM), ... and if the character context is known to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found