Skip to content

Conversation

@kelvinst
Copy link
Contributor

@kelvinst kelvinst commented Aug 6, 2022

Closes rrrene/credo-proposals#81

This PR is introducing a new :ignore param on Credo.Check.Readability.AliasAs,
to allow users to configure a list of modules that should be ignored by
this check.

For example: with {Credo.Check.Readability.AliasAs, ignore: [Test]} on the config, the check would not warn for alias Test, as: T anywhere.

Introducing a new `:ignore` param on `Credo.Check.Readability.AliasAs`,
to allow users to configure a list of modules that should be ignored by
this check. For example, with `{Credo.Check.Readability.AliasAs,
ignore: [Test]}` on the config, the check would not warn for `alias
Test, as: T` anywhere.
Copy link
Owner

@rrrene rrrene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for putting this together! Please find my comments attached 👍

do: issue_for(issue_meta, meta[:line], inspect(:__MODULE__))
defp issue({:alias, _, [{:__MODULE__, _, nil}, [as: {_, meta, _}]]}, issue_meta, ignore) do
line = meta[:line]
{Credo.IssueMeta, source_file, _check_params} = issue_meta
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the functions in Credo.IssueMeta to deal with IssueMeta.

defp issue({:alias, _, [{:__MODULE__, _, nil}, [as: {_, meta, _}]]}, issue_meta, ignore) do
line = meta[:line]
{Credo.IssueMeta, source_file, _check_params} = issue_meta
{_def, module_name} = Check.scope_for(source_file, line: line)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems expensive to get the scope for each occurrence instead of passing the module name during traversal.

line = meta[:line]
{Credo.IssueMeta, source_file, _check_params} = issue_meta
{_def, module_name} = Check.scope_for(source_file, line: line)
module = Module.concat([module_name])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use Credo.Code.Name.full/1 instead of Module.concat/1.

{_def, module_name} = Check.scope_for(source_file, line: line)
module = Module.concat([module_name])

if :__MODULE__ not in ignore and module not in ignore do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If :__MODULE__ is in ignore than we could have saved a lot of time calculating module.

defp issue({:alias, _, [{_, _, original}, [as: {_, meta, _}]]}, issue_meta),
do: issue_for(issue_meta, meta[:line], inspect(Module.concat(original)))
defp issue({:alias, _, [{_, _, original}, [as: {_, meta, _}]]}, issue_meta, ignore) do
module = Module.concat(original)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use Credo.Code.Name.full/1 instead of Module.concat/1.

@kelvinst
Copy link
Contributor Author

kelvinst commented Sep 2, 2022

Thanks for the thorough review @rrrene. Will work on your suggestions soon!

@rrrene
Copy link
Owner

rrrene commented Dec 17, 2023

Checking in: Any developments?

@rrrene
Copy link
Owner

rrrene commented Jan 30, 2024

Checking in: Any news?

@kelvinst
Copy link
Contributor Author

Sorry for the delay. I finally am getting back on tracks after a huge hiatus in contributions. I'm focusing on this first, so I'll get back to you soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Config: ignore specific modules on Credo.Check.Readability.AliasAs

2 participants