-
-
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/RootPublicPath
cop
#588
Add new Rails/RootPublicPath
cop
#588
Conversation
6f726fc
to
d3b0bc9
Compare
Instead of ```ruby Rails.root.join('public') Rails.root.join('public/file.pdf') Rails.root.join('public', 'file.pdf') ``` we can use ```ruby Rails.public_path Rails.public_path.join('file.pdf') Rails.public_path.join('file.pdf') ```
d3b0bc9
to
ce65d64
Compare
|
||
it "registers an offense when using `Rails.root.join('public/file.pdf')`" do | ||
expect_offense(<<~RUBY) | ||
Rails.root.join('public/file.pdf') |
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.
Will it detect "public/#{file}.pdf"
?
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.
Not yet. Will work on that.
Rails/RootPublicPath: | ||
Description: "Favor `Rails.public_path` over `Rails.root` with `'public'`." | ||
Enabled: pending | ||
VersionAdded: '2.13' |
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.
VersionAdded: '2.13' | |
VersionAdded: '<<next>>' |
|
||
RESTRICT_ON_SEND = %i[join].to_set.freeze | ||
|
||
PATTERN = %r{^public(/|$)}.freeze |
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.
\A
and \z
would be preferable if it is unexpecting a match to a multiline.
PATTERN = %r{^public(/|$)}.freeze | |
PATTERN = %r{\Apublic(/|\z)}.freeze |
@@ -484,3 +484,4 @@ | |||
[@theunraveler]: https://github.com/theunraveler | |||
[@pirj]: https://github.com/pirj | |||
[@vitormd]: https://github.com/vitormd | |||
[@leoarnold]: https://github.com/leoarnold |
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.
Account name will be auto-inserted, so it's better to remove it.
@leoarnold Can you rebase with the latest mater branch? |
@leoarnold Ping |
I've cherry-picked this PR into the master branch. The following can be extended later. Thank you. |
Instead of
we can use
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.