Skip to content

Latest commit

 

History

History
193 lines (143 loc) · 5.14 KB

Reek-4-to-Reek-5-migration.md

File metadata and controls

193 lines (143 loc) · 5.14 KB

Reek 4 to Reek 5 migration

Schema validation

Reek now uses a schema to validate your configuration against on start up and will faily loudly in case you misspelled an option or used the wrong data type for a value like this:

Error: We found some problems with your configuration file: [/detectors/DetectorWithTypo] key 'DetectorWithTypo:' is undefined.

Obviously this might affect existing configuration files that until now contained an error nobody noticed.

Scoping detectors under detectors

In Reek 4 you could just configure your detectors on top level like this:

UncommunicativeMethodName:
  accept:
    - foobar
UnusedPrivateMethod:
  exclude:
    - app/controllers  

In Reek 5 you have to scope your detector configurations under the detectors key:

detectors:
  UncommunicativeMethodName:
    accept:
      - foobar
  UnusedPrivateMethod:
    exclude:
    - app/controllers  

Move directory directives under a special key

In Reek 4 you could apply directory specific directives like this:

---
"web_app/app/controllers":
  NestedIterators:
    enabled: false
"web_app/app/helpers":
  UtilityFunction:
    enabled: false

which was nice and easy but also quite messy. With Reek 5 you'll have to scope this under a directories key like this:

---
directories:
  "web_app/app/controllers":
    NestedIterators:
      enabled: false
  "web_app/app/helpers":
    UtilityFunction:
      enabled: false

No more regular expressions in Reeks configuration

In Reek 4 you could pass regular expressions to the accept or reject settings of

and to the exclude settings which are part of our Basic Smell Options.

This means that this configuration was perfectly valid:

detectors:
  UncommunicativeMethodName:
    accept:
      - !ruby/regexp /foobar/
  UnusedPrivateMethod:
    exclude:
      - !ruby/regexp /i am(.*)unused/  

Support for this has been scrapped with Reek 5 to make the Reek configuration more yaml standard compliant. You can still pass in regexes, you just have to wrap them into a string using a forward slash at the beginning and at the end of the string like this:

---
UncommunicativeMethodName:
  accept:
    - "/^foobar$/"
UnusedPrivateMethod:
  exclude:
    - "/i am(.*)unused/"  

Everything within the forward slashes will be loaded as a regex.

No more single item shortcuts for list items

You cant use a configuration option that is supposed to be a list with a single element like this anymore:

---
UncommunicativeMethodName:
  accept: foobar
UnusedPrivateMethod:
  exclude: omg  

You'll have to use a proper list here like this:

---
UncommunicativeMethodName:
  accept: 
    - foobar
UnusedPrivateMethod:
  exclude:
    - omg  

Failing on syntax errors in source files

Previously Reek would just continue on syntax errors in source files which might have been convenient but not necessarily fitting for a tool that's all about code quality. With Reek 5, Reek will fail hard on invalid source files.

API changes

This is something that will only affect very advanced users. In case you have no idea what this might be about you can just skip it or check out our Developer API.

Allow only detector names in configuration hash

In Reek 4 you could build your configuration like this:

config_hash = { Reek::SmellDetectors::IrresponsibleModule => { 'enabled' => false } }

or like this:

config_hash = { 'IrresponsibleModule' => { 'enabled' => false } }

Starting with Reek 5, the first way is not working anymore and the latter one is what you'll have to use.

Do not accept a class as parameter for reek_of

In the same vein as the change above you also can't use fully qualified detector names like this:

 reek_of(Reek::SmellDetectors::DuplicateMethodCall)

The only supported way now is either as symbol or string:

reek_of(:DuplicateMethodCall)
reek_of('DuplicateMethodCall')

Smaller changes

  • PrimaDonnaMethod has been given the better name MissingSafeMethod
  • wiki-links flag has been renamed to documentation flag
  • Reek assumes the default configuration file to be named ".reek.yml" and will ignore all other files. You can still use any name you want though by passing in a name via the -c flag
  • We have dropped the legacy code comment separator ":" at the end of a detector name. If you wanted to configure a smell detector via comment before this release you had to use g like this:
# :reek:UnusedPrivateMethod: { exclude: [ bravo ] }

Mind the ":" at the end of "UnusedPrivateMethod". This syntax is disallowed with Reek 5 - you have to drop the ":" at the end now like this:

# :reek:UnusedPrivateMethod { exclude: [ bravo ] }
  • We have dropped support for Ruby 2.1 and 2.2 since they are officially not supported by the Ruby core team anymore