Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In https://github.com/orgs/qltysh/discussions/1313 @nk-ty noted that `qlty` and `codeclimate` CLIs calculate the cognitive complexity of a method with trailing unless statements differently. After some investigation, I determined that both were incorrectly calculating cognitive complexity. This PR is concerned with the cognitive complexity calculation in qlty. The following are equivalent ways of expressing an `if` conditional in Ruby: ```ruby if !foo puts "hi" end ``` ```ruby unless foo puts "foo" end ``` ```ruby puts "hi" if !foo ``` ```ruby puts "hi" unless foo ``` The first was correctly being calculated. The second was an obvious oversight. And the 3rd and 4th ones were less obvious oversights (the parser calls them `if_modifier` / `unless_modifier` nodes not `if` / `unless` nodes. This PR categorizes all 4 as `if_nodes` which the cognitive complexity calculator uses, and correctly penalizes all 4 as 1 point.
- Loading branch information