Skip to content

Commit

Permalink
Fix false positive for SpaceAroundOperators
Browse files Browse the repository at this point in the history
Refs #983
  • Loading branch information
rrrene committed Jul 22, 2022
1 parent 5725c8f commit 0710977
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators.SpaceHelper do
def usually_no_space_after?({:"(", _}, {:dual_op, _, :-}, {:int, _, _}), do: true
def usually_no_space_after?({:"(", _}, {:dual_op, _, :-}, {:float, _, _}), do: true
def usually_no_space_after?({:"(", _}, {:dual_op, _, :-}, {:flt, _, _}), do: true
def usually_no_space_after?({:"{", _}, {:dual_op, _, :-}, {:identifier, _, _}), do: true
def usually_no_space_after?({:"{", _}, {:dual_op, _, :-}, {:number, _, _}), do: true
def usually_no_space_after?({:"{", _}, {:dual_op, _, :-}, {:int, _, _}), do: true
def usually_no_space_after?({:"{", _}, {:dual_op, _, :-}, {:float, _, _}), do: true
def usually_no_space_after?({:"{", _}, {:dual_op, _, :-}, {:flt, _, _}), do: true
def usually_no_space_after?({:",", _}, {:dual_op, _, :-}, {:identifier, _, _}), do: true
def usually_no_space_after?({:",", _}, {:dual_op, _, :-}, {:number, _, _}), do: true
def usually_no_space_after?({:",", _}, {:dual_op, _, :-}, {:int, _, _}), do: true
Expand Down
28 changes: 27 additions & 1 deletion test/credo/check/consistency/space_around_operators_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,31 @@ defmodule Credo.Check.Consistency.SpaceAroundOperatorsTest do
assert MyModule.fun != -24
ExUnit.assert -12 == MyApp.fun_that_should_return_a_negative
"""

@with_spaces7 """
defmodule AlwaysNoSpacesInBinaryTypespecTest do
@callback foo() :: <<_::_*8>>
def foo, do: 1 + 1
end
"""
@with_spaces8 """
defmodule AlwaysNoSpacesInBinaryTypespecTest do
def seed_collection(entity, collection, opts) when is_map(collection) do
collection = Enum.map(collection, fn {_key, entity} -> entity end)
seed_collection(entity, collection, opts)
end
def foo do
%{
geom12: %Geo.Point{coordinates: {-74.30323, 47.619055}},
geom13: %Geo.Point{coordinates: {-74.30323, 47.619055}},
geom14: %Geo.Point{coordinates: {-74.30323, 47.619055}},
geom15: %Geo.Point{coordinates: {-74.30323, 47.619055}},
}
end
end
"""

@with_and_without_spaces """
defmodule OtherModule3 do
Expand Down Expand Up @@ -250,6 +267,15 @@ defmodule Credo.Check.Consistency.SpaceAroundOperatorsTest do
|> refute_issues()
end

test "it should not report issues when operators are negative float values" do
[
@with_spaces8
]
|> to_source_files()
|> run_check(@described_check)
|> refute_issues()
end

test "it should not report issues if spaces are used everywhere" do
[
@with_spaces,
Expand Down

0 comments on commit 0710977

Please sign in to comment.