clutchski / coffeelint

Lint your CoffeeScript.
http://www.coffeelint.org
Other
1.18k stars 171 forks source link

error: missing / (unclosed regex) with JSX syntax #543

Closed soyjavi closed 8 years ago

soyjavi commented 8 years ago

Hi,

I'm trying to lint my .cjsx files, everything is ok with coffee syntax ... but with my jsx syntax always have this error in sublime console:

<issue 
...
reason="[error] [stdin]:33:26: error: missing / (unclosed regex)..."
evidence="undefined" />

My syntax:

render: ->
    <h1 active>Hello world!!!</h1>

My coffeelint.json file is:

{
  "arrow_spacing": {
    "level": "error"
  },
  "line_endings": {
    "level": "error"
  },
  "indentation": {
    "value": 2
  },
  "colon_assignment_spacing": {
    "level": "error",
    "spacing": {
      "left": 0,
      "right": 1
    }
  },
  "space_operators": {
    "level": "error"
  },
  "prefer_english_operator": {
    "level": "error"
  },
  "cyclomatic_complexity": {
    "value": 11,
    "level": "warn"
  },
  "no_debugger": {
    "level": "warn",
    "console": true
  },
  "spacing_after_comma": {
    "level": "error"
  },
  "no_unnecessary_double_quotes": {
    "level": "error"
  },
  "braces_spacing": {
    "level": "error",
    "spaces": 1
  },
  "camel_case_classes": {
    "level": "error"
  },
  "eol_last": {
    "level": "error"
  },
  "max_line_length": {
    "value": 120,
    "level": "warn"
  },
  "no_empty_param_list": {
    "level": "error"
  },
  "coffeelint": {
    "transforms": [ "coffee-react-transform" ]
  }
}
AsaAyers commented 8 years ago

CSJSX (I'm sure my acronym is wrong) is not valid CoffeeScript. It really truly is a syntax error as CoffeeLint will only parse CoffeeScript, not that hybrid-whatever.

What you can do is convert the CSX to plain CoffeeScript before CoffeeLint parses it. We have some docs on how to do this.

WARNING: CoffeeLint cannot control what these transformers do. They may violate all kinds of rules you have setup. It's up to you to wrap your code in # coffeelint: disable=max_line_length or whatever you need.

Now that you know your option on how to fix this particular error, I have a piece of advice. Just switch to ES6 and use Babel. You'll get much better support for JSX from every tool you pick up than you're ever going to get out of this JSX+CoffeeScript thing. CoffeeLint supports it through a hack that, depending on your rules, may end up producing errors that you will have no control over.

soyjavi commented 8 years ago

CJSX it's the syntax of React CoffeeScript files is just coffeescript plus jsx syntax. I need to know which are your rules for compile React+Coffeescript because in your documentation the only reference is use:

coffeelint.json

...
"coffeelint": {
    "transforms": [ "coffee-react-transform" ]
}
AsaAyers commented 8 years ago

There are no rules that do any compiling. CoffeeLint has no concept of CJSX whatsoever. If you use the transform it runs your file through the transformer and then lints the valid CoffeeScript that comes out the other side.

The most common problem is that you may be setting a line-length limit. When coffee-react-transform converts the code you have no control over the line length and will start getting lint errors that you can't fix. When this happens your only option is to wrap your CJSX in # coffeelint: disable=max_line_length comments to ignore those lines.

Wexcode commented 8 years ago

Double check that your file extension is .cjsx. You will get this error if you file is saved with .coffee.

ABaldwinHunter commented 8 years ago

What do the file names / columns look like in the case where .cjsx files were transformed? Is there an example project / results for reference?

swang commented 8 years ago

AFAIK there is no proper support for transforms in coffeelint and this feature was done more as a courtesy to users who used cjsx. So you may end up with incorrect line numbers.