This rule enforces or disallows use of @
vs this
This rule has two options: the first is a string option that can be "always"
, "never"
or "allow"
. The second is an
object option whose default value is:
{
forbidStandalone: false
}
###eslint coffee/shorthand-this: ["error", "always"]###
->
return this
a = this.b
###eslint coffee/shorthand-this: ["error", "always"]###
->
return @
a = @b
(@a) ->
###eslint coffee/shorthand-this: ["error", "never"]###
->
return @
a = @b
###eslint coffee/shorthand-this: ["error", "never"]###
->
return this
a = this.b
(@a) ->
If you want to allow (or enforce) usage of e.g. @prop
but disallow usage of "standalone" @
, you can use the
"forbidStandalone": true
option (possibly in combination with the "allow"
option, which by itself permits all
use of @
and/or this
so won't flag any violations)
###eslint coffee/shorthand-this: ["error", "allow", {"forbidStandalone": true}]###
->
return @
doSomething(@)
###eslint coffee/shorthand-this: ["error", "allow", {"forbidStandalone": true}]###
->
return this
doSomething(this)
a = this.b
a = @b
###eslint coffee/shorthand-this: ["error", "always", {"forbidStandalone": true}]###
->
return @
doSomething(@)
a = this.b
###eslint coffee/shorthand-this: ["error", "always", {"forbidStandalone": true}]###
->
return this
doSomething(this)
a = @b