1

jshint emitter emitter/emitter.js: line 15, col 61, Octal literals are not allowed in strict mode.

1 error

I receive the above message while running the linter jshint on my source code.

The offending line in the program is:

let pattern = new RegExp("^-(?=[gim]{1,3}$)(?!.*(.).*\1).*$");

jshint flags the error at \1 in the regular expression.

Is there any way to be rid of this message from jshint?

You can view the source here

Community
  • 1
  • 1
Linus Fernandes
  • 498
  • 5
  • 30

1 Answers1

4

In node.js you have to antislash the antislash (one for node, one for the regex) due to how node.js is dealing with strings.

new RegExp('^-(?=[gim]{1,3}$)(?!.*(.).*\\1).*$');


enter image description here

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • 3
    Not just in Node; in *any* JavaScript environment. – Pointy Apr 26 '19 at 12:34
  • It's basic JavaScript string syntax. I have no idea where the "octal literal" error is coming from, but the problem is that in any JavaScript string literal, backslashes ("antislash" is a better word!) have to be escaped. – Pointy Apr 26 '19 at 12:36
  • 1
    I don't get an error from Node when I try the code in the OP. *edit* oh wait, I do in strict mode. I'm going to need more coffee ... – Pointy Apr 26 '19 at 12:37
  • @Pointy I feel you ahahah third of the day – Orelsanpls Apr 26 '19 at 12:38