Repository: rrrene/credo
Pull request #1112 (2024-01-17 17:28:36)

Remove variable name clause for check that can't compile
This clause helped a test pass, but the test is made of code that can't compile
```ex
Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule CredoSampleModule do
...(1)>       def some_function(param, p2, p3) do
...(1)>         [someValue + v2 + v3 | {someValue} <- param, v2 <- p2, v3 <- p3]
...(1)>       end
...(1)>     end
error: misplaced operator |/2
```


Patch:
diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml
index 41081bc0..1a5b99a9 100644
--- a/.github/workflows/ci-workflow.yml
+++ b/.github/workflows/ci-workflow.yml
@@ -11,7 +11,7 @@ on:
 jobs:
   test:
     runs-on: ubuntu-20.04
-    name: "Elixir ${{matrix.elixir}} OTP ${{matrix.otp}}"
+    name: "[${{matrix.otp}}/${{matrix.elixir}}] CI Tests on Credo [OTP/Elixir]"
     strategy:
       fail-fast: false
       matrix:
diff --git a/.github/workflows/compatibility-elixir.yml b/.github/workflows/compatibility-elixir.yml
index f84edf26..0a46ba4e 100644
--- a/.github/workflows/compatibility-elixir.yml
+++ b/.github/workflows/compatibility-elixir.yml
@@ -9,7 +9,7 @@ jobs:
   test_on_source:
     runs-on: ubuntu-20.04
     if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
-    name: "Elixir ${{matrix.elixir}} OTP ${{matrix.otp}} - Credo running on Elixir ${{matrix.repo_branch}} source code"
+    name: "[${{matrix.otp}}/${{matrix.elixir}}] Elixir ${{matrix.repo_branch}} source code analysed by Credo [OTP/Elixir]"
     strategy:
       fail-fast: false
       matrix:
