Comments (8)
Which might also explain why the problem happens:
dbg
anddbg()
are parsed differently as evidenced by the following:
It doesn't because Credo does not use quote
, as Credo is not running your code.
Can you provide a piece of code where this happens?
from credo.
If you want a complete sample elixir-project with credo configuration, I will have to get back to you later tonight. But I think it should just be a matter of inserting something like :x |> dbg
anywhere in an existing project.
Here's a simple example from my utility module:
def headers_to_strings(headers) do
:x |> dbg()
Enum.map(headers, fn {key, value} -> "#{key}: #{value}" end)
end
Running credo I get the following (as expected):
$ mix credo
Checking 199 source files (this might take a while) ...
Warnings - please take a look
┃
┃ [W] ↗ There should be no calls to dbg.
┃ lib/leaf/util.ex:17:11 #(Leaf.Util.headers_to_strings)
Please report incorrect results: https://github.com/rrrene/credo/issues
Analysis took 2.3 seconds (0.1s to load, 2.1s running 68 checks on 199 files)
1149 mods/funs, found 1 warning.
If I remove the parenthesis, I get this instead:
def headers_to_strings(headers) do
:x |> dbg
Enum.map(headers, fn {key, value} -> "#{key}: #{value}" end)
end
$ mix credo
Checking 199 source files (this might take a while) ...
Please report incorrect results: https://github.com/rrrene/credo/issues
Analysis took 2.5 seconds (0.2s to load, 2.3s running 68 checks on 199 files)
1149 mods/funs, found no issues.
from credo.
@Munksgaard found it. Fix incoming 👍 Thx for reporting!
from credo.
This is part of 1.7.2-rc.3
👍
from credo.
Hi, try {Credo.Check.Warning.Dbg, []}
added inside checks: %{enabled: {Credo.Check.Warning.Dbg, []}}
in credo.exs, and also running mix credo --strict
@Munksgaard .
from credo.
Thank you @madclaws. I actually already have that setting in my .credo.exs
and am running strict, but I realize that that wasn't clear from my original issue description. I should also note that the warnings work great if I use |> dbg()
or dbg(something)
. It is specifically a problem when dbg
is called without parenthesis. Which might also explain why the problem happens: dbg
and dbg()
are parsed differently as evidenced by the following:
> quote do: :x |> dbg
{:|>, [context: Elixir, imports: [{2, Kernel}]],
[
:x,
{:dbg,
[
if_undefined: :apply,
context: Elixir,
imports: [{0, Kernel}, {1, Kernel}, {2, Kernel}]
], Elixir}
]}
> quote do: :x |> dbg()
{:|>, [context: Elixir, imports: [{2, Kernel}]],
[
:x,
{:dbg, [context: Elixir, imports: [{0, Kernel}, {1, Kernel}, {2, Kernel}]],
[]}
]}
Here is my config file for reference:
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: %{
enabled: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},
#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagFIXME, []},
#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, []},
#
## Refactoring Opportunities
#
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},
{Credo.Check.Refactor.FilterCount, []},
{Credo.Check.Refactor.FilterFilter, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},
#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.Dbg, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.SpecWithStruct, []},
{Credo.Check.Warning.WrongTestFileExtension, []},
{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.UnsafeExec, []}
],
disabled: [
#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
#
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
# and be sure to use `mix credo --strict` to see low priority checks)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Design.SkipTestWithoutComment, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.NestedFunctionCalls, []},
{Credo.Check.Readability.OneArityFunctionInPipe, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Readability.OnePipePerLine, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.FilterReject, []},
{Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PassAsyncInTestCases, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.UnsafeToAtom, []}
# {Credo.Check.Refactor.MapInto, []},
#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
}
]
}
from credo.
Great stuff @rrrene! Thanks for your work on Credo 🥇
from credo.
Amazing, thank you!
from credo.
Related Issues (20)
- Question: Is it possible to define a .credo.exs in a dependency with custom checks and apply it when running mix credo in a project HOT 3
- Predicate function names check does not work for non-zero arity functions HOT 2
- Add list of standard checks to docs HOT 2
- #FIXME fails silently HOT 6
- Credo wrongly reports about macro name HOT 2
- Credo.Check.Warning.MissedMetadataKeyInLoggerConfig reporting false errors since 1.7.2 upgrade HOT 8
- Elixir version check fails with Credo.Check.Warning.LazyLogging HOT 1
- Credo warning /test/add_credo_plugin_to_project.exs:121:6 HOT 2
- Code readability: Predicate function names should not start with 'is', and should end in a question mark. HOT 1
- Command line switch `--read-from-stdin` doesn't respect config files HOT 4
- Predicate callbacks from behavior are not ignored HOT 2
- Issue with Unused variables confused about the strategy HOT 1
- missing spec on unquoted function raise error HOT 3
- Credo.Check.Warning.WrongTestFileExtension displayed in non-test module in v1.7.4 HOT 8
- NoAmbiguousAliases fails on function param with name alias HOT 3
- "Most of the time you are using the multi-alias/require/import/use syntax..." with compile_env HOT 4
- Gracefully handle output of bitstring `:message` in `%Credo.Issue{}` HOT 8
- False positive: spec in quoted HOT 3
- False Positive: Macro sigils with uppercase words HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from credo.