profile
viewpoint
René Föhring rrrene 5Minds IT-Solutions GmbH & Co. KG Recklinghausen, Germany https://rrrene.org

inaka/credo_server 14

Credo Server

5minds/typescript-guidelines 4

Description and Styleguide for TypeScript via tslint

rrrene/awesome-elixir 2

A curated list of amazingly awesome Elixir and Erlang libraries, resources and shiny things.

5minds/javascript-guidelines 0

Our customized eslint config inspired by airbnb

cmg-dev/advanced_microservices 0

This Contains the Presentation of my Talk about Advanced Microservices.

rrrene/37-pieces-of-flair 0

The badges of github

rrrene/absinthe 0

GraphQL for Elixir

rrrene/action_enum 0

Fake enums for actionscript

rrrene/active_interaction 0

Manage application specific business logic.

rrrene/active_mocker 0

Create mocks from active record models and run them without loading rails or running a database.

issue commentrrrene/credo

Credo 1.6.0+ does not seem to complete

I narrowed this down to the :files key in the config. Will investigate more on the weekend! 👍

thbar

comment created time in 2 days

pull request commentrrrene/credo

FIX: detect unused variable when using guards

@ryvasquez Thx! 👍

ryvasquez

comment created time in 2 days

PR merged rrrene/credo

FIX: detect unused variable when using guards

Hello credo team! 👋

First of all thankyou for this great package!

When enablingUnusedVariableNames rule I noticed that it doesnt detect the unused variable when using guard due to different structure of the ast

# ast without guard <--- supported
[
  {:_, [line: 3, column: 13], nil},
  {:_, [line: 3, column: 16], nil},
  {:_, [line: 3, column: 19], nil}
]

# ast with guard <--- not supported
[
  {:bar, [line: 3, column: 9],
   [
     {:_, [line: 3, column: 13], nil},
     {:x2, [line: 3, column: 16], nil},
     {:_x3, [line: 3, column: 20], nil}
   ]},
  {:is_nil, [line: 3, column: 30], [{:x2, [line: 3, column: 37], nil}]}
]

To give concrete example, if the function is using guard with unused variable, the unused variable will not be detected by the collector

# credo.exs
Credo.Check.Consistency.UnusedVariableNames, [force: :anonymous]

# some_file.ex
# _x3 will be not be detected as unused variable, and will NOT complain about the consistency
def bar(_, x2, _x3) when is_nil(x2) do

so this proposal change will try to address that. This is my first time contributing this repo, so please let me know if I needed to do something else.

Thankyou!

+67 -1

0 comment

2 changed files

ryvasquez

pr closed time in 2 days

push eventrrrene/credo

ryvasquez

commit sha 61180c28ce106a4a3f1dcacc220f0e2eba30fc5f

FIX: detect unused variable when using guards

view details

René Föhring

commit sha b9d99da01b8c9a881d7ade5630c553623d31b503

Merge pull request #916 from ryvasquez/fix-undetected-unused-variable-with-guards FIX: detect unused variable when using guards

view details

push time in 2 days

push eventrrrene/credo

Ed Flanagan

commit sha 6372c46d19e2a9c4131f0d5045818d6bb65ad4b5

Fix #919: add `:in_op` to parentheses in conditon

view details

René Föhring

commit sha 6b436bfb0f37f12dcb24c9bcfffbde380c611009

Merge pull request #920 from ed-flanagan/issue-919/ed-flanagan/add-in-op-if-parens/1 Fix #919: add `:in_op` to parentheses in conditon

view details

push time in 2 days

issue closedrrrene/credo

False positive: "The condition of `if` should not be wrapped in parentheses."

Precheck

  • Proposals for new features should be submitted via: https://github.com/rrrene/credo-proposals
  • For bugs, please do a quick search and make sure the bug has not yet been reported here

Similar closed issues I came across:

  • https://github.com/rrrene/credo/issues/164
  • https://github.com/rrrene/credo/issues/461

Environment

  • Credo version (mix credo -v): 1.6.1-ref.main.cb6c59b+uncommittedchanges
  • Erlang/Elixir version (elixir -v): Elixir 1.12.3 (compiled with Erlang/OTP 24)
  • Operating system (sw_vers): macOS 11.6

What were you trying to do?

Checking membership of an element in a MapSet using in/2 rather than MapSet.member?/2.

