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 with rescued Rails.root #1392

Conversation

viralpraxis
Copy link
Contributor

@viralpraxis viralpraxis commented Dec 12, 2024

echo "\"#{Rails.root rescue '.'}/config\"" | rubocop --stdin bug.rb --only Rails/FilePath -d

An error occurred while Rails/FilePath cop was inspecting bug.rb:1:0.
undefined method `method?' for an instance of RuboCop::AST::RescueNode
lib/rubocop/cop/rails/file_path.rb:156:in `autocorrect_slash_after_rails_root_in_dstr'
lib/rubocop/cop/rails/file_path.rb:81:in `block in check_for_slash_after_rails_root_in_dstr'

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.

@koic
Copy link
Member

koic commented Dec 13, 2024

This looks good to me. Can you add a changelog entry and rebase with the latest master branch?

@viralpraxis viralpraxis force-pushed the fix-rails-file-path-cop-error-with-rescued-rails-root branch from 74892f1 to 30529f0 Compare December 13, 2024 21:21
```console
echo '"#{Rails.root rescue "."}/config"' | rubocop --stdin bug.rb -d

An error occurred while Rails/FilePath cop was inspecting bug.rb:1:0.
undefined method `method?' for an instance of RuboCop::AST::RescueNode
lib/rubocop/cop/rails/file_path.rb:156:in `autocorrect_slash_after_rails_root_in_dstr'
lib/rubocop/cop/rails/file_path.rb:81:in `block in check_for_slash_after_rails_root_in_dstr'
```
@viralpraxis viralpraxis force-pushed the fix-rails-file-path-cop-error-with-rescued-rails-root branch from 30529f0 to bb03d6b Compare December 13, 2024 21:22
@koic koic merged commit c6f869b into rubocop:master Dec 13, 2024
14 checks passed
@koic
Copy link
Member

koic commented Dec 13, 2024

Thanks!

@viralpraxis viralpraxis deleted the fix-rails-file-path-cop-error-with-rescued-rails-root branch December 21, 2024 13:16
viralpraxis added a commit to viralpraxis/rubocop-rails that referenced this pull request Dec 21, 2024
…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 added a commit to viralpraxis/rubocop-rails that referenced this pull request Dec 21, 2024
…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 added a commit to viralpraxis/rubocop-rails that referenced this pull request Dec 22, 2024
…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 added a commit to viralpraxis/rubocop-rails that referenced this pull request Dec 22, 2024
…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 added a commit to viralpraxis/rubocop-rails that referenced this pull request Dec 22, 2024
…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.
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