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 configuration for modules to exclude for alias lifting #140

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

novaugust
Copy link
Contributor

@novaugust novaugust commented Mar 18, 2024

Closes #139

works like

[
  plugins: [Styler],
  styler: [alias_lifting_exclude: ~w(Plug Oban Phoenix Ecto GetText)a],
  line_length: 1_000_000,
]

todos

  • figure out if we actually need to support this or not by getting folks to try alias lifting :)
  • documentation ...
  • better/clearer option names?

Enum.reduce(aliases, @stdlib, fn
Enum.reduce(aliases, MapSet.union(@stdlib, excluded_by_config), fn
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would be worth pre-calculating this when Styler first initializes and putting it in persistent_term so that it only needs to be calculated once, since it won't vary over the course of a single formatter run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooooooo i was sad about calculating it every time, but hadn't thought to globally cache it via persistent_term! that's a beaut. could do that with the whole config so that you don't have to pass it down thru context, oo la la

@@ -179,6 +179,19 @@ defmodule Styler.Style.ModuleDirectives.AliasLiftingTest do
end

describe "it doesn't lift" do
test "collisions with configured modules" do
Styler.Config.set!(alias_lifting_exclude: ~w(C)a)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GregMefford lmk if you have an idea for clean config setting per test. i had it built into assert_style and honestly could still do that. maybe smart to just add a set_config in style_case that does the on_exit(fn -> set!([]) end)...

@novaugust
Copy link
Contributor Author

merging this as-is for now since main's pretty WIP anyways, especially re: documentation

@novaugust novaugust merged commit 19fbef0 into main Apr 5, 2024
4 checks passed
@novaugust novaugust deleted the me/config-excluded-lifts branch April 5, 2024 21:44
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.

alias lifting: add config for modules to exclude from conflicts
2 participants