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

[Feature Request] Support add default argument in ~/.rubocop.yml #2253

Closed
zw963 opened this issue Sep 17, 2015 · 9 comments
Closed

[Feature Request] Support add default argument in ~/.rubocop.yml #2253

zw963 opened this issue Sep 17, 2015 · 9 comments

Comments

@zw963
Copy link

zw963 commented Sep 17, 2015

Support add default argument in ~/.rubocop.yml, e.g. settings default formatter to emacs (-fe)

@zw963
Copy link
Author

zw963 commented Sep 17, 2015

like a function in bash shell, e.g.

function rubocop () {
    command rubocop -fe "$@"
}

@jonas054
Copy link
Collaborator

At this point it would be difficult to introduce a configuration parameter acting as "generic default command line options", because we've already added a lot of configuration parameters that are default values for individual CLI options:

  • RunRailsCops
  • DisplayCopNames
  • DisplayStyleGuide
  • StyleGuideCopsOnly
  • DisabledByDefault
  • UseCache

But I do think it would be possible to add an AllCops: DefaultFormatter parameter, perhaps limited to setting only one formatter, and not dealing with the --out option.

@zw963
Copy link
Author

zw963 commented Sep 19, 2015

thanks.

AllCops: DefaultFormatter is good, I just hope can config more things
with my personal ~/rubocop.yml

@tigris
Copy link

tigris commented Sep 21, 2015

I approve of this feature, I was just trying to implement it myself.

@alexdowad
Copy link
Contributor

One problem with that is that .rubocop.yml is not just one file. There can be many; one in each project subdirectory. When RC is ready to check a file, it finds the configuration which applies to that particular file.

So what if you had multiple .rubocop.yml files in various subdirectories, with different AllCops: DefaultFormatter parameters?

I am inclined to say that a shell alias would be the best thing for you.

@apowers
Copy link

apowers commented Dec 23, 2015

I would like to be able to set a default formatter. And especially when running rubocop as a rake task.

"What if you had multiple values of DefaultFormatter?" Well, what if you have multiple values of any parameter? You must already have an order of precedence or enabling a cop in one place and disabling it in another would be very interesting.

@alexdowad
Copy link
Contributor

@apowers, there is a big difference. Most parameters make sense even if changed for each source file. And that is what RC does, if you have different RC config files in different subdirectories. The proposed DefaultFormatter parameter doesn't make sense if changed from one source file to the next.

Actually, the internal methods which select the formatter(s) to use don't even look at the paths to the files being checked. It shouldn't matter when selecting the formatter.

@jonas054
Copy link
Collaborator

@alexdowad What you say is correct, but there is a way to circumvent the problem posed by our per-directory configuration functionality. The trick is to say that a global config parameter like that is taken from the configuration for the current directory. I used it here when I faced a similar problem for AllCops: MaxFilesInCache.

Edit: Made the link robust by linking to a tagged version instead of master.

@alexdowad
Copy link
Contributor

@jonas054, OK, let me code something up.

alexdowad added a commit to alexdowad/rubocop that referenced this issue Jan 1, 2016
….yml

The new config parameter can be used like:

    AllCops:
      DefaultFormatter: fuubar

It is only applied once, close to the beginning of program execution. Whatever
.rubocop.yml file applies within the working directory from which RuboCop is
run, will decide what the default formatter is.

Previously, setting formatters was the responsibility of Options. This doesn't
work any more. It is not possible to load .rubocop.yml first, extract the value
of DefaultFormatter, and then use it within Options. Why? Because the options
affect how the config file is loaded, from where it is loaded, and so on. We
can't load a config file until we first parse the options.

Therefore, both the selection of a default formatter, as well as adding the
formatter for --auto-gen-config, must be done after `Options#parse`.
@bbatsov bbatsov closed this as completed in dbe5679 Jan 3, 2016
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

5 participants