clutchski / coffeelint

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

Super keyword #623

Closed ashawley closed 6 years ago

ashawley commented 6 years ago

I have some coffeescript 1.7 code that uses the super keyword. After upgrading from coffeelint 1.16.0 to 2.0.6, it is getting flagged for indentation problems:

  ✗ app/assets/javascripts/activities/seq_module.js.coffee
     ✗ #789: [stdin]:789:9: error: unexpected indentation
    super
        ^.

Here is a unit test:

    'Make sure bare super keyword is fine':
        topic:
            '''
            newMethod: ->
              super
            '''

        'returns no errors': (source) ->
            config =
                indentation:
                    level: 'error'
                    value: 2
            errors = coffeelint.lint(source)
            assert.isEmpty(errors)
swang commented 6 years ago

coffeelint 2.0 is for coffeescript 2.0

This is not a coffeelint issue; [stdin] means compiling it caused an error. Also in CS2 you can no longer call super bare without paren. http://coffeescript.org/#try:newMethod%3A%20-%3E%0A%20%20super%0A

Due to a syntax clash with super with accessors, "bare" super (the keyword super without parentheses) no longer compiles to a super call forwarding all arguments.

ashawley commented 6 years ago

Ok, good to know. I wondered if it was the case that coffeelint is expecting coffeescript 2.0 code. Thanks for this explanation.

ashawley commented 6 years ago

Coffeelint does the right thing with well-formed coffee code:

    'Make sure bare super keyword is fine':
        topic:
            '''
            class NewClass
              newMethod: ->
                super arguments...
            '''

        'returns no errors': (source) ->
            config =
                indentation:
                    level: 'error'
                    value: 2
            errors = coffeelint.lint(source)
            assert.isEmpty(errors)

There's no longer a compiler error nor a coffeelint error.

 $ npm test
  Make sure bare super keyword is fine
    ✓ returns no errors

Thanks for coffeelint!