KEMBAR78
Enhance `Naming/MethodName` cop to handle offenses within `Struct` members by viralpraxis · Pull Request #14325 · rubocop/rubocop · GitHub
Skip to content

Conversation

@viralpraxis
Copy link
Contributor

This patch enhances Naming/MethodName to detect these offenses:

Struct.new(:fooBar) # offense if style is `snake_case`

Struct.new(:foo_bar) # offense if style is `camelCase`

Since the first argument of Struct.new might be a special string (class_name), it's ignored. See https://rubyapi.org/3.4/o/struct#method-c-new


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.
  • 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.

@viralpraxis viralpraxis marked this pull request as ready for review June 23, 2025 10:26
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 25, 2025

Your proposal seems reasonable. Looking at the specs I noticed that the cop doesn't also check for define_method with a literal as the method name, which it should probably do as well.

viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jun 25, 2025
…hod` calls

ref: rubocop#14325 (comment)

```
This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
define_method(:fooBar) {} # offense if style is `snake_case`

define_method(:foo_bar) {} # offense if style is `camelCase`
```
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jun 25, 2025
…hod` calls

ref: rubocop#14325 (comment)

This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
define_method(:fooBar) {} # offense if style is `snake_case`

define_method(:foo_bar) {} # offense if style is `camelCase`
```
@viralpraxis viralpraxis marked this pull request as draft June 25, 2025 23:27
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jun 26, 2025
…hod` calls

ref: rubocop#14325 (comment)

This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
define_method(:fooBar) {} # offense if style is `snake_case`

define_method(:foo_bar) {} # offense if style is `camelCase`
```
bbatsov pushed a commit that referenced this pull request Jun 26, 2025
…hod` calls

ref: #14325 (comment)

This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
define_method(:fooBar) {} # offense if style is `snake_case`

define_method(:foo_bar) {} # offense if style is `camelCase`
```
…mbers

This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
Struct.new(:fooBar) # offense if style is `snake_case`

Struct.new(:foo_bar) # offense if style is `camelCase`
```

Since the first argument of `Struct.new` might be a special string (`class_name`),
it's ignored. See https://rubyapi.org/3.4/o/struct#method-c-new
@viralpraxis viralpraxis force-pushed the enhance-naming-method-name-cop-to-detect-offenses-within-struct-members branch from dafcf4a to 60b0daa Compare June 26, 2025 11:57
@viralpraxis viralpraxis marked this pull request as ready for review June 26, 2025 12:00
@bbatsov bbatsov merged commit 6c55825 into rubocop:master Jun 26, 2025
22 of 23 checks passed
@viralpraxis
Copy link
Contributor Author

This can be extended by also taking Data.define and OpenStruct.new into account.

@viralpraxis viralpraxis deleted the enhance-naming-method-name-cop-to-detect-offenses-within-struct-members branch June 26, 2025 12:36
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jul 3, 2025
…hod` calls

ref: rubocop#14325 (comment)

This patch enhances `Naming/MethodName` to detect these offenses:

```ruby
define_method(:fooBar) {} # offense if style is `snake_case`

define_method(:foo_bar) {} # offense if style is `camelCase`
```
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jul 19, 2025
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request Jul 20, 2025
5hun-s pushed a commit to 5hun-s/rubocop that referenced this pull request Jul 21, 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