Repository navigation
Update dependency styler to v1 - #24
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
~> 0.11→~> 1.0Release Notes
adobe/elixir-styler (styler)
v1.12.2Compare Source
Fixes
|> DateTime.add(val, :microsecond)(#256, h/t @zvlasic)v1.12.1Compare Source
Fixes
DateTime.add(dt, val, :microsecond)untouched sinceDateTime.shiftwith microseconds requires a precision (#255, h/t @janpieper)v1.12.0Compare Source
Improvements
|> dbg, to help our friends who format-on-save and like throwing a quick dbg pipe in while debugging (h/t @mhanberg)DateTime.shift |> DateTime.shiftinto a singleDateTime.shiftwhen working with literal durations whose keys are disjointnot (a == b),!(a == b)=>a != b(#251, h/t @tomkonidas)DateTime.add(dt, amount, unit)is rewritten toDateTime.shift(dt, unit: amount)for 1.17+ codebases. While not technically deprecated, Elixir docs recommendshiftoveradd(#253, h/t @tomkonidas)DateTime.shift(dt, ..duration pairs..)now has its duration pairs shrunk liketo_timeoutsecond: 86_400=>day: 1Fixes
Map/Keyword.merge([single: :key])=>Map/Keyword.put(:single, :key)v1.11.0Compare Source
Improvements
mix styler.inline_attrs: Allow multiple file paths to be specified:mix styler.inline_attrs <file1> [<file2> ...]Module Directive References
Module directives got smarter. Styler will no longer move module attributes below their references in
useor@moduledocs.In other words, Styler will leave the following code untouched:
v1.10.1Compare Source
Improvements
Adds two experimental refactoring features as mix tasks.
mix styler.remove_unusedWith Elixir 1.20 on the horizon, many projects are about to discover that they have a lot of unnecessary
require Loggerlines throughout their codebase.mix styler.remove_unusedwill automate the removal of thoseunused require:statements, alongside anyunused import:andunused alias:warnings.This has long been an internal script useful for running after a bigger refactor that resulted in many superfluous aliases, but with 1.20 coming it seems it might be useful for others as well.
This will never be an integrated part of
Styler's format plugin features, as it would not be correct to remove unused nodes whenever running format. It's typical to have unused warnings while in the midst of an implementation, and deleting that code would be obnoxious.mix styler.inline_attrs <file>Inlines one-off module attributes that define literal values.
This is something that sometimes is good, and sometimes is bad. In general, defining a module attribute when you could've just written an atom is bad, so inlining is good!
It would probably be most useful as a refactor ability for a language server, but CLIs are a nice second place.
An example of a situation where it results in an improvement:
It's worthwhile to run this on some suspicious files, then followup with manual intervention when it went too far. This style is not aware of quote boundaries, and so might do some broken things. (Hence "EXPERIMENTAL")
You've been warned =)
v1.10.0Compare Source
Improvements
Two new standard-library pipe optimizations
enum |> Enum.map(fun) |> Enum.intersperse(separator)=>Enum.map_intersperse(enum, separator, fun)enum |> Enum.sort() |> Enum.reverse()=>Enum.sort(enum, :desc)And Req (the http client library) pipe optimizations, as detailed below
Req pipe optimizations
Req is a popular HTTP Client. If you aren't using it, you can just ignore this whole section!
Reqs 1-arity "execute the request" functions (
delete get head patch post put request run) have a 2-arity version that takes a superset of the argumentsReq.new/1does as its first argument, and the typicaloptionskeyword list as its second argument. And so, many places developers are calling a 1-arity function can be replaced with a 2-arity function.More succinctly, these two statements are equivalent:
foo |> Req.new() |> Req.merge(bar) |> Req.post!()Req.post!(foo, bar)Styler now rewrites the former to the latter, since "less is more" or "code is a liability".
It also rewrites
|> Keyword.merge(bar) |> Req.foo()to|> Req.foo(bar). This changes the program's behaviour, sinceKeyword.mergewould overwrite existing values in all cases, whereasReq2-arity functions intelligently deep-merge values for some keys, like:headers.v1.9.1Compare Source
Fix
v1.9.0Compare Source
This was a weird one, but I found myself often writing
to_timeoutwith plural units and then having to go back and fixthe code to be singular units instead. Polling a few colleagues, it seemed I wasn't alone in that mistake. So for the first time,
Styler will correct code that would otherwise produce a runtime error, saving you from flow-breaking backtracking.
Improvements
to_timeoutimprovements:to_timeout(hours: 2)->to_timeout(hour: 2)(plurals are valid ast, but invalid arguments to this function)to_timeout(hours: 24 * 1, seconds: 60 * 4)->to_timeout(day: 1, minute: 4). this can introduce runtime bugs due to duplicate keys, as in the following scenario:to_timeout(minute: 60, hours: 3)->to_timeout(hour: 1, hour: 3)v1.8.0Compare Source
Improvements
Rewrite single-clause case statements to be assignments (h/t 🤖)
v1.7.0Compare Source
Surprising how fast numbers go up when you're following semver.
Two new features, one being a pipe optimization and the other a style-consistency-enforcer in
condstatements.Improvements
|> Enum.filter(fun) |> List.first([default])=>|> Enum.find([default], fun)(#242, h/t @janpieper)condIf the last clause's left-hand-side is a truthy atom, map literal, or tuple, rewrite it to be
trueThis also helps Styler identify 2-clause conds that can be rewritten to
if/elsemore readily, like the following:v1.6.0Compare Source
That's right, a feature release again so soon!
Improvements
This version of Styler adds many readability improvements around ExUnit
assertandrefute, specifically when working with 1. negations or 2. someEnumstdlib functions.Some of these rewrites are not semantically equivalent due to
refutepassing for bothnilandfalse.ExUnit assert/refute rewrites
Styler now inverts negated (
!, not) assert/refute (egassert !x=>refute x) statements, and further invertsrefutewith boolean comparison operators (refute x < y=>assert x >= y) because non-trivial refutes are harder to reason about [ citation needed ]. Asserting something is not nil is the same as just asserting that something, so that's gone too now.These changes are best summarized by the following table:
assert !xrefute xassert not xrefute xassert !!xassert xassert x != nilassert xassert x == nilassert is_nil(x)assert !is_nil(x)assert xassert x not in yrefute x in yrefute xrefute !xassert xrefute not xassert xrefute x != yassert x == yrefute x !== yassert x === yrefute x != nilassert x == nilrefute x not in yassert x in yrefute x < yassert x >= yrefute x <= yassert x > yrefute x > yassert x <= yrefute x >= yassert x < yassert Enum.member?(y, x)->assert x in yassert Enum.find(x, y)->assert Enum.any?(x, y)(nb. not semantically equivalent in theory, but equivalent in practice)assert Enum.any?(y, & &1 == x)->assert x in yassert Enum.any?(y, fn var -> var == x end)->assert x in yFixes
v1.5.1Compare Source
Fixes
v1.5.0Compare Source
Improvements
:minimum_supported_elixir_versionconfiguration to better support libraries using Styler (#231, h/t @maennchen)# styler:sortwill now sort keys for struct/map typespecs (#213, h/t @rojnwa)Fixes
v1.4.2Compare Source
Fixes
# styler:sort(#230, h/t @cschmatzler)v1.4.1Compare Source
Improvements
to_timeout/1rewrites to use the next largest unit in some simple instancesFixes
v1.4.0Compare Source
Read on for details.
Improvements
Alias Lifting
This release taught Styler to try just that little bit harder when doing alias lifting.
general improvements around conflict detection, lifting in more correct places and fewer incorrect places (#193, h/t @jsw800)
use knowledge of existing aliases to shorten invocations (#201, h/t me)
example:
becomes:
Struct Updates => Map Updates
1.19 deprecates struct update syntax in favor of map update syntax.
WARNING Double check your diffs to make sure your variable is pattern matching against the same struct if you want to harness 1.19's type checking features. Apologies to folks who hoped Styler would do this step for you <3 (#199, h/t @SteffenDE)
Ex1.17+
:timer.units(x)with the newto_timeout(unit: x)forhours|minutes|seconds(This style is only applied if you're on 1.17+)Fixes
pipes: handle pipifying when the first arg is itself a pipe:c(a |> b, d)=>a |> b() |> c(d)(#214, h/t @kybishop)pipes: handle pipifying nested functionsd(c(a |> b))=>a |> b |> c() |> d(#216, h/t @emkguts)with: fix a stabbywith, else: (_ -> :ok)being rewritten to a case (#219, h/t @iamhassangm)v1.3.3Compare Source
Improvements
with do: bodyand variations with no arrows in the head will be rewritten to justbody# styler:sortwill sort arbitrary ast nodes within ado endblock:Given:
styler:sort
styler:sort
Fixes
# styler:sortdirectives are added to a file at the same timev1.3.2Compare Source
Improvements
# styler:sortcan be used to sort values of key-value pairs. eg, sort the value of a single key in a map (Closes #208, h/t @ypconstante)v1.3.1Compare Source
Improvements
# styler:sortnow works with maps and thedefstructmacroFixes
# styler:sortno longer blows up on keyword lists :Xv1.3.0Compare Source
Improvements
# styler:sortStyler's first comment directiveStyler will now keep a user-designated list or wordlist (
~wsigil) sorted as part of formatting via the use of comments. Elements of the list are sorted by their string representation.The intention is to remove comments to humans, like
# Please keep this list sorted!, in favor of comments to robots:# styler:sort. Personally speaking, Styler 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:
Would yield:
v1.2.1Compare Source
Fixes
|>don't pipify when the call is itself in a pipe (aka don't toucha |> b(c |> d() |>e()) |> f()) (Closes #204, h/t @paulswartz)v1.2.0Compare Source
Improvements
pipes: pipe-ifies when first arg to a function is a pipe. reach out if this happens in unstylish places in your code (Closes #133)pipes: unpiping assignments will make the assignment one-line when possible (Closes #181)deprecations: 1.18 deprecationsList.zip=>Enum.zipfirst..last = range=>first..last//_ = rangeFixes
pipes: optimizations are less likely to move comments (Closes #176)v1.1.2Compare Source
Improvements
v1.1.1Compare Source
Improvements
unless: rewriteunless a |> b |> casunless !(a |> b() |> c())rather thanunless a |> b() |> c() |> Kernel.!()(h/t @gregmefford)v1.1.0Compare Source
Improvements
The big change here is the rewrite/removal of
unlessdue to unless "eventually" being deprecated. Thanks to @janpieper and @ypconstante for bringing this up in #190.unless: rewrite allunlesstoif(#190)pipes: optimize|> Stream.{each|map}(fun) |> Stream.run()to|> Enum.each(fun)Fixes
pipes: optimizations reducing 2 pipes to 1 no longer squeeze all pipes onto one line (#180)if: fix infinite loop rewriting negated if with empty do bodyif x != y, do: (), else: :ok(#196, h/t @itamm15)v1.0.0Compare Source
Styler's two biggest outstanding bugs have been fixed, both related to compilation breaking during module directive organization. One was references to aliases being moved above where the aliases were declared, and the other was similarly module directives being moved after their uses in module directives.
In both cases, Styler is now smart enough to auto-apply the fixes we recommended in the old Readme.
Other than that, a slew of powerful new features have been added, the neatest one (in the author's opinion anyways) being Alias Lifting.
Thanks to everyone who reported bugs that contributed to all the fixes released in 1.0.0 as well.
Improvements
Alias Lifting
Along the lines of
Credo.Check.Design.AliasUsage, Styler now "lifts" deeply nested aliases (depth >= 3, alaA.B.C....) that are used more than once.Put plainly, this code:
will become
To exclude modules ending in
.Foofrom being lifted, addstyler: [alias_lifting_exclude: [Foo]]to your.formatter.exsModule Attribute Lifting
A long outstanding breakage of a first pass with Styler was breaking directives that relied on module attributes which Styler moved after their uses. Styler now detects these potential breakages and automatically applies our suggested fix, which is creating a variable before the module. This usually happened when folks were using a library that autogenerated their moduledocs for them.
In code, this module:
Will now be styled like so:
Mix Config File Organization
Styler now organizes
Mix.Config.config/2,3stanzas according to erlang term sorting. This helps manage large configuration files, removing the "where should I put this" burden from developers AND helping find duplicated configuration stanzas.See the moduledoc for
Styler.Style.Configsfor more.Pipe Optimizations
Enum.into(x, [])=>Enum.to_list(x)Enum.into(x, [], mapper)=>Enum.map(x, mapper)a |> Enum.map(m) |> Enum.join()tomap_join(a, m). we already did this forjoin/2, but missed the case forjoin/1lhs |> Enum.reverse() |> Kernel.++(enum)=>lhs |> Enum.reverse(enum)withstyleswithstructure with no left arrows in its head to be normal code (#174)with true <- x(), do: y=>if x(), do: y(#173)Everything Else
if/unless: invert if and unless with!=or!==, like we do for!andnot#132@derive: move@derivebeforedefstruct|schema|embedded_schemadeclarations (fixes compiler warning!) #134~swhen there's 4+ escaped double-quotes(
"\"\"\"\""->~s("""")) (Credo.Check.Readability.StringSigils) #146Map.drop(foo, [single_key])=>Map.delete(foo, single_key)#161 (also in pipes)Keyword.drop(foo, [single_key])=>Keyword.delete(foo, single_key)#161 (also in pipes)Fixes
def function_head_with_no_body_nor_parens(#185, h/t @ypconstante)witharrow replacement + redundant body removal creating invalid statements (#184, h/t @JesseHerrick)!andnotas valid pipe starts (#183, h/t @nherzing)Map.drop(x, [a | b])registering as a chance to refactor toMap.deletealias: expands aliases when moving an alias after another directive that relied on it (#137)Timex.now/1will no longer be rewritten toDateTime.now!/1due to Timex accepting a wider domain of "timezones" than the stdlib (#145, h/t @ivymarkwell)with: skip nodes which (unexpectedly) do not contain adobody (#158, h/t @DavidB59)then(&fun/1): fix false positives on arithmetic&1 + x / 1(#164, h/t @aenglisc)Breaking Changes
1.14before_compile after_compile after_verify) with nondirectives (previously, were grouped withuse, their relative order maintained). to keep the desired behaviour, you can make newusemacros that wrap these callbacks. Apologies if this makes using Styler untenable for your codebase, but it's probably not a good tool for macro-heavy libraries.Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.