Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nested function calls check #933

Merged
merged 6 commits into from
Jan 8, 2022
Merged

Add nested function calls check #933

merged 6 commits into from
Jan 8, 2022

Conversation

Stratus3D
Copy link
Contributor

This PR adds a check named Credo.Check.Readability.NestedFunctionCalls that checks for nested function calls that could be converted to pipelines. I created this check to catch violations of the rule about nested function calls specified in the Christopher Adam's style guide (https://github.com/christopheradams/elixir_style_guide#pipe-operator)

It tries to be smart enough to handle things like access protocol, string interpolation, and function calls with no arguments. See the tests for examples.

Context:

# Elixir >= 1.8.0
# '__#{val}__' are compiled to String.to_charlist("__#{val}__")
# we want to consider these charlists a valid pipe chain start
defp valid_chain_start?({{:., _, [List, :to_charlist]}, _, [[_ | _]]}), do: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if these two charlist clauses are needed or not. I copied them from Credo.Check.Refactor.PipeChainStart.

Copy link
Owner

Choose a reason for hiding this comment

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

This comment does irritate me a bit as it sounds like you made copy-pasta and are asking me if you did it correctly? Maybe I'm misunderstanding the question?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I did copy-and-paste this code from the Credo.Check.Refactor.PipeChainStart module. I have removed the unnecessary clauses from the function and added some additional tests to validate the remaining code is sufficient.

@Stratus3D
Copy link
Contributor Author

Reproducing Test-Case Detector (experimental) has failed and I am not sure why. Any suggestions?

@rrrene
Copy link
Owner

rrrene commented Jan 2, 2022

Reproducing Test-Case Detector (experimental) has failed and I am not sure why. Any suggestions?

It is a pipeline that does not matter for new checks 👍

@Stratus3D
Copy link
Contributor Author

I'm not sure why the Github workflows haven't run, but I have updated the PR and as far as I know everything is good to merge.

@rrrene rrrene merged commit 05fde3b into rrrene:master Jan 8, 2022
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.

2 participants