Contrived example:

defmodule Example do
  @moduledoc false

  def example() do
    if (5 - 4) in MapSet.new([1]) do
      :ok
    else
      :error
    end
  end

  def a(), do: nil
end

mix format will add parentheses around the expression 5 - 4.

Regarding the trailing a/0 function: For some reason, I had trouble triggering the warning without a trailing function. Once added, it seems to consistently trigger the warning.

Expected outcome

No Readability issue.

Actual outcome

from mix credo explain:

...
┃   [R] Category: readability
┃    ↗  Priority: high
┃
┃       The condition of `if` should not be wrapped in parentheses.
┃       lib/credo_example.ex:5:5 (Example.example)
┃
┃    __ CODE IN QUESTION
┃
┃     3
┃     4   def example() do
┃     5     if (5 - 4) in MapSet.new([1]) do
┃           ^^
┃     6       :ok
┃     7     else
┃
┃    __ WHY IT MATTERS
...

closed time in 2 days

ed-flanagan

pull request commentrrrene/credo

Fix #919: add `:in_op` to parentheses in conditon

Looking good 👍 Will merge soon!

ed-flanagan

comment created time in 3 days

issue commentrrrene/credo

Credo 1.6.0+ does not seem to complete

Thx for reporting! :+1:

I will have a look ASAP. In the meantime: Could you change the Credo command on the branch to mix credo --strict --debug?

thbar

comment created time in 5 days

pull request commentrrrene/credo

Grammar fix

@jiegillet Thank you!

jiegillet

comment created time in 9 days

push eventrrrene/credo

Jie

commit sha 2e068fcaf1be46966e42f897be8426ac65871341

Grammar fix, "apply" -> "imply"

view details

René Föhring

commit sha 1c2c3679d72a18a956d6c54c0a8dd2a7af08ac55

Merge pull request #909 from jiegillet/patch-1 Grammar fix

view details

push time in 9 days

PR merged rrrene/credo

Grammar fix

Hello, I am a maintainer of the Elixir track on Exercism, and one of the tool in the track I work on is a code analyzer. Credo has inspired us a lot for that project, so many thanks to you.

Long story short, we were working on a check for unless with else, we looked at the message you provided, and found a typo in it.

+1 -1

0 comment

1 changed file

jiegillet

pr closed time in 9 days

push eventrrrene/credo

Mathias Polligkeit

commit sha 6a6761504daede1b1c9227d6fa44c65fa7921602

fix refactoring example

view details

René Föhring

commit sha 9091b9a67c165637eca6e085d6c7000e87329f33

Merge pull request #914 from woylie/patch-1 fix refactoring example

view details

push time in 9 days

PR merged rrrene/credo

fix refactoring example

Just saw this in the check output.

+1 -1

1 comment

1 changed file

woylie

pr closed time in 9 days

pull request commentrrrene/credo

fix refactoring example

It's pretty amazing that nobody, including me, ever noticed this. Thank you!

woylie

comment created time in 9 days

issue commentrrrene/credo

Credo does not install mix tasks

Strange. I have basically the same setup and just tested it. Can't reproduce.

If anybody has any ideas about this, please chime in :+1:

paulbickford

comment created time in 9 days

issue commentrrrene/credo

Max line length should ignore regex sigil

So we should not only ignore strings, but also sigils by default. Good catch! :+1:

datafoo

comment created time in 9 days

issue closedrrrene/credo

Exit with error status when fail to load config

Environment

  • Credo version (mix credo -v): 1.5.1
  • Erlang/Elixir version (elixir -v): Elixir 1.10.3 (compiled with Erlang/OTP 21)
  • Operating system: Ubuntu 20.04.1 LTS

What were you trying to do?

Run mix credo with a syntax error in .credo.exs

Expected outcome

Credo exit with an error status.

Actual outcome

➜  mix credo                                                                                                                                                                                                                            
** (config) Error while loading config file!

  file: /home/user/project/credo.exs
  line: 173

  syntax error before: '{'

  171          # Custom checks can be created using `mix credo.gen.check`.
  172          #
  173          {CredoNaming.Check.Consistency.ModuleFilename}
  174          ]
  175        }


➜  echo $?                                                                                                                                                                                                                              
0

Context

A syntax error was added by the team, but it tooks some time to be noticed because CI pipeline was ok, since credo was not exiting with an error status.

