credo icon indicating copy to clipboard operation
credo copied to clipboard

Adding file exclusions to a single check causes a hang

Open tomtaylor opened this issue 9 months ago • 4 comments

I'm rolling out a custom check slowly and have 68 files to exclude from it initially.

The check works fine without exclusions:

> mix credo suggest -C ci
Checking 1595 source files (this might take a while) ...

[snip]

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

Analysis took 0.9 seconds (0.4s to load, 0.5s running 35 checks on 1595 files)
12514 mods/funs, found 250 warnings.

Use `mix credo explain` to explain issues, `mix credo --help` for options.

But when I add the 68 file exclusions to my custom check it seems to become unresponsive and I have to kill BEAM:

%{
  configs: [
    %{
      name: "ci",
      files: %{
        included: [
          "lib/",
          "test/"
        ]
      },
      requires: ["lib/checks/"],
      strict: true,
      parse_timeout: 5000,
      color: false,
      checks: [
        {Credo.Check.Design.TagFIXME, []},
        {Credo.Check.Readability.AliasOrder, []},
        {Credo.Check.Readability.FunctionNames, []},
        {Credo.Check.Readability.ModuleAttributeNames, []},
        {Credo.Check.Readability.MultiAlias, []},
        {Credo.Check.Readability.RedundantBlankLines, []},
        {Credo.Check.Readability.Semicolons, []},
        {Credo.Check.Readability.SeparateAliasRequire, []},
        {Credo.Check.Readability.VariableNames, []},
        {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
        {Credo.Check.Warning.BoolOperationOnSameValues, []},
        {Credo.Check.Warning.Dbg, []},
        {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
        {Credo.Check.Warning.ForbiddenModule, []},
        {Credo.Check.Warning.IExPry, []},
        {Credo.Check.Warning.IoInspect, []},
        {Credo.Check.Warning.LeakyEnvironment, []},
        {Credo.Check.Warning.MapGetUnsafePass, []},
        {Credo.Check.Warning.MixEnv, []},
        {Credo.Check.Warning.OperationOnSameValues, []},
        {Credo.Check.Warning.OperationWithConstantResult, []},
        {Credo.Check.Warning.RaiseInsideRescue, []},
        {Credo.Check.Warning.SpecWithStruct, []},
        {Credo.Check.Warning.UnsafeExec, []},
        {Credo.Check.Warning.UnsafeToAtom, []},
        {Credo.Check.Warning.UnusedEnumOperation, []},
        {Credo.Check.Warning.UnusedFileOperation, []},
        {Credo.Check.Warning.UnusedKeywordOperation, []},
        {Credo.Check.Warning.UnusedListOperation, []},
        {Credo.Check.Warning.UnusedPathOperation, []},
        {Credo.Check.Warning.UnusedRegexOperation, []},
        {Credo.Check.Warning.UnusedStringOperation, []},
        {Credo.Check.Warning.UnusedTupleOperation, []},
        {Credo.Check.Warning.WrongTestFileExtension, []},
        {Checks.ExampleCheck,
         files: %{
           excluded: [
             "lib/foo.ex", ...
           ]
         }}
      ]
    }
  ]
}

If I set excluded to an empty list it works fine again.

tomtaylor avatar May 29 '25 10:05 tomtaylor

Thx for reporting 👍 This sounds super strange. How many files are there? Meaning 68 out of how many are excluded?

rrrene avatar May 29 '25 12:05 rrrene

Hey @rrrene - there's 1595 files.

tomtaylor avatar May 29 '25 12:05 tomtaylor

I've narrowed this down a bit - it works if I pass in an explicit included option, e.g. included: ["lib/example/foo/**/.*.ex"]. If excluded is provided, but not included, it seems to fall back to the default glob

https://github.com/rrrene/credo/blob/f731459d4fb5c3359303e99fde9fa1e51d6fbea9/lib/credo/sources.ex#L116-L117

The default is **/*.{ex,exs}. When this is passed into Path.wildcard...

https://github.com/rrrene/credo/blob/f731459d4fb5c3359303e99fde9fa1e51d6fbea9/lib/credo/sources.ex#L187-L205

...it looks like it's hanging, but it's probably just enumerating a lot of files, because we have a few million non-Elixir files in this directory.

I think I'd expect the default to be the inclusions for the whole project.

tomtaylor avatar May 30 '25 13:05 tomtaylor

@tomtaylor This may have been solved by #1232.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! 👍

rrrene avatar Dec 04 '25 19:12 rrrene