Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reformat code with 120 chars per line
  • Loading branch information
rrrene committed Feb 18, 2018
1 parent 1d8e2bd commit 578875b
Show file tree
Hide file tree
Showing 63 changed files with 124 additions and 292 deletions.
3 changes: 1 addition & 2 deletions .formatter.exs
Expand Up @@ -9,6 +9,5 @@ export_locals_without_parens = [
[
inputs: ["{mix,.formatter,.credo}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: export_locals_without_parens,
export: [locals_without_parens: export_locals_without_parens],
line_length: 80
export: [locals_without_parens: export_locals_without_parens]
]
3 changes: 1 addition & 2 deletions lib/credo/check.ex
Expand Up @@ -120,8 +120,7 @@ defmodule Credo.Check do

@callback explanation_for_params() :: Keyword.t()

@callback format_issue(issue_meta :: IssueMeta, opts :: Keyword.t()) ::
Issue.t()
@callback format_issue(issue_meta :: IssueMeta, opts :: Keyword.t()) :: Issue.t()

def explanation_for(nil, _), do: nil
def explanation_for(keywords, key), do: keywords[key]
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/consistency/exception_names.ex
Expand Up @@ -40,8 +40,7 @@ defmodule Credo.Check.Consistency.ExceptionNames do
defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

issue_locations =
@collector.find_locations_not_matching(expected, source_file)
issue_locations = @collector.find_locations_not_matching(expected, source_file)

Enum.map(issue_locations, fn location ->
format_issue(issue_meta, [
Expand Down
Expand Up @@ -31,8 +31,7 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUse do
defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

issue_locations =
@collector.find_locations_not_matching(expected, source_file)
issue_locations = @collector.find_locations_not_matching(expected, source_file)

Enum.map(issue_locations, fn line_no ->
format_issue(issue_meta, message: message_for(expected), line_no: line_no)
Expand Down
Expand Up @@ -61,8 +61,7 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUse.Collector do
|> Enum.into(%{})
end

defp drop_locations({_, single}, :multi),
do: multiple_single_locations(single)
defp drop_locations({_, single}, :multi), do: multiple_single_locations(single)

defp drop_locations({multi, _}, :single), do: multi_locations(multi)

Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/consistency/parameter_pattern_matching.ex
Expand Up @@ -27,8 +27,7 @@ defmodule Credo.Check.Consistency.ParameterPatternMatching do
defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

issue_locations =
@collector.find_locations_not_matching(expected, source_file)
issue_locations = @collector.find_locations_not_matching(expected, source_file)

Enum.map(issue_locations, fn location ->
format_issue(issue_meta, [{:message, message_for(expected)} | location])
Expand Down
12 changes: 3 additions & 9 deletions lib/credo/check/consistency/space_around_operators.ex
Expand Up @@ -104,9 +104,7 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators do
# -2 because we need to subtract the operator
line
|> String.slice(0..(column - 2))
|> String.match?(
~r/(\A\s+|\@[a-zA-Z0-9\_]+|[\|\\\{\[\(\,\:\>\<\=\+\-\*\/])\s*$/
)
|> String.match?(~r/(\A\s+|\@[a-zA-Z0-9\_]+|[\|\\\{\[\(\,\:\>\<\=\+\-\*\/])\s*$/)
end

defp number_in_range?(line, column) do
Expand Down Expand Up @@ -145,17 +143,13 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators do
typed_after? =
line
|> String.slice(column..-1)
|> String.match?(
~r/^\s*(integer|native|signed|unsigned|binary|size|little|float)/
)
|> String.match?(~r/^\s*(integer|native|signed|unsigned|binary|size|little|float)/)

# -2 because we need to subtract the operator
typed_before? =
line
|> String.slice(0..(column - 2))
|> String.match?(
~r/(integer|native|signed|unsigned|binary|size|little|float)\s*$/
)
|> String.match?(~r/(integer|native|signed|unsigned|binary|size|little|float)\s*$/)

heuristics_met_count =
[
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/consistency/space_in_parentheses.ex
Expand Up @@ -30,8 +30,7 @@ defmodule Credo.Check.Consistency.SpaceInParentheses do
defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

lines_with_issues =
@collector.find_locations_not_matching(expected, source_file)
lines_with_issues = @collector.find_locations_not_matching(expected, source_file)

lines_with_issues
|> Enum.filter(&create_issue?(expected, &1[:trigger]))
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/consistency/tabs_or_spaces.ex
Expand Up @@ -26,8 +26,7 @@ defmodule Credo.Check.Consistency.TabsOrSpaces do
defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

lines_with_issues =
@collector.find_locations_not_matching(expected, source_file)
lines_with_issues = @collector.find_locations_not_matching(expected, source_file)

Enum.map(lines_with_issues, fn line_no ->
format_issue(issue_meta, message: message_for(expected), line_no: line_no)
Expand Down
28 changes: 9 additions & 19 deletions lib/credo/check/design/alias_usage.ex
Expand Up @@ -32,10 +32,8 @@ defmodule Credo.Check.Design.AliasUsage do
@explanation [
check: @moduledoc,
params: [
if_nested_deeper_than:
"Only raise an issue if a module is nested deeper than this.",
if_called_more_often_than:
"Only raise an issue if a module is called more often than this."
if_nested_deeper_than: "Only raise an issue if a module is nested deeper than this.",
if_called_more_often_than: "Only raise an issue if a module is called more often than this."
]
]
@default_params [
Expand Down Expand Up @@ -69,22 +67,16 @@ defmodule Credo.Check.Design.AliasUsage do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

excluded_namespaces =
Params.get(params, :excluded_namespaces, @default_params)
excluded_namespaces = Params.get(params, :excluded_namespaces, @default_params)

excluded_lastnames =
Params.get(params, :excluded_lastnames, @default_params)
excluded_lastnames = Params.get(params, :excluded_lastnames, @default_params)

if_nested_deeper_than =
Params.get(params, :if_nested_deeper_than, @default_params)
if_nested_deeper_than = Params.get(params, :if_nested_deeper_than, @default_params)

if_called_more_often_than =
Params.get(params, :if_called_more_often_than, @default_params)
if_called_more_often_than = Params.get(params, :if_called_more_often_than, @default_params)

source_file
|> Credo.Code.prewalk(
&traverse(&1, &2, issue_meta, excluded_namespaces, excluded_lastnames)
)
|> Credo.Code.prewalk(&traverse(&1, &2, issue_meta, excluded_namespaces, excluded_lastnames))
|> filter_issues_if_called_more_often_than(if_called_more_often_than)
|> filter_issues_if_nested_deeper_than(if_nested_deeper_than)
end
Expand Down Expand Up @@ -190,8 +182,7 @@ defmodule Credo.Check.Design.AliasUsage do
first_name = Credo.Code.Name.first(mod_list)
last_name = Credo.Code.Name.last(mod_list)

Enum.member?(excluded_namespaces, first_name) ||
Enum.member?(excluded_lastnames, last_name)
Enum.member?(excluded_namespaces, first_name) || Enum.member?(excluded_lastnames, last_name)
end

# Returns true if mod_list and alias_name would result in the same alias
Expand Down Expand Up @@ -249,8 +240,7 @@ defmodule Credo.Check.Design.AliasUsage do
defp issue_for(issue_meta, line_no, trigger) do
format_issue(
issue_meta,
message:
"Nested modules could be aliased at the top of the invoking module.",
message: "Nested modules could be aliased at the top of the invoking module.",
trigger: trigger,
line_no: line_no
)
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/design/duplicated_code.ex
Expand Up @@ -23,8 +23,7 @@ defmodule Credo.Check.Design.DuplicatedCode do
params: [
mass_threshold:
"The minimum mass which a part of code has to have to qualify for this check.",
nodes_threshold:
"The number of nodes that need to be found to raise an issue."
nodes_threshold: "The number of nodes that need to be found to raise an issue."
]
]
@default_params [
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/find_lint_attributes.ex
Expand Up @@ -15,8 +15,7 @@ defmodule Credo.Check.FindLintAttributes do
end

def find_lint_attributes(source_file) do
lint_attributes =
Credo.Code.prewalk(source_file, &traverse(&1, &2, source_file))
lint_attributes = Credo.Code.prewalk(source_file, &traverse(&1, &2, source_file))

{source_file.filename, lint_attributes}
end
Expand Down
9 changes: 3 additions & 6 deletions lib/credo/check/readability/max_line_length.ex
Expand Up @@ -9,11 +9,9 @@ defmodule Credo.Check.Readability.MaxLineLength do
check: @moduledoc,
params: [
max_length: "The maximum number of characters a line may consist of.",
ignore_definitions:
"Set to `true` to ignore lines including function definitions.",
ignore_definitions: "Set to `true` to ignore lines including function definitions.",
ignore_specs: "Set to `true` to ignore lines including `@spec`s.",
ignore_strings:
"Set to `true` to ignore lines that are strings or in heredocs"
ignore_strings: "Set to `true` to ignore lines that are strings or in heredocs"
]
]
@default_params [
Expand All @@ -35,8 +33,7 @@ defmodule Credo.Check.Readability.MaxLineLength do
issue_meta = IssueMeta.for(source_file, params)
max_length = Params.get(params, :max_length, @default_params)

ignore_definitions =
Params.get(params, :ignore_definitions, @default_params)
ignore_definitions = Params.get(params, :ignore_definitions, @default_params)

ignore_specs = Params.get(params, :ignore_specs, @default_params)
ignore_strings = Params.get(params, :ignore_strings, @default_params)
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/readability/module_doc.ex
Expand Up @@ -36,8 +36,7 @@ defmodule Credo.Check.Readability.ModuleDoc do
@explanation [
check: @moduledoc,
params: [
ignore_names:
"All modules matching this regex (or list of regexes) will be ignored."
ignore_names: "All modules matching this regex (or list of regexes) will be ignored."
]
]
@default_params [
Expand Down
9 changes: 3 additions & 6 deletions lib/credo/check/readability/parentheses_in_condition.ex
Expand Up @@ -162,11 +162,9 @@ defmodule Credo.Check.Readability.ParenthesesInCondition do
children
end

defp collect_paren_child({:"(", _}, {nest_level, tokens}),
do: {nest_level + 1, tokens}
defp collect_paren_child({:"(", _}, {nest_level, tokens}), do: {nest_level + 1, tokens}

defp collect_paren_child({:")", _}, {nest_level, tokens}),
do: {nest_level - 1, tokens}
defp collect_paren_child({:")", _}, {nest_level, tokens}), do: {nest_level - 1, tokens}

defp collect_paren_child(token, {0, tokens}), do: {0, tokens ++ [token]}
defp collect_paren_child(_, {_, _} = state), do: state
Expand All @@ -186,8 +184,7 @@ defmodule Credo.Check.Readability.ParenthesesInCondition do
defp issue_for(issue_meta, line_no, trigger) do
format_issue(
issue_meta,
message:
"The condition of `#{trigger}` should not be wrapped in parentheses.",
message: "The condition of `#{trigger}` should not be wrapped in parentheses.",
trigger: trigger,
line_no: line_no
)
Expand Down
Expand Up @@ -80,8 +80,7 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do
defp issue_for(issue_meta, line_no) do
format_issue(
issue_meta,
message:
"Do not use parentheses when defining a function which has no arguments.",
message: "Do not use parentheses when defining a function which has no arguments.",
line_no: line_no
)
end
Expand Down
5 changes: 1 addition & 4 deletions lib/credo/check/readability/prefer_unquoted_atoms.ex
Expand Up @@ -102,10 +102,7 @@ defmodule Credo.Check.Readability.PreferUnquotedAtoms do

format_issue(
issue_meta,
message:
"Use unquoted atom `#{inspect(atom)}` rather than quoted atom `#{
trigger
}`.",
message: "Use unquoted atom `#{inspect(atom)}` rather than quoted atom `#{trigger}`.",
trigger: trigger,
line_no: line_no,
column: column
Expand Down
6 changes: 2 additions & 4 deletions lib/credo/check/readability/redundant_blank_lines.ex
Expand Up @@ -10,8 +10,7 @@ defmodule Credo.Check.Readability.RedundantBlankLines do
@explanation [
check: @moduledoc,
params: [
max_blank_lines:
"The maximum number of tolerated consecutive blank lines."
max_blank_lines: "The maximum number of tolerated consecutive blank lines."
]
]
@default_params [
Expand All @@ -36,8 +35,7 @@ defmodule Credo.Check.Readability.RedundantBlankLines do
defp issue_for(issue_meta, line, max_blank_lines) do
format_issue(
issue_meta,
message:
"There should be no more than #{max_blank_lines} consecutive blank lines.",
message: "There should be no more than #{max_blank_lines} consecutive blank lines.",
line_no: line
)
end
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/readability/semicolons.ex
Expand Up @@ -30,8 +30,7 @@ defmodule Credo.Check.Readability.Semicolons do
collect_issues(rest, acc, issue_meta)
end

defp collect_issues([_ | rest], acc, issue_meta),
do: collect_issues(rest, acc, issue_meta)
defp collect_issues([_ | rest], acc, issue_meta), do: collect_issues(rest, acc, issue_meta)

def issue_for(issue_meta, line_no, column) do
format_issue(
Expand Down
9 changes: 3 additions & 6 deletions lib/credo/check/readability/string_sigils.ex
Expand Up @@ -22,8 +22,7 @@ defmodule Credo.Check.Readability.StringSigils do
@explanation [
check: @moduledoc,
params: [
maximum_allowed_quotes:
"The maximum amount of escaped quotes you want to tolerate."
maximum_allowed_quotes: "The maximum amount of escaped quotes you want to tolerate."
]
]
@default_params [
Expand All @@ -37,8 +36,7 @@ defmodule Credo.Check.Readability.StringSigils do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

maximum_allowed_quotes =
Params.get(params, :maximum_allowed_quotes, @default_params)
maximum_allowed_quotes = Params.get(params, :maximum_allowed_quotes, @default_params)

Credo.Code.prewalk(
source_file,
Expand Down Expand Up @@ -92,8 +90,7 @@ defmodule Credo.Check.Readability.StringSigils do
issue_meta,
line_no
) do
if !is_heredoc(issue_meta, line_no) &&
too_many_quotes?(string, maximum_allowed_quotes) do
if !is_heredoc(issue_meta, line_no) && too_many_quotes?(string, maximum_allowed_quotes) do
[issue_for(issue_meta, line_no, string, maximum_allowed_quotes) | issues]
else
issues
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/readability/trailing_white_space.ex
Expand Up @@ -8,8 +8,7 @@ defmodule Credo.Check.Readability.TrailingWhiteSpace do
@explanation [
check: @moduledoc,
params: [
ignore_strings:
"Set to `false` to check lines that are strings or in heredocs"
ignore_strings: "Set to `false` to check lines that are strings or in heredocs"
]
]
@default_params [
Expand Down
8 changes: 2 additions & 6 deletions lib/credo/check/refactor/abc_size.ex
Expand Up @@ -95,8 +95,7 @@ defmodule Credo.Check.Refactor.ABCSize do
def abc_size_for(ast, arguments) do
initial_acc = [a: 0, b: 0, c: 0, var_names: get_parameters(arguments)]

[a: a, b: b, c: c, var_names: _] =
Credo.Code.prewalk(ast, &traverse_abc/2, initial_acc)
[a: a, b: b, c: c, var_names: _] = Credo.Code.prewalk(ast, &traverse_abc/2, initial_acc)

:math.sqrt(a * a + b * b + c * c)
end
Expand Down Expand Up @@ -236,10 +235,7 @@ defmodule Credo.Check.Refactor.ABCSize do
def issue_for(issue_meta, line_no, trigger, max_value, actual_value) do
format_issue(
issue_meta,
message:
"Function is too complex (ABC size is #{actual_value}, max is #{
max_value
}).",
message: "Function is too complex (ABC size is #{actual_value}, max is #{max_value}).",
trigger: trigger,
line_no: line_no,
severity: Severity.compute(actual_value, max_value)
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/refactor/append_single_item.ex
Expand Up @@ -45,8 +45,7 @@ defmodule Credo.Check.Refactor.AppendSingleItem do
defp issue_for(issue_meta, line_no, trigger) do
format_issue(
issue_meta,
message:
"Appending a single item to a list is inefficient, use [head | tail]
message: "Appending a single item to a list is inefficient, use [head | tail]
notation (and Enum.reverse/1 when order matters)",
trigger: trigger,
line_no: line_no
Expand Down
3 changes: 1 addition & 2 deletions lib/credo/check/refactor/cond_statements.ex
Expand Up @@ -53,8 +53,7 @@ defmodule Credo.Check.Refactor.CondStatements do
def issue_for(issue_meta, line_no, trigger) do
format_issue(
issue_meta,
message:
"Cond statements should contain at least two conditions besides `true`.",
message: "Cond statements should contain at least two conditions besides `true`.",
trigger: trigger,
line_no: line_no
)
Expand Down

0 comments on commit 578875b

Please sign in to comment.