closed time in 9 days

Danielwsx64

issue commentrrrene/credo

Exit with error status when fail to load config

This is part of v1.6.1 💚

Danielwsx64

comment created time in 9 days

issue closedrrrene/credo

Credo complains when there's pattern match with `=` in a lambda inside of an `if` condition

Environment

  • Credo version (mix credo -v): 1.5.1
  • Erlang/Elixir version (elixir -v): Elixir 1.11.0 (compiled with Erlang/OTP 23)
  • Operating system: macOS 10.15.7

What were you trying to do?

if Enum.any?(Keyword.get_values(changeset.errors, attr), &({^message, _} = &1)) do
  ...
end

Note how there is a pattern match in the predicate to Enum.any?.

Expected outcome

No issues from Credo

Actual outcome

Credo complains with [F] → There should be no matches in 'if' conditions., even though this is not an assignment. My guess is it gets upset that it sees a lone = in the conditional expression of an if.

It might make sense to to a more nuanced check to see if the top-level expression of the conditional is a pattern-matching assignment.

closed time in 9 days

ashton314

issue closedrrrene/credo

Diff is checking files that weren't changed

Environment

  • Credo version (mix credo -v): 1.5.4
  • erlang; 23.1.5
  • elixir: 1.11.2-otp-23
  • Operating system: ubuntu:20.04 ci and MacOS 10.14.6 locally

What were you trying to do?

In ci I'm running mix credo diff master --config-name default -a and it shows issues from files that aren't in the diff. Ci is running ubuntu:20.04.

Expected outcome

I would expect to not see any issues, as none of the files are changed by my branch.

Actual outcome

In CI I'm seeing errors that aren't in the diff. In both places, I'm seeing the following. Diffing 710 source files in working dir with master (this might take a while) ...

closed time in 9 days

Ch4s3

issue commentrrrene/credo

Diff is checking files that weren't changed

This is part of v1.6.1 💚

Ch4s3

comment created time in 9 days

issue closedrrrene/credo

False positive in UnnecessaryAliasExpansion when alias value is the result of a function call

Environment

  • Credo version: 1.5.4
  • Erlang/Elixir version (elixir -v): 1.11.3
  • Operating system: Mac

What were you trying to do?

When writing a macro, wrapping a module reference in the alias!/1 macro forces it to resolve via the caller's aliases when compiling.

For example,

alias alias!(MyModule)

and its use in a proof-of-concept which leverages its functionality:

defmodule MyMacro do
  defmacro my_macro do
    quote do
      defmodule MySubmodule do
        alias alias!(MyAliasedModule)

        def test do
          IO.puts(MyAliasedModule)
        end
      end
    end
  end

  defmacro my_dsl(do: block) do
    quote do
      alias __MODULE__.MyAliasedModule

      defmodule MyAliasedModule do
      end

      unquote(block)
    end
  end
end

defmodule MyModule do
  import MyMacro

  my_dsl do
    my_macro
  end
end

will result in MyModule.MySubmodule.test/0 outputting Elixir.MyModule.MyAliasedModule as opposed to Elixir.MyAliasedModule had alias! not been used.

Expected outcome

Credo to not flag an UnnecessaryAliasExpansion styling error

Actual outcome

Using both alias and alias!, credo misconstrues it with an unnecessary alias expansion as it matches the pattern used by the checker. This can theoretically happen for other function calls as well in the form of alias my_function(MyModule) or alias MyModule.my_function(MyModule2).

For alias alias!(MyAliasedModule), the generated AST looks like:

{:alias, [context: Elixir],
 [
   {:alias!, [context: Elixir, import: Kernel],
    [{:__aliases__, [alias: false], [:MyAliasedModule]}]}
 ]}

which matches the pattern used for checking UnnecessaryAliasExpansion

{:alias, _, [{_, _, [{:__aliases__, opts, [child]}]}]}

UnnecessaryAliasExpansion may need to specify that the first element of the tuple is a :. operation with the second/last argument being a :{} to specify that it's an alias expansion.

{:alias, _,
  [{
    {:., _, [_, :{}]},
    _,
    [{:__aliases__, opts, [child]}]
  }]
}

closed time in 9 days

heydtn

issue closedrrrene/credo

Actual module not alphabetically ordered not mentioned

