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

Add a validation for supported styles other than EnforcedStyle #3765

Merged
merged 2 commits into from
Dec 6, 2016

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Dec 3, 2016

I added a validation for supported styles other than EnforcedStyle.

Problem

Currently, EnforcedStyle value is validated by SupportedStyles.

e.g.

$ cat .rubocop.yml
Style/AlignParameters:
  EnforcedStyle: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Error: invalid EnforcedStyle 'aaaaaaaaaaaaaaaaaaaaaa' for Style/AlignParameters found in /tmp/tmp.SyHaGtdT0U/.rubocop.yml
Valid choices are: with_first_parameter, with_fixed_indentation

However, other styles aren't validated.

e.g.

$ cat .rubocop.yml
Style/SpaceAroundBlockParameters:
  EnforcedStyleInsidePipes: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Inspecting 0 files

0 files inspected, no offenses detected

Goal

Validate the invalid value.

e.g.

$ cat .rubocop.yml
Style/SpaceAroundBlockParameters:
  EnforcedStyleInsidePipes: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Error: invalid EnforcedStyleInsidePipes 'aaaaaaaaaaaaaaaaaaaaaa' for Style/SpaceAroundBlockParameters found in /tmp/tmp.SyHaGtdT0U/.rubocop.yml
Valid choices are: space, no_space

Changes

  • Add validation for styles other than EnforcedStyle
    • And rename some SupportedStyles names to match EnforcedStyle name
      • e.g. SupportedStyles to SupportedStylesInsidePipes (for EnforcedStyleInsidePipes)
  • Add SupportedStyles for missing styles in config/default.yml
  • Add a spec to check existence of SupportedStyles into project_spec.rb
  • Add test cases to check validation

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

I added a validation for supported styles other than EnforcedStyle.

Problem
======

Currently, EnforcedStyle value is validated by SupportedStyles.

e.g.

```sh
$ cat .rubocop.yml
Style/AlignParameters:
  EnforcedStyle: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Error: invalid EnforcedStyle 'aaaaaaaaaaaaaaaaaaaaaa' for Style/AlignParameters found in /tmp/tmp.SyHaGtdT0U/.rubocop.yml
Valid choices are: with_first_parameter, with_fixed_indentation
```

However, other styles aren't validated.

e.g.

```sh
$ cat .rubocop.yml
Style/SpaceAroundBlockParameters:
  EnforcedStyleInsidePipes: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Inspecting 0 files

0 files inspected, no offenses detected
```

Goal
======

Validate the invalid value.

e.g.

```sh
$ cat .rubocop.yml
Style/SpaceAroundBlockParameters:
  EnforcedStyleInsidePipes: aaaaaaaaaaaaaaaaaaaaaa
$ rubocop
Error: invalid EnforcedStyleInsidePipes 'aaaaaaaaaaaaaaaaaaaaaa' for Style/SpaceAroundBlockParameters found in /tmp/tmp.SyHaGtdT0U/.rubocop.yml
Valid choices are: space, no_space
```

Changes
=====

- Add validation for styles other than `EnforcedStyle`
  - And rename some `SupportedStyles` names to match EnforcedStyle name
    - e.g. `SupportedStyles` to `SupportedStylesInsidePipes` (for `EnforcedStyleInsidePipes`)
- Add `SupportedStyles` for missing styles in config/default.yml
- Add a spec to check existence of `SupportedStyles` into `project_spec.rb`
- Add test cases to check validation
@@ -271,6 +271,15 @@ def compatible_external_encoding_for?(src)
src = src.dup if RUBY_VERSION < '2.3'
src.force_encoding(Encoding.default_external).valid_encoding?
end

def to_supported_styles(enforced_style)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this method that much - too many things seem hardcoded in it, which means people are likely going to forget updating it and me might end up with more unvalidated config down the road.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 4, 2016

I'll have to think about this a bit more. While I think your idea is good it might be worth reconsidering the configuration of cops with multiple configurable styles in general. Frankly, even I find some of our configuration options to be extremely confusing.

@pocke
Copy link
Collaborator Author

pocke commented Dec 5, 2016

I don't like this method that much - too many things seem hardcoded in it, which means people are likely going to forget updating it and me might end up with more unvalidated config down the road.

I think so too. I hope the hardcoded names will be removed.

Frankly, even I find some of our configuration options to be extremely confusing.

