Unexpected 'INDENT' in CoffeeScript Example Code

后端 未结 6 1199
悲哀的现实
悲哀的现实 2020-12-15 17:21

As I was playing around for the first time with CoffeeScript, I ran in to a problem. In order to debug my problem, I tried replacing my whole file with one of the example b

相关标签:
6条回答
  • 2020-12-15 17:28

    I am pretty sure this is a tabs-vs-spaces issue. Tell your editor not to convert spaces to tabs if it does that. Also, go through your code with the cursor and make sure it doesn't jump over blank areas.

    The issue is that while normal editors see a tab as equivalent to two or four spaces, coffeescript sees it as one space, so the indentation gets messed up.

    If this all doesn't help, make sure you have a recent coffeescript version, e.g. 1.1.0 or newer.

    0 讨论(0)
  • 2020-12-15 17:35

    If you have the same problem, but your indentation is okay,
    then you must be suffering from bug 2868.

    Basically, the error is misleading. Check for indentation
    errors in the required files.

    0 讨论(0)
  • 2020-12-15 17:48

    If you are using a JetBrains IDE (IntelliJ, PHPStorm, etc) the change of setting that worked for me is:

    File > Settings > Project Settings > Code Style > CoffeeScript > Tabs and Indents

    Tick "Use tab character" & "Smart tabs"

    0 讨论(0)
  • 2020-12-15 17:49

    Code is fine. Make sure you haven't messed up the whitespace (strange control chars showing as blanks, tabs or similar).

    0 讨论(0)
  • 2020-12-15 17:49

    When in Atom you can automatically convert tabs to spaces:

    Packages > Whitespace > Convert Tabs to Spaces

    0 讨论(0)
  • 2020-12-15 17:49

    You can resolve this two ways 1. IF using webstorm File->Default Settings as said above 2. Other workaround, is to use a different editor like Sublime, there u can press enter on earlier line and it will auto tab it for you with spaces

    0 讨论(0)
提交回复
热议问题