Skip to content

Commit fb3ff12

Browse files
author
Digit
authored
Fix size(variable) causing an issue (#24)
1 parent 14b08b3 commit fb3ff12

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/credo_binary_patterns/check/consistency/pattern.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ defmodule CredoBinaryPatterns.Check.Consistency.Pattern do
145145
[{value_matched, [line: _, column: _], nil}, {:size, _, [size_value]}]} = ast,
146146
issues,
147147
issue_meta
148-
) do
148+
)
149+
when is_integer(size_value) do
149150
process_traverse(
150151
value_matched,
151152
[:size, size_value],

test/credo_binary_patterns/check/consistency/pattern_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ defmodule CredoBinaryPatterns.Check.Consistency.PatternTest do
176176
|> assert_issue()
177177
end
178178

179+
test "Should NOT raise an issue if size is used with a variable value" do
180+
"""
181+
defmodule Test do
182+
def some_function(x) do
183+
<<x::size(variable_value)>>
184+
end
185+
end
186+
"""
187+
|> to_source_file()
188+
|> run_check(@described_check)
189+
|> refute_issues()
190+
end
191+
179192
# Bit Strings
180193

181194
test "Should raise an issue if constants are used with `bitstring`" do

0 commit comments

Comments
 (0)