-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Move LineLength
cop from Metrics
to Layout
department
#7542
Conversation
58e5a8d
to
b56bcdf
Compare
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 guess we can revisit this before 1.0 when we discuss which defaults should be updated. |
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.
b56bcdf
to
6deb06b
Compare
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 ```
En rubocop 0.78.0 se mueve LineLength de departamento rubocop/rubocop#7542
`Metrics/LineLength` moved to `Layout/LineLength` since rubocop 0.78.0 c.f. rubocop/rubocop#7542
`Metrics/LineLength` moved to `Layout/LineLength` since rubocop 0.78.0 c.f. rubocop/rubocop#7542
Breaking change in RuboCop 0.78.0 Ref: rubocop/rubocop#7542
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
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)
Breaking change in RuboCop 0.78.0 Ref: rubocop/rubocop#7542
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
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
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
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
* 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.
Breaking change in RuboCop 0.78.0 Ref: rubocop/rubocop#7542
Summary
The
Layout
department was created afterMetrics
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 whenLineLength
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 byClassLength
cop,MethodLength
cop, andBlockLength
cop isresolved by a logic change.
So
ClassLength
,MethodLength
, andBlockLength
cop remain inthe
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:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.