clutchski / coffeelint

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

Split 'implicit parens/braces' into two rules #146

Closed tarruda closed 10 years ago

tarruda commented 11 years ago

I currently use the following coding style for function/method calls:

## parenthesis when all arguments appear in one line

# explicit(good)
obj.method(a, b, c.call(this)) 

 # implicit(bad)
obj.method a, b, c.call this

## parenthesis when arguments appear over multiple lines

# explicit(bad)
describe('something', ->
  it('works', ->
    expect(true).to.be.true
  )
)

# implicit(good)
describe 'something', ->
  it 'works', ->
    expect(true).to.be.true

Same for object literals:

## braces when all key/values appear in one line

# explicit(good)
put '/users/1', {name: 'user1', role: 'admin'}, ->
  console.log('success!')

# implicit(bad)
put '/users/1', name: 'user1', role: 'admin', ->
  console.log('success!')

## braces when all keys/values appear over multiple lines

# explicit(bad)
query '/users', {
  name: 'user1'
  role: 'admin'
  contact: {
    email: 'user1@company.net'
    twitter: '@user1'
  }
}, -> console.log('success!')

# implicit(good)
query '/users',
  name: 'user1'
  role: 'admin'
  contact:
    email: 'user1@company.net'
    twitter: '@user1'
  -> console.log('success!')

I think identation makes pretty clear when the function call/object literal ends so I only use braces when everything is in the same line and can lead to confusion.

Maybe coffeelint should support this style?

AsaAyers commented 11 years ago

I'm not seeing where your description lines up with the subject "Split 'implicit parens/braces' into two rules". no_implicit_parens and no_implicit_braces are already different rules.

Am I understanding correctly that you're asking for multi-line statements to have one set of rules and single-line statements to gave the opposite rule? If I'm understanding correctly I think that would make this by far the most complex rule in all of CoffeeLint.

tarruda commented 11 years ago

I tought about adding four extra rules:

no_implicit_multiline_parens no_implicit_singleline_parens no_implicit_multiline_braces no_implicit_singleline_braces

These rules would override no_implicit_parens and no_implicit_braces for when the expression is spread over one line/multiple lines. This would allow the programmer to selectively enforce explicit parenthesis/braces

clutchski commented 11 years ago

I'm not a huge fan. The purpose of these rules is to completely eliminate potentially ambiguous syntax, not eliminate it under certain circumstances.

These potentially could be an option in each rule, but definitely shouldn't be a rule in and of itself.

tarruda commented 11 years ago

@clutchski I was not aware that coffeelint support rule-specific options, if so then I also think those should be options within the existing rules

Sinetheta commented 10 years ago

So, was there a way to do this? I'm not a huge fan of the apparent flip-flopyness, but I can sympathize with those who think single line compositions can get a little confusing without parens.

AsaAyers commented 10 years ago

Yes, it's possible to add options to the rules. Someone with an interest in using the rule just needs to get it done.