How do I fix linting error on jsx closing tags : "unclosed regular expression"?
Asked Answered
M

2

9

(PS none of these SO questions (with inaccurate titles) solved, or addressed, this issue: React Linting: Unclosed Regular Expression, unclosed regular expression, React JSX error : Unclosed regular expression)

How do I fix linting error on jsx closing tags : "unclosed regular expression" ?

For example, this code snippet runs fine, but causes a SublimeLinter Error:

class Users extends React.Component {
  render() {

    var friends = this.props.list.filter(function(user){
        return user.friend === true;
    });
    var nonFriends = this.props.list.filter(function(user){
        return !user.friend;
    });

    return (
      <div>
        <h1>Friends</h1>
        <ul>
          ...
        </ul>
      </div>
    )
  }
}

The linter balks at the </h1> closing JSX tag, thinking it's the start of a regular expression.
1-2 of 2 errors: Unclosed regular expression; Unrecoverable syntax error. (42% scanned), 2 lines, 25 characters selected

Relevant packages I have installed in Sublime Text3:
SublimeLinter, SublimeLinter-contrib-eslint, JSHint, Babel

edit:
I just added the package "JSX", but that didn't help.
I've searched for the "sublimeLinter-jsxhint" package, but cannot find it.

Miniaturist answered 16/8, 2017 at 18:32 Comment(1)
Are you using jsx as the file extension? I wonder if Sublime doesn't understand that you actually have JSX on the page instead of plain JS.Turgor
D
2

The extension runs jshint on the complete jsx file, and jshint doesn't support jsx syntax and its features. I simply turned off the JShint using -> (Code-> Preferences-> Settings-> User extensions-> JSHint configuration-> JSHint:Enable tick box-> Off)

One solution would be manually turning off jshint around the functions returning HTML using /* jshint ignore: start */ and /* jshint ignore: end */.

Dermis answered 24/1, 2022 at 14:52 Comment(0)
P
0

If you use SublimeLinter-contrib-eslint AND JSHint, you are probably having problems with them conflicting. I'd remove JSHint from Sublime, unless you use it in your build pipeline, then remove the eslint package instead.

Precess answered 22/12, 2018 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.