-
-
Notifications
You must be signed in to change notification settings - Fork 263
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 new Rails/RootJoinChain
cop
#586
Merged
koic
merged 1 commit into
rubocop:master
from
leoarnold:leoarnold/rails-root-join-chain
Nov 28, 2021
Merged
Add new Rails/RootJoinChain
cop
#586
koic
merged 1 commit into
rubocop:master
from
leoarnold:leoarnold/rails-root-join-chain
Nov 28, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
from
November 21, 2021 05:18
cd98870
to
8e77876
Compare
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Nov 21, 2021
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
9 tasks
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
from
November 21, 2021 06:01
8e77876
to
5a867ab
Compare
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Nov 21, 2021
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
from
November 21, 2021 07:04
5a867ab
to
af7d2a1
Compare
pirj
approved these changes
Nov 21, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
from
November 21, 2021 14:38
af7d2a1
to
1f7a089
Compare
koic
reviewed
Nov 21, 2021
koic
reviewed
Nov 21, 2021
koic
reviewed
Nov 21, 2021
koic
reviewed
Nov 21, 2021
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
2 times, most recently
from
November 23, 2021 02:38
95c2fe4
to
d6dc624
Compare
Instead of chaining `#join` on `Rails.root` or `Rails.public_path` ```ruby Rails.root.join('db').join('schema.rb') Rails.root.join('db').join(migrate).join('migration.rb') Rails.public_path.join('path').join('file.pdf') Rails.public_path.join('path').join(to).join('file.pdf') ``` we can combine all arguments into a single join ```ruby Rails.root.join('db', 'schema.rb') Rails.root.join('db', migrate, 'migration.rb') Rails.public_path.join('path', 'file.pdf') Rails.public_path.join('path', to, 'file.pdf') ```
leoarnold
force-pushed
the
leoarnold/rails-root-join-chain
branch
from
November 23, 2021 03:05
d6dc624
to
6eae52a
Compare
Thanks! |
8 tasks
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 16, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 17, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 17, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 17, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 17, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
leoarnold
added a commit
to leoarnold/rubocop-rails
that referenced
this pull request
Jul 17, 2022
`Rails.root` is an instance of `Pathname`. So instead of ```ruby File.open(Rails.root.join('db', 'schema.rb')) File.open(Rails.root.join('db', 'schema.rb'), 'w') File.read(Rails.root.join('db', 'schema.rb')) File.binread(Rails.root.join('db', 'schema.rb')) File.write(Rails.root.join('db', 'schema.rb'), content) File.binwrite(Rails.root.join('db', 'schema.rb'), content) ``` we can simply write ```ruby Rails.root.join('db', 'schema.rb').open Rails.root.join('db', 'schema.rb').open('w') Rails.root.join('db', 'schema.rb').read Rails.root.join('db', 'schema.rb').binread Rails.root.join('db', 'schema.rb').write(content) Rails.root.join('db', 'schema.rb').binwrite(content) ``` This cop works best when used together with [`Style/FileRead`](rubocop/rubocop#10261), [`Style/FileWrite`](rubocop/rubocop#10260), and [`Rails/RootJoinChain`](rubocop#586).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of chaining
#join
onRails.root
orRails.public_path
we can combine all arguments into a single join
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.