Skip to content

Releases: smartrent/quokka

v2.4.1

12 Mar 04:17
9548a9e
Compare
Choose a tag to compare

What's Changed

  • Change default schema autosort order by @emkguts in #59

Full Changelog: v2.4.0...v2.4.1

v2.4.0

11 Mar 04:12
6296606
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.3.1...v2.4.0

v2.3.1

06 Mar 20:49
f42f372
Compare
Choose a tag to compare

What's Changed

  • fix: don't crash when variable matches directive by @emkguts in #54

Full Changelog: v2.3.0...v2.3.1

v2.3.0

06 Mar 16:34
3af3856
Compare
Choose a tag to compare

What's Changed

Improvements

Credo doesn't warn about alias lifting for behaviour, use, import directives (unless there are aliases inside opts). Therefore, to match credo:

  • Don't lift behaviour aliases at all.
  • Only lift use and import aliases if they were going to be lifted anyways (credo wouldn't yell either way, but it seems sensible to lift an alias if it's already lifted).

Full Changelog: v2.2.0...v2.3.0

v2.2.0

04 Mar 18:34
479e33b
Compare
Choose a tag to compare

What's Changed

  • feat: respect .formatter.exs line_length by @ilyabayel in #47
  • fix: don't sort use since it can cause bugs by @kybishop in #49

New Contributors

Full Changelog: v2.1.0...v2.2.0

v2.1.0

02 Mar 22:52
4f89eef
Compare
Choose a tag to compare

What's Changed

Improvements

New options

  • autosort: Sort all maps and/or defstructs in your codebase. Quokka will skip sorting maps that have comments inside them, though sorting can still be forced with # quokka:sort

  • piped_function_exclusions allows you to specify certain functions that won't be rewritten into a pipe. Particularly good for things like Ecto's subquery macro. Example:

# Before
subquery(
  base_query()
  |> select([:id, :name])
  |> where([_, id], id > 100)
  |> limit(1)
)

would normally be rewritten to:

  base_query()
  |> select([:id, :name])
  |> where([_, id], id > 100)
  |> limit(1)
  |> subquery()

but with the option set like this, it will not be rewritten:

# .formatter.exs
quokka: [
  piped_function_exclusions: [:"Ecto.Query.subquery"]
]

Deprecations

  • For elixir 1.18 and above, Quokka will rewrite %Foo{x | y} => %{x | y}
  • For elixir 1.17 and above, Quokka will replace :timer.units(x) with to_time(unit: x)

Fixes

  • Lift aliases that were already lifted
  • Lift aliases from inside module directives like use if the directive type comes after the alias.
  • with redundant body + non-arrow behind redundant clause

Full Changelog: v2.0.0...v2.1.0

v2.0.0

20 Feb 18:00
1843332
Compare
Choose a tag to compare

What's Changed

Quokka now supports filtering which rewrites to apply using the :only and :exclude configuration options. This allows teams to gradually adopt Quokka's rewrites by explicitly including or excluding specific ones.

Example configuration in .formatter.exs:

[
  # Only apply these specific rewrites
  only: [:pipes, :aliases, :line_length],
  
  # Or exclude specific rewrites
  exclude: [:sort_directives]
]

See the documentation for a complete list of available rewrite options.

Breaking Changes

  • Removed newline_fixes_only configuration option in favor of using only: [:line_length]
  • Removed reorder_configs configuration option in favor of using only: [:configs]
  • Removed rewrite_deprecations configuration option in favor of using only: [:deprecations]

v1.1.0

14 Feb 16:38
3bae4cc
Compare
Choose a tag to compare

Improvements

Line length formatting only

In order to phase this into large codebases, Quokka now supports formatting only the line length, the idea being that it is easier to review a diff where one commit is just compressing vertical code and the following is the substantive rewrites -- aka the rewrites that change the AST. In order to use this feature, use newline_fixes_only: true | false in the config.

# quokka:sort Quokka's first comment directive

Quokka will now keep a user-designated list or wordlist (~w sigil) sorted as part of formatting via the use of comments. Elements of the list are sorted by their string representation. It also works with maps, key-value pairs (sort by key), and defstruct, and even arbitrary ast nodes with a do end block.

The intention is to remove comments to humans, like # Please keep this list sorted!, in favor of comments to robots: # quokka:sort. Personally speaking, Quokka is much better at alphabetical-order than I ever will be.

To use the new directive, put it on the line before a list or wordlist.

This example:

# quokka:sort
[:c, :a, :b]

# quokka:sort
~w(a list of words)

# quokka:sort
@country_codes ~w(
  en_US
  po_PO
  fr_CA
  ja_JP
)

# quokka:sort
a_var =
  [
    Modules,
    In,
    A,
    List
  ]

  # quokka:sort
  my_macro "some arg" do
    another_macro :q
    another_macro :w
    another_macro :e
    another_macro :r
    another_macro :t
    another_macro :y
  end

Would yield:

# quokka:sort
[:a, :b, :c]

# quokka:sort
~w(a list of words)

# quokka:sort
@country_codes ~w(
  en_US
  fr_CA
  ja_JP
  po_PO
)

# quokka:sort
a_var =
  [
    A,
    In,
    List,
    Modules
  ]

# quokka:sort
my_macro "some arg" do
  another_macro :e
  another_macro :q
  another_macro :r
  another_macro :t
  another_macro :w
  another_macro :y
end

Other improvements

  • General improvements around conflict detection, lifting in more correct places and fewer incorrect places.

  • Use knowledge of existing aliases to shorten invocations.

    example:
    alias A.B.C

      A.B.C.foo()
      A.B.C.bar()
      A.B.C.baz()
    

    becomes:
    alias A.B.C

      C.foo()
      C.bar()
      C.baz()
    
  • Config Sorting: improve comment handling when only sorting a few nodes.

  • Pipes: pipe-ifies when first arg to a function is a pipe. reach out if this happens in unstylish places in your code.

  • Pipes: unpiping assignments will make the assignment one-line when possible

  • Deprecations: 1.18 deprecations

    • List.zip => Enum.zip
    • first..last = range => first..last//_ = range

Fixes

  • Support the credo config of the format checks: %{enabled: [...], disabled: [...]}, whereas previously it expected checks: [...]}
  • Pipes: optimizations are less likely to move comments
  • Don't pipify when the call is itself in a pipe (aka don't touch a |> b(c |> d() |>e()) |> f())

v1.0.0

12 Feb 00:20
7337c9e
Compare
Choose a tag to compare

Quokka is inspired by the wonderful elixir-styler ❤️

It maintains the same directive that consistent coding standards can help teams iterate quickly, but allows a few more affordances via .credo.exs configuration. This allows users with an already fine-tuned .credo.exs config to enjoy the automatic rewrites and strong opinions of Quokka

More details about specific Credo rewrites and their configurability can be found in Quokka: Credo inspired rewrites.

Adoption of opinionated code changes can be hard in larger code bases, so Quokka allows a few configuration options in .formatter.exs to help isolate big sets of potentially controversial or code breaking changes that may need time for adoption. However, these may be removed in a future release. See Quokka: Configuration for more details.