Commit Graph
241 Commits
Author SHA1 Message Date
José Valim 8b4ec95a99 Revert "Consistently handle empty blocks"
Actually, we don't allow `-> [EMPTY]` anywhere else.

This reverts commit 3c6891cb7d.
2020-06-25 12:32:07 +02:00
José Valim 3c6891cb7d Consistently handle empty blocks 2020-06-24 20:48:05 +02:00
José Valim 8770a61769 Handle ; inside empty parens, closes #9964 2020-04-26 11:42:20 +02:00
Ivan Rublev 29f29419a2 Add +++ and --- with right associativity to the list of custom operators (#9954) 2020-04-21 13:03:31 +02:00
Wojtek Mach 2701169b1e Use new ExDoc extras auto-links (#9912) 2020-03-27 00:05:48 +01:00
José Valim d375989b28 Do not warn on nullary calls without parens 2020-03-12 13:11:11 +01:00
José Valim 534d8eac6b Do not emit invalid code when formatting assocs in maps, closes #9771 2020-02-01 11:18:28 +01:00
Wojtek Mach 7287ae758a Fix bug: move :indentation from sigil meta to binary meta (#9738)
We need it there so we can retrieve it like this:

    defmacro sigil_E({:<<>>, meta, [expr]}, []) do
      options = [
        line: __CALLER__.line + 1,
        indentation: meta[:indentation] || 0
      ]

      EEx.compile_string(expr, options)
    end
2020-01-15 16:11:38 +01:00
Wojtek Mach 331df3587b Add :indentation to sigil heredoc meta (#9725) 2020-01-14 20:45:24 +01:00
Devon Estes ec65f8d48a Always capture delimiter metadata for sigils (#9671)
This makes it so we're always capturing delimiter metadata for sigils
instead of requiring the `token_metadata` option. This means that we can
now show the correct sigils in ExUnit diffs (and elsewhere) for code
examples.
2020-01-05 16:07:58 +01:00
Eksperimental 2121cbd086 Replace usage of "e.g." (#9571) 2019-11-22 11:26:23 +01:00
José Valim 8e7befb108 Add parens to static remote nullary calls
test/erlang/module_test.erl have also been removed
as they have been ported elsewhere.
2019-11-08 17:59:08 +01:00
José Valim 560e721b9b Remove unused funtionality and erase pdict properly 2019-10-25 15:29:46 +02:00
José Valim f38895cebb Add literal encoder option to Code.string_to_quoted 2019-06-19 00:04:08 +02:00
José Valim 776225f4e1 Add end of expression token information
This also renames pairing_metadata to token_metadata,
as it mostly contains information about related tokens
and not necessarily pairs.
2019-06-18 00:25:22 +02:00
José Valim faefb0b882 Exposing pairing metadata (#9146)
This introduces five new metadata nodes:

  * `do` - contains metadata about do location in a function call with
    `do/end` blocks
  * `end` - contains metadata about end location in a function call with
    `do/end` blocks
  * `closing` - contains metadata about the closing pair, such as a `}`
    in a tuple or in a map, or such as the closing `)` in a function call
    with parens
  * `eol` - is set to true when the opening pair, such as `{` or `(`, are
    followed by the end of the line
  * `delimiter` - contains the opening for sigils (such as `"{"`, `"/"`,
    etc)
2019-06-17 16:38:52 +02:00
José Valim e2c78e8ba9 Rename :end metadata to less ambiguous :closing 2019-06-16 00:01:48 +02:00
José Valim 0229358f88 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim 81e5a57d51 Nest all terminator metadata under :end key 2019-05-09 10:28:18 +02:00
José Valim 0ce62a2add Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
José Valim 0c1df34645 Standardize more TODOs 2018-12-21 13:42:54 +01:00
Eksperimental bd37919247 Improvements to Operators guide (#8512) 2018-12-14 09:58:43 +01:00
José Valim 741ff046b7 Preserve user's choice on operators, closes #8417 2018-11-25 23:01:53 +01:00
Michał Muskała e89e9d874b Compile charlist interpolation more efficiently
Today charlist interpolation is quivalent to calling `String.to_charlist`
on the equivalent string interpolation. It can be more efficient by
leveraging chardata support in the `:unicode` module and encoding as a
list of literal binaries and results of `Kernel.to_string` calls for the
interpolated segments.
2018-11-20 17:54:13 +01:00
José Valim 95bf439828 Update TODO notes 2018-10-29 19:04:19 +01:00
Fernando Tapia Rico b59d280a79 Use imported function in elixir_parser.yrl (#8151) 2018-08-29 14:19:50 +02:00
José Valim 5866b9da5c Do not allow atoms inside maps 2018-08-09 10:33:15 +02:00
José Valim 396e0bff9f Only compute eol if necessary 2018-06-10 17:53:40 +02:00
Sihui Huang 47f1107a7a When fn is followed by a newline, use multi-clause formatting style (#7737) 2018-06-10 17:45:02 +02:00
José Valim 5edb1d2739 Add hints on mismatched do/end and others pairs
When you are working on large files and you add new code,
you may forget to add a `do` or an `end`. In those cases,
the error message usually points to the first `do` or the
last `end` in the file, which are usually far away from
the source of the error.

This pull request adds a simple heuristic based on the
indentation of the tokens, to try to provide hints of
where the source may be. Those hints are not deterministic
but they may be able to point users to the source of the
problem.

For example, in this case:

    defmodule MyApp do
      def one do
      # end

      def two do
      end
    end

we know that we now that `def two do` is happening on the
same indentation as `def one do`, which may mean that
`def one do` was not closed properly. We store this as a
hint in case the terminators do not match later.

Similarly, in the case below:

    defmodule MyApp do
      def one
      end

      def two do
      end
    end

The `end` on line 3 will end-up closing the defmodule `do`,
on line 1. Because their indentation do not match, it may
be that there is a missing `do`, where the `end` was supposed
to align.

Some basic testing show those heuristics work on the majority
of the cases, but we will only be sure when we have enough
feedback from the community.
2018-06-10 13:55:49 +02:00
Glauber Campinho 54a29ddde0 Remove unnecessary catch from the parser (#7674)
The throws with this pattern are (caught by yecc)[https://github.com/erlang/otp/blob/master/lib/parsetools/include/yeccpre.hrl#L67]
and returned as an error. Also renamed throw to error to avoid confusions.
2018-05-12 10:27:05 +02:00
José Valim 97ff1ed89f Clarify not in warnings 2018-01-19 11:28:18 +01:00
José Valim bfa3cfba19 Only rearrange not in if explicitly opted-in
Closes #7227.
2018-01-19 10:54:39 +01:00
José Valim 4175ddebd9 Do not allow stabs mixed with expressions 2018-01-16 12:23:12 +01:00
José Valim 8ece3b9748 Fix precedence of & in regards to =, closes #7188 2018-01-09 14:13:45 +01:00
Andrea Leopardi 48e914dd3a Hard-deprecate some things for 1.7 (#7139) 2017-12-24 21:32:56 +01:00
José Valim 9e1485f29a Start v1.7 2017-12-23 19:40:30 +01:00
Eric Meadows-Jönsson 1303d09f61 Fix precedence of bitwise XOR (^^^) in formatter (#7036)
Closes #7034.
2017-11-15 19:53:20 +01:00
José Valim 5ea7321562 Consider comments inside function calls
Closes #6994
2017-11-07 10:50:11 +01:00
José Valim 794928efe1 Restrict next break fits and eols on operators and function calls
* Whitelist which operators support next_break_fits
  * No longer consider tuples as part of next_break_fits
  * Do not consider eol for = and ::
  * Do not consider eol for calls with one next_break_fits arg
2017-10-27 12:34:09 +02:00
José Valim 3d84aec0f9 Respect the user's choice on calls
Closes #6977
2017-10-26 13:19:21 +02:00
José Valim 7f8136915f Treat => and : as operators in the formatter
This means that the right side will break on its own line
when it doesn't fit and be indented by two spaces.

Closes #6976.
2017-10-26 12:43:02 +02:00
José Valim d3a85bfd21 Remove end column information from tokens
If we want to store this information, we need to store it
alongside the end line, otherwise it is ambiguous.
2017-10-25 11:56:31 +02:00
José Valim b87989e702 Support columns: true in string_to_quoted, closes #3554 2017-10-25 11:02:53 +02:00
Andrea Leopardi 169b8f5a77 Fix a bug where we discarded some meta in some literals in the parser (#6946)
Closes #6945.
2017-10-17 17:31:48 +02:00
José Valim 3d0dbb42d7 Formatter should not fail on empty clauses, closes #6924 2017-10-12 11:30:41 +02:00
José Valim 34651f1034 Format errors_test.exs 2017-10-12 09:35:58 +02:00
José Valim 1bef178c86 Do not add parens for var.field before do/end blocks 2017-10-10 16:13:10 +02:00
José Valim 9e5126256f Do not apply next_break_fits if eol is present 2017-10-09 23:55:49 +02:00
José Valim 52b405bbda Keep the user's choice on non-module remote calls with no args 2017-10-09 22:43:08 +02:00