coffeelint icon indicating copy to clipboard operation
coffeelint copied to clipboard

Added prefer_fat_arrows_in_methods rule

Open mitar opened this issue 9 years ago • 5 comments

Tests don't pass because I have no idea how to detect assigning to the prototype.

mitar avatar May 19 '15 12:05 mitar

Any suggestions here?

mitar avatar May 26 '15 07:05 mitar

Not 100%, but the AST should look very similar to this:

Assign(
  variable: Value(
    base: Literal("className"),
    properties: [
      Access(
        name=Literal("prototype")
      ),
      Access(
        name=Literal("methodName")
      )
    ]
  ),
  value: Code(...)
)

Sometimes the Literals are replaced by plain strings so you should probably check for that as well.

So basically, find code that assigns a method to something.prototype.something and scan that method's code using your existing implementation.

Some food for thought:

  1. What about requiring:

    class Foo
      bar: =>
        console.log("I'm exclusively foo")
    
  2. How does this interact with no_unnecessary_fat_arrows ? I think you'll also need to check if this is used inside the function body and don't enforce any constraints if it isn't

  3. What happens here:

    class Foo
      bar: ->
        class Baz
          constructor: ->
            # can't ever have a bound constructor so will this fail?  
    

If you need help, I'm happy to take this over. However I'd like to resurrect the community behind coffeelint as the project needs a lot of love.

za-creature avatar Mar 06 '16 23:03 za-creature

I would also love to help with coffeelint.

mitar avatar Mar 06 '16 23:03 mitar

@mitar if you still want to help with coffeelint I have moved the repo to https://github.com/coffeelint/coffeelint

UziTech avatar Jan 14 '20 06:01 UziTech

Further development on coffeelint will be on coffeelint/coffeelint and will be released as @coffeelint/cli.

This PR will be tracked at https://github.com/coffeelint/coffeelint/pull/15

UziTech avatar Jan 14 '20 15:01 UziTech