Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Style/MethodDefParentheses enabled by default (custom config) #213

Closed
Gee-Bee opened this issue Oct 23, 2020 · 4 comments
Closed

Make Style/MethodDefParentheses enabled by default (custom config) #213

Gee-Bee opened this issue Oct 23, 2020 · 4 comments

Comments

@Gee-Bee
Copy link

Gee-Bee commented Oct 23, 2020

I've run tests on usage parentheses around parameters in method definitions.

1) test counted methods defined with parenthesis around parameters.

ag --stats '^[ \t]*def +(?=.*\()'

2) test counted methods defined without parenthesis around parameters.

ag --stats '^[ \t]*def(?: +[^ \n#<;\(]+){2,}'

The results are unambiguous:

1) with 2) without
rails 9171 1
devise 292 1
rubocop 4297 45
puma 4392 45

If it's not possible to enable this by default, is it possible to add this rule manually to config file?

@searls
Copy link
Contributor

searls commented Oct 23, 2020

What do you mean to say is unambiguous about the results? That those projects use parentheses in method definitions?

In any case, we're intentionally flexible about enforcing whether method defs and invocations use parentheses, because we want to be inclusive of Rubyists from Seattle

But in all seriousness, this isn't something that I think Standard should be in the business of constraining people on. The freedom to express yourself with a bare minimum of supporting syntax is one of Ruby's strengths, and tamping that down just for the sake of uniformity would be a real shame.

@searls searls closed this as completed Oct 23, 2020
@Gee-Bee
Copy link
Author

Gee-Bee commented Oct 23, 2020

What do you mean to say is unambiguous about the results? That those projects use parentheses in method definitions?

Yes, that's exactly what I meant.

In any case, we're intentionally flexible about enforcing whether method defs and invocations use parentheses, because we want to be inclusive of Rubyists from Seattle

That's right. When comparing minitest and flog, the results where quite the opposite to the ones from the table.
If I had taken them under consideration, the results in the table would have been ambiguous ;)

But in all seriousness, this isn't something that I think Standard should be in the business of constraining people on. The freedom to express yourself with a bare minimum of supporting syntax is one of Ruby's strengths, and tamping that down just for the sake of uniformity would be a real shame.

Understood.
Talking about constraints and going back to the question. Is it possible to enable this rule using standard gem on a project basis, or it's 'take it or leave it' scenario?

@jmkoni
Copy link
Contributor

jmkoni commented Oct 23, 2020

You can if you do something like this and use standard rules, but use rubocop instead: #158 (comment)

@Gee-Bee
Copy link
Author

Gee-Bee commented Oct 23, 2020

You can if you do something like this and use standard rules, but use rubocop instead: #158 (comment)

Thank you for pointing that. Works like a charm 🎉

For anyone who stumbled this:

  • install standard as regular - rubocop is listed as dependency,
  • use rubocop for formatting and linting,
  • put this in your .rubocop.yml:
require:
  - standard/cop/semantic_blocks

inherit_gem:
  standard: config/base.yml

Style/MethodDefParentheses:
  Enabled: true
  EnforcedStyle: require_parentheses

@Gee-Bee Gee-Bee changed the title Make Style/MethodDefParentheses enabled by default Make Style/MethodDefParentheses ~~enabled by default~~ custom config Oct 23, 2020
@Gee-Bee Gee-Bee changed the title Make Style/MethodDefParentheses ~~enabled by default~~ custom config Make Style/MethodDefParentheses enabled by default / custom config Oct 23, 2020
@Gee-Bee Gee-Bee changed the title Make Style/MethodDefParentheses enabled by default / custom config Make Style/MethodDefParentheses enabled by default (custom config) Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants