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

Move LineLength cop from Metrics to Layout department #7542

Merged

Conversation

koic
Copy link
Member

@koic koic commented Dec 1, 2019

Summary

The Layout department was created after Metrics was created.

As far as I use LineLength cop, I think this cop belongs to the layout, not the logic metrics. Rather than changing the logic when LineLength cop becomes a offense, a solution is often a line wrap.

The horizontal length targeted by LineLength cop is resolved by often a line wrapping, while the vertical length targeted by ClassLength cop, MethodLength cop, and BlockLength cop is
resolved by a logic change.
So ClassLength, MethodLength, and BlockLength cop remain in
the Metrics department.

Other Information

I'm wondering if the default maximum length of 80 is reasonable.
This is because there are cases where clear variable name (and etc) have to be omitted due to restrictions on LineLength.
However, this PR does not handle it because first of all this PR aims to move department.


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).
  • 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.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the move_line_length_cop_to_layout_department branch from 58e5a8d to b56bcdf Compare December 4, 2019 15:45
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 4, 2019

I agree with your reasoning, but this might be confusing to the end users. @rubocop-hq/rubocop-core what do you think about the proposed change?

I'm wondering if the default maximum length of 80 is reasonable.

I guess we can revisit this before 1.0 when we discuss which defaults should be updated.

@Drenmi
Copy link
Collaborator

Drenmi commented Dec 5, 2019

I tend to agree with the move, actually. 👍


As for the default length, I think 80 is the only length that has an actual justification. The problem is that justification is veeery outdated, dating back to IBM punch cards.

There does exist some research for optimal line length, but that is for natural language texts, and the results are inconsistent. I'm not aware of any such studies for code.

Bottom line is whatever is chosen is going to be arbitrary. 🙂

### Summary

The `Layout` department was created after `Metrics` was created.

- Create namespace Metrics and move some cops there
  rubocop@e2153e8
- Layout department
  rubocop#4278

As far as I use `LineLength` cop, I think this cop belongs to the layout,
not the logic metrics. Rather than changing the logic when `LineLength`
cop becomes a offense, a solution is often a line wrap.

The horizontal length targeted by `LineLength` cop is resolved by
often a line wrapping, while the vertical length targeted by
`ClassLength` cop, `MethodLength` cop, and `BlockLength` cop is
resolved by a logic change.
So `ClassLength`, `MethodLength`, and `BlockLength` cop remain in
the `Metrics` department.

### Other Information

I'm wondering if the default maximum length of 80 is reasonable.
This is because there are cases where clear variable name (and etc)
have to be omitted due to restrictions on `LineLength`.
However, this PR does not handle it because first of all this PR aims
to move department.
@koic koic force-pushed the move_line_length_cop_to_layout_department branch from b56bcdf to 6deb06b Compare December 6, 2019 01:54
@bbatsov bbatsov merged commit 8ccdf3e into rubocop:master Dec 9, 2019
@koic koic deleted the move_line_length_cop_to_layout_department branch December 9, 2019 09:48
koic added a commit to koic/rubocop-rails that referenced this pull request Dec 13, 2019
Follow rubocop/rubocop#7542.

This PR suppresses the following warning.

```console
% bundle exec rake
(snip)

Running RuboCop...
spec/project_spec.rb: Metrics/LineLength has the wrong namespace -
should be Layout
Inspecting 130 files
```
mfloresnss added a commit to mfloresnss/rubocop-nosolosoftware that referenced this pull request Dec 20, 2019
En rubocop 0.78.0 se mueve LineLength de departamento
rubocop/rubocop#7542
sue445 added a commit to sue445/onkcop that referenced this pull request Dec 20, 2019
`Metrics/LineLength` moved to `Layout/LineLength` since rubocop 0.78.0

c.f. rubocop/rubocop#7542
sue445 added a commit to sue445/onkcop that referenced this pull request Dec 20, 2019
`Metrics/LineLength` moved to `Layout/LineLength` since rubocop 0.78.0

c.f. rubocop/rubocop#7542
tagliala added a commit to tagliala/slim-lint that referenced this pull request Dec 25, 2019
Breaking change in RuboCop 0.78.0

Ref: rubocop/rubocop#7542
koic added a commit to koic/rubocop-rake that referenced this pull request Dec 28, 2019
This PR suppress the following RuboCop's offenses.

```console
% cd path/to/repo/rubocop-rake
% bundle exec rake
rubocop
Inspecting 25 files
....C.CC.....C....C..CC..

Offenses:

lib/rubocop/cop/rake/class_definition_in_task.rb:32:81: C:
Layout/LineLength: Line is too long. [99/80]
        MSG = 'Do not define a %<type>s in rake task, because it will be
defined to the top level.'
       ^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/rake/duplicate_namespace.rb:6:81: C: Layout/LineLength:
Line is too long. [87/80]
      # If namespaces are defined with the same name, Rake executes the
both namespaces
        ^^^^^^^
lib/rubocop/cop/rake/duplicate_namespace.rb:33:81: C: Layout/LineLength:
Line is too long. [90/80]
        MSG = 'Namespace `%<namespace>s` is defined at both %<previous>s
and %<current>s.'
       ^^^^^^^^^^
lib/rubocop/cop/rake/duplicate_namespace.rb:46:81: C: Layout/LineLength:
Line is too long. [94/80]
            message = message_for_dup(previous: previous, current: node,
namespace: full_name)
       ^^^^^^^^^^^^^^
lib/rubocop/cop/rake/duplicate_task.rb:45:81: C: Layout/LineLength: Line
is too long. [94/80]
            message = message_for_dup(previous: previous, current: node,
task_name: full_name)
       ^^^^^^^^^^^^^^
lib/rubocop/cop/rake/method_definition_in_task.rb:34:81: C:
Layout/LineLength: Line is too long. [97/80]
        MSG = 'Do not define a method in rake task, because it will be
defined to the top level.'
         ^^^^^^^^^^^^^^^^^
rubocop-rake.gemspec:24:81: C: Layout/LineLength: Line is too
long. [87/80]
  # The `git ls-files -z` loads the files in the RubyGem that have been
added into git.
        ^^^^^^^
rubocop-rake.gemspec:26:81: C: Layout/LineLength: Line is too
long. [85/80]
    `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|
features)/}) }
         ^^^^^
spec/rubocop/cop/rake/duplicate_namespace_spec.rb:63:81: C:
Layout/LineLength: Line is too long. [88/80]
  it 'does not register an offense with the same name but in the
different namespace' do
               ^^^^^^^^
spec/rubocop/cop/rake/duplicate_task_spec.rb:74:81: C:
Layout/LineLength: Line is too long. [88/80]
  it 'does not register an offense with the same name but in the
different namespace' do
               ^^^^^^^^

25 files inspected, 10 offenses detected
rake aborted!
Command failed with status (1): [rubocop...]
/Users/koic/src/github.com/rubocop-hq/rubocop-rake/Rakefile:36:in `block
in <top (required)>'
/Users/koic/.rbenv/versions/2.7.0/bin/bundle:23:in `load'
/Users/koic/.rbenv/versions/2.7.0/bin/bundle:23:in `<main>'
Tasks: TOP => default => rubocop
(See full trace by running task with --trace)
```

`LineLength` cop has been moved from `Metrics` department
to `Layout` department.

cf. rubocop/rubocop#7542
sihugh added a commit to alphagov/rubocop-govuk that referenced this pull request Dec 30, 2019
Resolves warning after upgrade of rubocop from 0.77 to 0.78:

> config/gds-ruby-styleguide.yml: Layout/LineLength has the wrong namespace - should be Metrics

[Relevant Rubocop issue](rubocop/rubocop#7542)
sds pushed a commit to sds/slim-lint that referenced this pull request Jan 3, 2020
ta1kt0me added a commit to grooves/forkwell_cop that referenced this pull request Jan 6, 2020
masutaka added a commit to masutaka/circleci-bundle-update-pr that referenced this pull request Jan 21, 2020
masutaka added a commit to masutaka/circleci-bundle-update-pr that referenced this pull request Jan 21, 2020
ipmsteven added a commit to ipmsteven/rubocop-github that referenced this pull request Apr 18, 2020
johnboyes added a commit to johnboyes/hotcustard-payments that referenced this pull request Aug 19, 2020
johnboyes added a commit to johnboyes/hotcustard-payments that referenced this pull request Aug 19, 2020
johnboyes added a commit to johnboyes/hotcustard-payments that referenced this pull request Aug 20, 2020
johnboyes added a commit to johnboyes/hotcustard-payments that referenced this pull request Aug 20, 2020
johnboyes added a commit to johnboyes/hotcustard-payments that referenced this pull request Aug 20, 2020
* Add default Ruby sinatra devcontainer settings

We want to be able to run the application in a [Visual Studio Code
Docker devcontainer][1] (including on [GitHub Codespaces][2]), rather
than having to install all the software locally.

This commit adds the [default Ruby sinatra devcontainer settings][3].

The application will not run on the devcontainer yet, as we will need
to customise the container settings to install the additional software
we need (e.g. Redis).  We will apply these customisations in subsequent
commits.

[1]: https://code.visualstudio.com/docs/remote/containers
[2]: https://github.com/features/codespaces
[3]: https://github.com/microsoft/vscode-dev-containers/tree/master/containers/ruby-sinatra

* Set devcontainer Ruby version to match Gemfile's

* Ensure gpg is available to git to sign commits

* Set Visual Studio Code as the git editor

* Suppress Dockerfile unpinned gem versions warning

We will pin the gem versions in a later commit.  Not doing it in this
commit as want to take the smallest steps possible to get the
application running successfully in a Docker devcontainer.

* Bump Ruby to 2.5.8 so it can run in devcontainer

The version before this commit (2.5.3) is not available as a Docker
devcontainer image.

* Install RuboCop on Docker devcontainer

[RuboCop][1] is the predominant Ruby linter. We have already been using
it on this project for a long time, so it definitely needs to be on the
devcontainer.

[1]: https://github.com/rubocop-hq/rubocop

* Add ruby-rubocop devcontainer extension

[Ruby RuboCop extension homepage][1]

Also ensured that the RuboCop execution path and settings location are
set correctly via the `devcontainer.json` file.

[1]: https://github.com/misogi/vscode-ruby-rubocop

* Update location of RuboCop line length check

The new location was introduced in [RuboCop 0.78.0][1], via [this PR][2]

[1]: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md#0780-2019-12-18
[2]: rubocop/rubocop#7542

* Install application gems upon container creation

* Install Redis on devcontainer

Redis is needed for the application to run locally.

We set Redis to start every time the container starts or restarts.

* Install Heroku to run app locally on devcontainer

To run the app locally on the devcontainer we use [Heroku Local][1].
We install Heroku Local using the [standalone method][2].

[1]: https://devcenter.heroku.com/articles/heroku-local
[2]: https://devcenter.heroku.com/articles/heroku-cli#standalone-installation

* Make the web app available outside devcontainer

We use [Heroku Local][1] to run the web app, so we forward Heroku
Local's default port of 5000 so we can access it outside the container.

[1]: https://devcenter.heroku.com/articles/heroku-local

* Stop installing Sinatra on devcontainer

There is no need, as it is declared in the Gemfile as one of the
project's gems.

* Stop installing Nodejs on the devcontainer

We don't use Node in this project.

* Use language server to improve Ruby IDE experience

The VS Code [Ruby extension highly recommends using the language server]
[1], which is why we have switched to it in this commit.

It integrates with RuboCop, so we have also removed the separate RuboCop
extension.

We are using the default language server settings suggested by the
extension's homepage (except we use a globally installed RuboCop gem,
rather than bundling it with the project).

[1]: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby

* Document the new local development workflow

Added documentation for remote containers and Codespaces.
MegaDev007 added a commit to MegaDev007/slim-lint that referenced this pull request Aug 3, 2024
Breaking change in RuboCop 0.78.0

Ref: rubocop/rubocop#7542
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.

3 participants