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

Fix Rails/FilePath cop error in case of extra operations in Rails.root interpolation #1399

Conversation

viralpraxis
Copy link
Contributor

Follow-up to #1392. Previous PR didn't fix cases like this

"#{Rails.root || '.'}/config"

(it makes sense in real code since Rails.root can be nil)

I think it's safe to simply check if the entire expression is of send type.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root rescue '.'}/config"
RUBY
end
end

context 'with addition operations inside `Rails.root` interpolation expression' do
Copy link
Member

Choose a reason for hiding this comment

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

The meaning of "addition operations" is unclear. Could you clarify the context of this spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the spec's description, hope it's more clear now.

@viralpraxis viralpraxis force-pushed the fix-rails-file-path-cop-error-on-extra-operations-in-rails-root-interpolation branch 2 times, most recently from 2f60f06 to efe2c57 Compare December 22, 2024 19:08
…root` interpolation

Follow-up to rubocop#1392.
Previous PR didn't fix cases like this

```
"#{Rails.root || '.'}/config"
```

(it makes sense in real code since `Rails.root` [can be nil](https://github.com/rails/rails/blob/main/railties/lib/rails.rb#L65-L67))

I think it's safe to simply check if the entire expression is of `send` type.
@viralpraxis viralpraxis force-pushed the fix-rails-file-path-cop-error-on-extra-operations-in-rails-root-interpolation branch from efe2c57 to e4aee6b Compare December 22, 2024 19:12
@koic koic merged commit fecead8 into rubocop:master Dec 23, 2024
14 checks passed
@koic
Copy link
Member

koic commented Dec 23, 2024

Thanks!

koic added a commit that referenced this pull request Jan 2, 2025
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