troessner / reek

Code smell detector for Ruby
https://github.com/troessner/reek
MIT License
4k stars 279 forks source link

Fix ModuleInitialize false positive with custom Data constructor #1682

Closed bkuhlmann closed 10 months ago

bkuhlmann commented 1 year ago

Overview

Hello. :wave: I'm working on upgrading to Ruby 3.2.0 by leveraging the new Data primitive and discovered a slight bug where Reek doesn't handle a custom Data constructor.

Screenshots

2022-12-18_11-04-29-iTerm2

Steps to Recreate

# frozen_string_literal: true

RootMail = Data.define :from, :to do
  # ✅ Reek doesn't detect this as a code smell.
  def initialize from: nil, to: nil
    super
  end
end

module Demo
  Mail = Data.define :from, :to do
    # ❌ Reek thinks this is a code smell.
    def initialize from: nil, to: nil
      super
    end
  end
end

Workaround

As a workaround, I can configure Reek to ignore the source files with false positives but would definitely prefer not to have to do that. 😅

Environment

mvz commented 1 year ago

Thanks, @bkuhlmann, I'll take a look.

bkuhlmann commented 12 months ago

Hey. :wave: Wanted to touch base on this. Would this be possible to support? I run into this a lot when working Data primitives and would make using them more enjoyable when this isn't flagged.

mvz commented 12 months ago

Hi @bkuhlmann thanks for the ping. I've created a pull request for this.