Skip to content

Commit 02292c6

Browse files
committed
mix styler.remove_unused: allow multiple file args
1 parent 4e013e0 commit 02292c6

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ they can and will change without that change being reflected in Styler's semanti
55

66
## main
77

8+
### Improvements
9+
10+
- `mix styler.inline_attrs`: Allow multiple file paths to be specified: `mix styler.inline_attrs <file1> [... additional files]`
11+
812
## 1.10.1
913

1014
### Improvements

lib/mix/tasks/inline_attributes.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ defmodule Mix.Tasks.Styler.InlineAttrs do
1616
**This is known to create invalid code.** It's far from perfect.
1717
It can still be a helpful first step in refactoring though.
1818
19-
Formats the file with a currently hard-coded length of 122.
19+
Formats files with a currently hard-coded length of 122.
2020
2121
**Usage**:
2222
23-
mix styler.inline_attrs path/to/my/file.ex
23+
mix styler.inline_attrs <file_path> [... additional file paths]
24+
25+
mix styler.inline_attrs path/to/my/file.ex path/to/another_file.ex
2426
2527
## Example:
2628
@@ -44,9 +46,11 @@ defmodule Mix.Tasks.Styler.InlineAttrs do
4446
alias Styler.Zipper
4547

4648
@impl Mix.Task
47-
def run([file]) do
48-
{ast, comments} = file |> File.read!() |> Styler.string_to_ast(file)
49-
{{ast, _}, _} = ast |> Zipper.zip() |> Zipper.traverse_while(nil, &Styler.Style.InlineAttrs.run/2)
50-
File.write!(file, Styler.ast_to_string(ast, comments))
49+
def run(files) do
50+
for file <- files do
51+
{ast, comments} = file |> File.read!() |> Styler.string_to_ast(file)
52+
{{ast, _}, _} = ast |> Zipper.zip() |> Zipper.traverse_while(nil, &Styler.Style.InlineAttrs.run/2)
53+
File.write!(file, Styler.ast_to_string(ast, comments))
54+
end
5155
end
5256
end

lib/style/inline_attrs.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ defmodule Styler.Style.InlineAttrs do
5757
{:halt, zipper, ctx}
5858
end
5959
end
60+
6061
# Can't rely on `Macro.quoted_literal?` up front because we wrapped our literals :/
6162
# This function is not complete, but it's good enough for the needs here.
6263
defp quoted_literal?(value) when is_list(value) or is_map(value) do

0 commit comments

Comments
 (0)