There are several rules of EnforcedStyle's naming convention.

  • EnforcedStyle
  • EnforcedFooStyle
    • e.g.) EnforcedHashRocketStyle in Style/AlignHash
  • EnforcedStyleFoo
    • e.g.) EnforcedStyleInsidePipes in Style/SpaceAroundBlockParameters
  • AlignWith
  • IndentWhenRelativeTo
  • EnforcedMode

AlignWith, IndentWhenRelativeTo and EnforcedMode are irregular. So, I think it is better to rename these.

For example

  • AlignWith to EnforcedStyleAlignWith
  • IndentWhenRelativeTo to EnforcedStyle
    • and rename values
      • case to relative_to_case
      • end to relative_to_end
  • EnforcedMode to EnforcedStyle

By this rename, the hardcorded problem will be solved.

I think confusion will be resolved by this rename. However, it's braking change...

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 5, 2016

By this rename, the hardcorded problem will be solved.

I think confusion will be resolved by this rename. However, it's braking change...

Let's do it. I'd rather do a breaking change now than after 1.0.

See. rubocop#3765 (comment)

- Rename EnforcedMode to EnforcedStyle
- Rename AlignWith to EnforcedStyleAlignWith
- Rename IndentWhenRelativeTo to EnforcedStyle
@pocke
Copy link
Collaborator Author

pocke commented Dec 6, 2016

@bbatsov I renamed them.

@bbatsov bbatsov merged commit 022146a into rubocop:master Dec 6, 2016
@pocke pocke deleted the check-supported-style branch December 6, 2016 10:51
pocke added a commit to pocke/rubocop that referenced this pull request Jan 14, 2017
This change improves obsolete warnings in three ways.

1. Show all obsoletes
--------

Currently, RuboCop displays first obsolete warning only.

```yaml
 # two obsolete cops
Style/SingleSpaceBeforeFirstArg:
  Enabled: false
Style/SpaceBeforeModifierKeyword:
  Enabled: false
```

```
Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
```

This change makes to display all obsolete warnings.

```
Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.`
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please use `Style/SpaceAroundKeyword` instead.
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
```

2. Add obsolete cops
---------

`Style/MethodCallParentheses` and `Lint/Eval` are renamed.
- rubocop#3797
- rubocop#3820

So, I added the cops to `OBSOLATE_COPS`.

3. Add obsolete parameters

In rubocop#3765, some cop's parameters are renamed.

So, I added the parameters to `OBSOLATE_PARAMETERS`
@pocke pocke mentioned this pull request Jan 14, 2017
11 tasks
bbatsov pushed a commit that referenced this pull request Jan 14, 2017
This change improves obsolete warnings in three ways.

1. Show all obsoletes
--------

Currently, RuboCop displays first obsolete warning only.

```yaml
 # two obsolete cops
Style/SingleSpaceBeforeFirstArg:
  Enabled: false
Style/SpaceBeforeModifierKeyword:
  Enabled: false
```

```
Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
```

This change makes to display all obsolete warnings.

```
Error: The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to `Style/SpaceBeforeFirstArg.`
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please use `Style/SpaceAroundKeyword` instead.
(obsolete configuration found in /tmp/tmp.9T2ers7SW8/.rubocop.yml, please update it)
```

2. Add obsolete cops
---------

`Style/MethodCallParentheses` and `Lint/Eval` are renamed.
- #3797
- #3820

So, I added the cops to `OBSOLATE_COPS`.

3. Add obsolete parameters

In #3765, some cop's parameters are renamed.

So, I added the parameters to `OBSOLATE_PARAMETERS`
toshimaru added a commit to toshimaru/rubocop-rails that referenced this pull request Jan 16, 2017
volmer added a commit to Shopify/ruby-style-guide that referenced this pull request Jan 20, 2017
Our current config does not work with RuboCop 0.47 and up because
unfortunately RuboCop introduced a breaking change in
rubocop/rubocop#3765

Sadly this commit will break all configs that inherit from our
`rubocop.yml` that are still run using RuboCop 0.46 or older.
koic pushed a commit to rubocop/rubocop-rails that referenced this pull request Oct 26, 2018
See. rubocop/rubocop#3765 (comment)

- Rename EnforcedMode to EnforcedStyle
- Rename AlignWith to EnforcedStyleAlignWith
- Rename IndentWhenRelativeTo to EnforcedStyle
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

Successfully merging this pull request may close these issues.

2 participants