Skip to content

Commit

Permalink
Merge branch 'master' into fix-deprected-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Jul 25, 2023
2 parents 9fa8370 + 00ca6ed commit cfb4c13
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 28 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,20 @@ on:

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
name: "[${{matrix.otp}}/${{matrix.elixir}}] CI Tests on Credo [OTP/Elixir]"
strategy:
fail-fast: false
matrix:
otp: [21.3, 22.3, 23.3, 24.2]
elixir: [1.10.4, 1.11.4, 1.12.2, 1.13.4, 1.14.0]
otp: [23.3, 24.2, 25.3, 26.0]
elixir: [1.11.4, 1.12.2, 1.13.4, 1.14.5, 1.15.4]
exclude:
- otp: 24.2
elixir: 1.10.4
- otp: 21.3
elixir: 1.12.2
- otp: 21.3
elixir: 1.13.4
- otp: 21.3
elixir: 1.14.0
- otp: 22.3
elixir: 1.14.0
- elixir: 1.14.5
otp: 26.0
- elixir: 1.15.4
otp: 23.3
steps:
- uses: actions/checkout@v2.3.1
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: erlef/setup-beam@v1
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 24.2
elixir 1.14.2
erlang 26.0
elixir 1.15.4
2 changes: 1 addition & 1 deletion guides/commands/suggest_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Alias for [`--ignore-checks`](#ignore-checks-aliased-as-ignore)

### `--min-priority`

Minimum priority to show issues (high,medium,normal,low,lower or number)
Minimum priority to show issues (higher,high,normal,low,ignore or number)

```bash
$ mix credo --min-priority high
Expand Down
2 changes: 1 addition & 1 deletion guides/configuration/cli_switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Suggest options:
--format Display the list in a specific format (json,flycheck,oneline)
-i, --ignore-checks Ignore checks that match the given strings
--ignore Alias for --ignore-checks
--min-priority Minimum priority to show issues (high,medium,normal,low,lower or number)
--min-priority Minimum priority to show issues (higher,high,normal,low,ignore or number)
--mute-exit-status Exit with status zero even if there are issues
--only Alias for --checks
--strict Alias for --all-priorities
Expand Down
20 changes: 16 additions & 4 deletions lib/credo/check/warning/missed_metadata_key_in_logger_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Credo.Check.Warning.MissedMetadataKeyInLoggerConfig do
In your app's logger configuration, you would need to include the `:error_code` key:
config :logger, :console,
format: "[$level] $message $metadata\n",
format: "[$level] $message $metadata\\n",
metadata: [:error_code, :file]
That way your logs might then receive lines like this:
Expand All @@ -43,11 +43,23 @@ defmodule Credo.Check.Warning.MissedMetadataKeyInLoggerConfig do
@impl Credo.Check
def run(%SourceFile{} = source_file, params) do
issue_meta = IssueMeta.for(source_file, params)
state = {false, []}

{_, issues} = Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta), state)
if ignore_check?(issue_meta) do
[]
else
state = {false, []}

{_, issues} = Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta), state)

issues
end
end

issues
# if logger metadata: :all is set, then ignore this check
defp ignore_check?(issue_meta) do
issue_meta_params = IssueMeta.params(issue_meta)
metadata_keys = find_metadata_keys(issue_meta_params)
metadata_keys == :all
end

defp traverse(
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/diff/diff_output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Credo.CLI.Command.Diff.DiffOutput do
--from-git-merge-base Diff from where the current HEAD branched off from the given merge base
-i, --ignore-checks Ignore checks that match the given strings
--ignore Alias for --ignore-checks
--min-priority Minimum priority to show issues (high,medium,normal,low,lower or number)
--min-priority Minimum priority to show issues (higher,high,normal,low,ignore or number)
--mute-exit-status Exit with status zero even if there are issues
--only Alias for --checks
--since Diff from the given point in time (using Git)
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/info/info_output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Credo.CLI.Command.Info.InfoOutput do
--format Display the list in a specific format (json,flycheck,oneline)
-i, --ignore-checks Ignore checks that match the given strings
--ignore Alias for --ignore-checks
--min-priority Minimum priority to show issues (high,medium,normal,low,lower or number)
--min-priority Minimum priority to show issues (higher,high,normal,low,ignore or number)
--only Alias for --checks
--verbose Display more information (e.g. checked files)
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/list/list_output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Credo.CLI.Command.List.ListOutput do
--format Display the list in a specific format (json,flycheck,oneline)
-i, --ignore-checks Ignore checks that match the given strings
--ignore Alias for --ignore-checks
--min-priority Minimum priority to show issues (high,medium,normal,low,lower or number)
--min-priority Minimum priority to show issues (higher,high,normal,low,ignore or number)
--mute-exit-status Exit with status zero even if there are issues
--only Alias for --checks
--strict Alias for --all-priorities
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/suggest/suggest_output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Credo.CLI.Command.Suggest.SuggestOutput do
--format Display the list in a specific format (json,flycheck,oneline)
-i, --ignore-checks Ignore checks that match the given strings
--ignore Alias for --ignore-checks
--min-priority Minimum priority to show issues (high,medium,normal,low,lower or number)
--min-priority Minimum priority to show issues (higher,high,normal,low,ignore or number)
--mute-exit-status Exit with status zero even if there are issues
--only Alias for --checks
--strict Alias for --all-priorities
Expand Down
9 changes: 7 additions & 2 deletions lib/credo/priority.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Credo.Priority do
@def_ops [:def, :defp, :defmacro]
@many_functions_count 5

@priority_names ~w[higher high normal low ignore]
@priority_names_map %{
"ignore" => -100,
"low" => -10,
Expand All @@ -29,12 +30,16 @@ defmodule Credo.Priority do
case Integer.parse(string) do
:error -> string |> String.to_atom() |> to_integer()
{value, ""} -> value
{_value, _rest} -> raise "Got an invalid priority: #{inspect(string)}"
{_value, _rest} -> raise error_message_for_invalid_priority(string)
end
end

def to_integer(key) when is_atom(key) do
@priority_names_map[to_string(key)] || raise "Got an invalid priority: #{inspect(key)}"
@priority_names_map[to_string(key)] || raise error_message_for_invalid_priority(key)
end

defp error_message_for_invalid_priority(key) do
"Got an invalid priority: #{inspect(key)} (valid are numbers or #{Enum.join(@priority_names, "/")})"
end

def to_atom(priority)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ defmodule Credo.Check.Warning.MissedMetadataKeyInLoggerConfigTest do
|> refute_issues()
end

test "it should NOT report when Logger.log/3 is used with metadata set to :all" do
"""
defmodule CredoSampleModule do
def some_function(parameter1, parameter2) do
Logger.log(:info, fn ->
"A warning message: #{inspect(1)}"
end, account_id: 1)
end
end
"""
|> to_source_file
|> run_check(@described_check, metadata_keys: :all)
|> refute_issues()
end

test "it should NOT report when Logger.log/2 is used" do
"""
defmodule CredoSampleModule do
Expand Down

0 comments on commit cfb4c13

Please sign in to comment.