rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

Use explicit negative ranges #1135

Closed kevinschweikert closed 3 months ago

kevinschweikert commented 3 months ago

In Elixir 1.17-rc.0 we get these warnings:

==> credo
Compiling 253 files (.ex)
warning: x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it
  (credo 1.7.4) lib/credo/backports.ex:4: Credo.Backports.Enum.slice/2

warning: x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it
  (credo 1.7.4) lib/credo/backports.ex:16: Credo.Backports.String.slice/2

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/explain/output/default.ex:272: Credo.CLI.Command.Explain.Output.Default.print_check_explanation/2

warning: 1..-1 has a default step of -1, please write 1..-1//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:107: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:109: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:110: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:111: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:112: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/cli/command/diff/task/get_git_diff.ex:113: Credo.CLI.Command.Diff.Task.GetGitDiff.run_credo_on_dir/4

warning: 1..-2 has a default step of -1, please write 1..-2//-1 instead
  (credo 1.7.4) lib/credo/check/config_comment.ex:138: Credo.Check.ConfigComment.value_for/1

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/consistency/multi_alias_import_require_use/collector.ex:41: Credo.Check.Consistency.MultiAliasImportRequireUse.Collector.traverse/2

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/warning/unused_function_return_helper.ex:135: Credo.Check.Warning.UnusedFunctionReturnHelper.verify_candidate/3

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/warning/unused_function_return_helper.ex:135: Credo.Check.Warning.UnusedFunctionReturnHelper.verify_candidate/3

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/warning/unused_function_return_helper.ex:135: Credo.Check.Warning.UnusedFunctionReturnHelper.verify_candidate/3

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/warning/unused_function_return_helper.ex:135: Credo.Check.Warning.UnusedFunctionReturnHelper.verify_candidate/3

warning: 0..-2 has a default step of -1, please write 0..-2//-1 instead
  (credo 1.7.4) lib/credo/check/warning/unused_function_return_helper.ex:135: Credo.Check.Warning.UnusedFunctionReturnHelper.verify_candidate/3

This PR fixes them

rrrene commented 3 months ago

With the release of 1.17, we can no longer use the Backports module and have to move the minimum Elixir version up to 1.13 (I think).

I will take a closer look soon. :+1:

rrrene commented 3 months ago

@kevinschweikert Thx for this!

rrrene commented 3 months ago

Please check out the RC to see if there are remaining issues: https://github.com/rrrene/credo/releases/tag/v1.7.7-rc.0 🧡

kevinschweikert commented 3 months ago

Tested 1.7.7-rc.o, and it compiles without warnings in my projects!