diff --git a/.github/workflows/compatibility-os-mac.yml b/.github/workflows/compatibility-os-mac.yml
deleted file mode 100644
index 8fa5d764..00000000
--- a/.github/workflows/compatibility-os-mac.yml
+++ /dev/null
@@ -1,71 +0,0 @@
-name: "Compatibility: macOS"
-
-on:
-  push:
-    branches:
-      - master
-      - release/*
-  pull_request:
-    branches:
-      - master
-
-jobs:
-  test:
-    name: "Compile & Run"
-    runs-on: macos-latest
-    steps:
-      - uses: actions/checkout@master
-
-      - name: Install Elixir
-        run: |
-          brew update
-          brew install elixir
-
-      - run: mix deps.get
-      - run: mix deps.compile
-      - run: |
-          mix compile --force --warnings-as-errors
-
-      - run: |
-          mix credo --mute-exit-status
-
-          mix credo --strict --mute-exit-status
-          mix credo --strict --enable-disabled-checks . --mute-exit-status
-          mix credo --debug --mute-exit-status
-          mix credo --strict --format=sarif --mute-exit-status
-          mix credo list --mute-exit-status
-          mix credo suggest --mute-exit-status
-          mix credo diff HEAD^ --mute-exit-status
-          mix credo diff v1.4.0 --mute-exit-status
-
-      - run: |
-          # explain issues
-          mix credo test/fixtures/example_code/clean_redux.ex:1:11 --mute-exit-status
-          mix credo explain test/fixtures/example_code/clean_redux.ex:1:11 --mute-exit-status
-          mix credo test/fixtures/example_code/clean_redux.ex:1:11 --mute-exit-status --format=json
-          mix credo explain test/fixtures/example_code/clean_redux.ex:1:11 --mute-exit-status --format=json
-
-      - run: |
-          # explain check
-          mix credo explain Credo.Check.Refactor.Nesting --mute-exit-status
-          mix credo explain Credo.Check.Refactor.Nesting --mute-exit-status --format=json
-
-      - run: |
-          mix credo categories
-          mix credo categories --format=json
-
-      - run: |
-          mix credo info
-          mix credo info --verbose
-          mix credo info --format=json
-          mix credo info --verbose --format=json
-
-      - run: |
-          mix credo version
-          mix credo help
-
-          mix credo -v
-          mix credo -h
-
-          echo ""
-          echo "Smoke test successful."
diff --git a/.github/workflows/compatibility-os-windows.yml b/.github/workflows/compatibility-os.yml
similarity index 90%
rename from .github/workflows/compatibility-os-windows.yml
rename to .github/workflows/compatibility-os.yml
index 49ef7c6f..c06dac74 100644
--- a/.github/workflows/compatibility-os-windows.yml
+++ b/.github/workflows/compatibility-os.yml
@@ -1,4 +1,4 @@
-name: "Compatibility: Windows"
+name: "OS Smoke Tests"
 on:
   push:
     branches:
@@ -10,10 +10,12 @@ on:
 
 jobs:
   test:
-    name: "Compile & Run"
-    runs-on: windows-2022
+    runs-on: ${{ matrix.os }}
+    name: "[${{matrix.os}}] testing latest Credo [OS]"
     strategy:
       fail-fast: false
+      matrix:
+        os: [ubuntu-20.04, windows-2022] # macos-12 (erlef/setup-beam does not work with macOS)
     steps:
       - uses: actions/checkout@v4
         with:
diff --git a/.github/workflows/compatibility-phoenix.yml b/.github/workflows/compatibility-phoenix.yml
index 5b4b3a4d..e6dbead2 100644
--- a/.github/workflows/compatibility-phoenix.yml
+++ b/.github/workflows/compatibility-phoenix.yml
@@ -8,7 +8,7 @@ on:
 jobs:
   test_on_source:
     runs-on: ubuntu-20.04
-    name: "Elixir ${{matrix.elixir}} OTP ${{matrix.otp}} - ${{matrix.repo_branch}}"
+    name: "[${{matrix.otp}}/${{matrix.elixir}}] Phoenix ${{matrix.repo_branch}} source code analysed by Credo [OTP/Elixir]"
     strategy:
       fail-fast: false
       matrix:
diff --git a/.github/workflows/housekeeping-format.yml b/.github/workflows/housekeeping-format.yml
deleted file mode 100644
index e57553a7..00000000
--- a/.github/workflows/housekeeping-format.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-name: "Housekeeping"
-on:
-  push:
-    branches:
-      - master
-      - release/*
-  pull_request:
-    branches:
-      - master
-
-jobs:
-  test:
-    name: "mix format"
-    runs-on: ubuntu-18.04
-    steps:
-      - uses: actions/checkout@v4
-        with:
-          fetch-depth: 0
-      - uses: erlef/setup-beam@v1
-        with:
-          otp-version: 26.2
-          elixir-version: 1.16.0
-      - run: mix deps.get
-      - run: mix compile
-      - run: ./test/check_formatted.sh
diff --git a/lib/credo/check/readability/alias_as.ex b/lib/credo/check/readability/alias_as.ex
index bb366f3d..a072e938 100644
--- a/lib/credo/check/readability/alias_as.ex
+++ b/lib/credo/check/readability/alias_as.ex
@@ -48,19 +48,18 @@ defmodule Credo.Check.Readability.AliasAs do
   defp add_issue(issues, issue), do: [issue | issues]
 
   defp issue({:alias, _, [{:__MODULE__, _, nil}, [as: {_, meta, _}]]}, issue_meta),
-    do: issue_for(issue_meta, meta[:line])
+    do: issue_for(issue_meta, meta[:line], inspect(:__MODULE__))
 
-  defp issue({:alias, _, [{_, _, _}, [as: {_, meta, _}]]}, issue_meta) do
-    issue_for(issue_meta, meta[:line])
-  end
+  defp issue({:alias, _, [{_, _, original}, [as: {_, meta, _}]]}, issue_meta),
+    do: issue_for(issue_meta, meta[:line], inspect(Module.concat(original)))
 
   defp issue(_ast, _issue_meta), do: nil
 
-  defp issue_for(issue_meta, line_no) do
+  defp issue_for(issue_meta, line_no, trigger) do
     format_issue(
       issue_meta,
       message: "Avoid using the :as option with alias.",
-      trigger: "as:",
+      trigger: trigger,
       line_no: line_no
     )
   end
diff --git a/lib/credo/check/readability/variable_names.ex b/lib/credo/check/readability/variable_names.ex
index b15464f3..e23d4d4c 100644
--- a/lib/credo/check/readability/variable_names.ex
+++ b/lib/credo/check/readability/variable_names.ex
@@ -40,14 +40,6 @@ defmodule Credo.Check.Readability.VariableNames do
     {ast, issues_for_lhs(lhs, issues, issue_meta)}
   end
 
-  defp traverse(
-         {:<-, _meta, [{:|, _comp_meta, [_lhs, rhs]}, _comp_rhs]} = ast,
-         issues,
-         issue_meta
-       ) do
-    {ast, issues_for_lhs(rhs, issues, issue_meta)}
-  end
-
   defp traverse({:<-, _meta, [lhs, _rhs]} = ast, issues, issue_meta) do
     {ast, issues_for_lhs(lhs, issues, issue_meta)}
   end
diff --git a/lib/credo/code/module.ex b/lib/credo/code/module.ex
index 9be7c2cc..5cb29cc3 100644
--- a/lib/credo/code/module.ex
+++ b/lib/credo/code/module.ex
@@ -306,7 +306,9 @@ defmodule Credo.Code.Module do
     module_parts(state)
   end
 
-  defp traverse_file({:defmodule, meta, [first_arg, [do: module_ast]]}, state) do
+  defp traverse_file({:defmodule, meta, args}, state) do
+    [first_arg, [do: module_ast]] = args
+
     state = start_module(state, meta)
     {_ast, state} = Macro.prewalk(module_ast, state, &traverse_module/2)
 
diff --git a/lib/credo/code/name.ex b/lib/credo/code/name.ex
index 7f0172de..65650b3d 100644
--- a/lib/credo/code/name.ex
+++ b/lib/credo/code/name.ex
@@ -75,11 +75,6 @@ defmodule Credo.Code.Name do
     full([full(mod_list), name])
   end
 
-  def full({{:., _, [{struct_name, _, nil}, field_name]}, _, []})
-      when is_atom(struct_name) and is_atom(field_name) do
-    full([struct_name, field_name])
-  end
-
   def full({:@, _, [{name, _, nil}]}) when is_atom(name) do
     "@#{name}"
   end


Test patch:
diff --git a/.github/workflows/compatibility-canary-smoke-tests.yml b/.github/workflows/compatibility-canary-smoke-tests.yml
index e4cd9a5e..a4c472e4 100644
--- a/.github/workflows/compatibility-canary-smoke-tests.yml
+++ b/.github/workflows/compatibility-canary-smoke-tests.yml
@@ -8,7 +8,7 @@ on:
 jobs:
   test_on_new_project:
     runs-on: ubuntu-20.04
-    name: "${{matrix.project.name}}"
+    name: "[${{matrix.project.name}}]"
     strategy:
       fail-fast: false
       matrix:
diff --git a/lib/credo/check/refactor/pass_async_in_test_cases.ex b/lib/credo/check/refactor/pass_async_in_test_cases.ex
index dfab01d8..649dcb76 100644
--- a/lib/credo/check/refactor/pass_async_in_test_cases.ex
+++ b/lib/credo/check/refactor/pass_async_in_test_cases.ex
@@ -26,11 +26,7 @@ defmodule Credo.Check.Refactor.PassAsyncInTestCases do
   end
 
   # `use` with options
-  defp traverse(
-         {:use, _, [{_, meta, module_namespace}, [_ | _] = options]} = ast,
-         issues,
-         issue_meta
-       ) do
+  defp traverse({:use, _, [{_, meta, module_namespace}, options]} = ast, issues, issue_meta) do
     module_name = module_name_from(module_namespace)
 
     if String.ends_with?(module_name, "Case") and !Keyword.has_key?(options, :async) do
diff --git a/test/credo/check/readability/alias_as_test.exs b/test/credo/check/readability/alias_as_test.exs
index f878f83e..ef439512 100644
--- a/test/credo/check/readability/alias_as_test.exs
+++ b/test/credo/check/readability/alias_as_test.exs
@@ -32,7 +32,7 @@ defmodule Credo.Check.Readability.AliasAsTest do
     |> to_source_file
     |> run_check(@described_check)
     |> assert_issue(fn issue ->
-      assert issue.trigger == "as:"
+      assert issue.trigger == "App.Module1"
     end)
   end
 
@@ -50,9 +50,9 @@ defmodule Credo.Check.Readability.AliasAsTest do
       |> run_check(@described_check)
       |> assert_issues()
 
-    assert issue1.trigger == "as:"
-    assert issue2.trigger == "as:"
-    assert issue3.trigger == "as:"
+    assert issue1.trigger == "App.Module1"
+    assert issue2.trigger == "App.Module3"
+    assert issue3.trigger == "App.Module4"
   end
 
   test "it should report on alias __MODULE__, as: Foo" do
diff --git a/test/credo/check/readability/variable_names_test.exs b/test/credo/check/readability/variable_names_test.exs
index 0f7b39b5..42a2dc0d 100644
--- a/test/credo/check/readability/variable_names_test.exs
+++ b/test/credo/check/readability/variable_names_test.exs
@@ -149,19 +149,6 @@ defmodule Credo.Check.Readability.VariableNamesTest do
     |> assert_issue()
   end
 
-  test "it should report a violation /10" do
-    """
-    defmodule CredoSampleModule do
-      def some_function(param, p2, p3) do
-        [someValue + v2 + v3 | {someValue} <- param, v2 <- p2, v3 <- p3]
-      end
-    end
-    """
-    |> to_source_file
-    |> run_check(@described_check)
-    |> assert_issue()
-  end
-
   test "it should report a violation /11" do
     """
     defmodule CredoSampleModule do