Environment

  • Credo version (mix credo -v): 1.5.5-ref.master.6e9dc6c+uncommittedchanges
  • Erlang/Elixir version (elixir -v): Elixir 1.11.3 (compiled with Erlang/OTP 23)
  • Operating system: Manjaro Linux

What were you trying to do?

alias Surface.Components.Form
alias Surface.Components.Form.{DateInput, TextInput, TextArea}

Expected outcome

I expected it to mention that Surface.Components.Form.TextArea is not alphabetically ordered, not Surface.Components.Form.

I wonder if this is easy or possible at all.

Actual outcome

  Code Readability
┃ 
┃ [R] ↘ The alias `Surface.Components.Form` is not alphabetically ordered among its group.
┃       lib/my_web/live/pages/my_page.ex:9:9 #(MyWeb.MyPage)

The alias Surface.Components.Form is not alphabetically ordered among its group. Which threw me there a little bit because of the double Surface.Components.Form declaration.

closed time in 9 days

lobo-tuerto

issue commentrrrene/credo

Actual module not alphabetically ordered not mentioned

This is part of v1.6.1 💚

lobo-tuerto

comment created time in 9 days

issue closedrrrene/credo

StrictModuleLayout check not included after enabling

Environment

  • Credo version (mix credo -v): 1.5.5-ref.master.06722e2+uncommittedchanges
  • Erlang/Elixir version (elixir -v): Elixir 1.11.3 (compiled with Erlang/OTP 23)
  • Operating system: macOS Catalina 10.15.7

What were you trying to do?

I wanted to enable the Credo.Check.Readability.StrictModuleLayout check for my project.

After doing so in .credo.exs as follows:

-170 {Credo.Check.Readability.StrictModuleLayout, false}, 
+170 {Credo.Check.Readability.StrictModuleLayout, []},

The check does not seem to be included when running mix credo.

Expected outcome

I expected to see "running 46 checks" instead of the default "running 45 checks" after enabling StrictModuleLayout in .credo.exs.

Actual outcome

Prerequisites:

$ mix new strict_module_layout
$ cd strict_module_layout
# Add `:credo` to `deps` in mix.exs...
$ mix deps.get

Running credo:

$ mix credo
Checking 3 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.1 seconds (0.07s to load, 0.03s running 45 checks on 3 files)
3 mods/funs, found no issues.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).
$ mix credo gen.config
* creating .credo.exs

Then after enabling StrictModuleLayout on line 170 in the generated .credo.exs file:

$ mix credo
Checking 3 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.1 seconds (0.07s to load, 0.04s running 45 checks on 3 files)
3 mods/funs, found no issues.

Af you can see, the number of checks remains the same.

After enabling Credo.Check.Readability.Specs (one of the other "controversial" checks listed), I do see different output:

$ mix credo
Checking 3 source files ...

  Code Readability                                                                                                      
┃ 
┃ [R] → Functions should have a @spec type specification.
┃       lib/strict_module_layout.ex:15:7 #(StrictModuleLayout.hello)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.1 seconds (0.07s to load, 0.06s running 46 checks on 3 files)
3 mods/funs, found 1 code readability issue.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).

Given these differences, I'm suspecting a bug somewhere in the StrictModuleLayout code and/or the flow for enabling checks.

closed time in 9 days

florish

issue commentrrrene/credo

StrictModuleLayout check not included after enabling

This is part of v1.6.1 💚

florish

comment created time in 9 days

issue closedrrrene/credo

Predicate function names check does not work for non-zero arity functions

Precheck

  • Proposals for new features should be submitted via: https://github.com/rrrene/credo-proposals
  • For bugs, please do a quick search and make sure the bug has not yet been reported here

Environment

  • Credo version (mix credo -v): 1.5.4
  • Erlang/Elixir version (elixir -v): Erlang 23, Elixir 1.11.3
  • Operating system: Mac OS

What were you trying to do?

  1. Have following function definition
defmodule A do
  defp is_user(cookie) do
    true
  end
end
  1. Credo has PredicateFunctionNames check enabled.
  2. Run credo

Expected outcome

Credo reports an issue with the function - it is a predicate function that starts with is_.

Actual outcome

Credo does not report any issues.

Extra information

The check works fine if I make the function 0-arity, for the following code an issue is reported:

defmodule A do
  defp is_user do
    true
  end
end

closed time in 9 days

laurglia
more