Skip to content

Latest commit

 

History

History
119 lines (76 loc) · 2.48 KB

shorthand-this.md

File metadata and controls

119 lines (76 loc) · 2.48 KB

coffee/shorthand-this

This rule enforces or disallows use of @ vs this

Options

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
}

👎 Examples of incorrect code for this rule with the default "always" option:

###eslint coffee/shorthand-this: ["error", "always"]###

->
  return this

a = this.b

👍 Examples of correct code for this rule with the default "always" option:

###eslint coffee/shorthand-this: ["error", "always"]###

->
  return @

a = @b

(@a) ->

👎 Examples of incorrect code for this rule with the "never" option:

###eslint coffee/shorthand-this: ["error", "never"]###

->
  return @

a = @b

👍 Examples of correct code for this rule with the "never" option:

###eslint coffee/shorthand-this: ["error", "never"]###

->
  return this

a = this.b

(@a) ->

forbidStandalone

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)

👎 Examples of incorrect code for this rule with the "allow" and "forbidStandalone": true options:

###eslint coffee/shorthand-this: ["error", "allow", {"forbidStandalone": true}]###

->
  return @

doSomething(@)

👍 Examples of correct code for this rule with the "allow" and "forbidStandalone": true options:

###eslint coffee/shorthand-this: ["error", "allow", {"forbidStandalone": true}]###

->
  return this

doSomething(this)

a = this.b

a = @b

👎 Examples of incorrect code for this rule with the "always" and "forbidStandalone": true options:

###eslint coffee/shorthand-this: ["error", "always", {"forbidStandalone": true}]###

->
  return @

doSomething(@)

a = this.b

👍 Examples of correct code for this rule with the "always" and "forbidStandalone": true options:

###eslint coffee/shorthand-this: ["error", "always", {"forbidStandalone": true}]###

->
  return this

doSomething(this)

a = @b