Permalink
Browse files

Reformat code with 120 chars per line

  • Loading branch information...
rrrene committed Feb 18, 2018
1 parent 1d8e2bd commit 578875b2d6c891e0ece718a318fbe39111a0a643
Showing with 124 additions and 292 deletions.
  1. +1 −2 .formatter.exs
  2. +1 −2 lib/credo/check.ex
  3. +1 −2 lib/credo/check/consistency/exception_names.ex
  4. +1 −2 lib/credo/check/consistency/multi_alias_import_require_use.ex
  5. +1 −2 lib/credo/check/consistency/multi_alias_import_require_use/collector.ex
  6. +1 −2 lib/credo/check/consistency/parameter_pattern_matching.ex
  7. +3 −9 lib/credo/check/consistency/space_around_operators.ex
  8. +1 −2 lib/credo/check/consistency/space_in_parentheses.ex
  9. +1 −2 lib/credo/check/consistency/tabs_or_spaces.ex
  10. +9 −19 lib/credo/check/design/alias_usage.ex
  11. +1 −2 lib/credo/check/design/duplicated_code.ex
  12. +1 −2 lib/credo/check/find_lint_attributes.ex
  13. +3 −6 lib/credo/check/readability/max_line_length.ex
  14. +1 −2 lib/credo/check/readability/module_doc.ex
  15. +3 −6 lib/credo/check/readability/parentheses_in_condition.ex
  16. +1 −2 lib/credo/check/readability/parentheses_on_zero_arity_defs.ex
  17. +1 −4 lib/credo/check/readability/prefer_unquoted_atoms.ex
  18. +2 −4 lib/credo/check/readability/redundant_blank_lines.ex
  19. +1 −2 lib/credo/check/readability/semicolons.ex
  20. +3 −6 lib/credo/check/readability/string_sigils.ex
  21. +1 −2 lib/credo/check/readability/trailing_white_space.ex
  22. +2 −6 lib/credo/check/refactor/abc_size.ex
  23. +1 −2 lib/credo/check/refactor/append_single_item.ex
  24. +1 −2 lib/credo/check/refactor/cond_statements.ex
  25. +2 −4 lib/credo/check/refactor/cyclomatic_complexity.ex
  26. +3 −7 lib/credo/check/refactor/function_arity.ex
  27. +1 −2 lib/credo/check/refactor/long_quote_blocks.ex
  28. +1 −3 lib/credo/check/refactor/nesting.ex
  29. +2 −4 lib/credo/check/refactor/perceived_complexity.ex
  30. +3 −6 lib/credo/check/refactor/pipe_chain_start.ex
  31. +1 −2 lib/credo/check/refactor/unless_with_else.ex
  32. +1 −3 lib/credo/check/warning/bool_operation_on_same_values.ex
  33. +2 −4 lib/credo/check/warning/lazy_logging.ex
  34. +1 −2 lib/credo/check/warning/name_redeclaration_by_case.ex
  35. +1 −2 lib/credo/check/warning/name_redeclaration_by_def.ex
  36. +1 −2 lib/credo/check/warning/name_redeclaration_by_fn.ex
  37. +2 −4 lib/credo/check/warning/raise_inside_rescue.ex
  38. +1 −2 lib/credo/check/warning/unused_function_return_helper.ex
  39. +1 −2 lib/credo/cli/command/list/list_command.ex
  40. +1 −2 lib/credo/cli/command/suggest/suggest_command.ex
  41. +1 −2 lib/credo/cli/filter.ex
  42. +2 −4 lib/credo/cli/task/prepare_checks_to_run.ex
  43. +1 −2 lib/credo/code/block.ex
  44. +2 −4 lib/credo/code/interpolation_helper.ex
  45. +1 −3 lib/credo/code/parameters.ex
  46. +12 −51 lib/credo/code/token.ex
  47. +1 −3 lib/credo/execution/monitor.ex
  48. +2 −5 lib/credo/execution/task.ex
  49. +1 −2 lib/credo/execution/task/parse_options.ex
  50. +1 −2 lib/credo/priority.ex
  51. +1 −2 mix.exs
  52. +2 −4 test/credo/check/code_helper_test.exs
  53. +1 −2 test/credo/check/config_comment_finder_test.exs
  54. +5 −10 test/credo/check/design/duplicated_code_test.exs
  55. +2 −4 test/credo/cli/command/gen.check_test.exs
  56. +3 −7 test/credo/cli/filename_test.exs
  57. +4 −12 test/credo/code/interpolation_helper_test.exs
  58. +1 −2 test/credo/code/name_test.exs
  59. +2 −4 test/credo/code/parameters_test.exs
  60. +6 −12 test/credo/code/scope_test.exs
  61. +4 −4 test/credo/config_file_test.exs
  62. +1 −2 test/credo/source_file_test.exs
  63. +2 −6 test/test_helper.exs
@@ -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]
]
@@ -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]
@@ -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, [
@@ -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)
@@ -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)
@@ -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])
@@ -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
@@ -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 =
[
@@ -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]))
@@ -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)
@@ -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 [
@@ -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
@@ -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
@@ -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
)
@@ -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 [
@@ -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
@@ -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 [
@@ -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)
@@ -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 [
@@ -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
@@ -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
)
@@ -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
@@ -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
@@ -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 [
@@ -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
@@ -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(
@@ -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 [
@@ -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,
@@ -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
@@ -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 [
@@ -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
@@ -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)
@@ -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
@@ -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
)
Oops, something went wrong.

0 comments on commit 578875b

Please sign in to comment.