Commit Graph
237 Commits
Author SHA1 Message Date
Wojtek Mach e922211913 Use new ExDoc extras auto-links (#9912) 2020-03-27 00:05:48 +01:00
José Valim 48dc01829f Do not warn on nullary calls without parens 2020-03-12 13:11:11 +01:00
José Valim 9f50f7de7e Do not emit invalid code when formatting assocs in maps, closes #9771 2020-02-01 11:18:28 +01:00
Wojtek Mach 1303afef90 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 c3752ac4df Add :indentation to sigil heredoc meta (#9725) 2020-01-14 20:45:24 +01:00
Devon Estes fc0ef36880 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 e8378b83da Replace usage of "e.g." (#9571) 2019-11-22 11:26:23 +01:00
José Valim 08d6fe8cb8 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 2493ff907d Remove unused funtionality and erase pdict properly 2019-10-25 15:29:46 +02:00
José Valim 8c5c466a71 Add literal encoder option to Code.string_to_quoted 2019-06-19 00:04:08 +02:00
José Valim 0803049293 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 e7097d778a 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 3d6947bb39 Rename :end metadata to less ambiguous :closing 2019-06-16 00:01:48 +02:00
José Valim d9af62f7e5 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim 52578ff2ac Nest all terminator metadata under :end key 2019-05-09 10:28:18 +02:00
José Valim 64eb6af13a Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
José Valim f93d703979 Standardize more TODOs 2018-12-21 13:42:54 +01:00
Eksperimental 142bf57b7a Improvements to Operators guide (#8512) 2018-12-14 09:58:43 +01:00
José Valim 8dbf96711e Preserve user's choice on operators, closes #8417 2018-11-25 23:01:53 +01:00
Michał Muskała f1015ebef9 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 127e35edf1 Update TODO notes 2018-10-29 19:04:19 +01:00
Fernando Tapia Rico 61052e412f Use imported function in elixir_parser.yrl (#8151) 2018-08-29 14:19:50 +02:00
José Valim 0e0deadb6c Do not allow atoms inside maps 2018-08-09 10:33:15 +02:00
José Valim 58540dd79a Only compute eol if necessary 2018-06-10 17:53:40 +02:00
Sihui Huang 36f7867a23 When fn is followed by a newline, use multi-clause formatting style (#7737) 2018-06-10 17:45:02 +02:00
José Valim 216d6d6edf 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 96cc47bd61 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 5f07c6928b Clarify not in warnings 2018-01-19 11:28:18 +01:00
José Valim a71d57b476 Only rearrange not in if explicitly opted-in
Closes #7227.
2018-01-19 10:54:39 +01:00
José Valim 6283d3d775 Do not allow stabs mixed with expressions 2018-01-16 12:23:12 +01:00
José Valim d222b98971 Fix precedence of & in regards to =, closes #7188 2018-01-09 14:13:45 +01:00
Andrea Leopardi 56b81ffc4d Hard-deprecate some things for 1.7 (#7139) 2017-12-24 21:32:56 +01:00
José Valim b37e8a3637 Start v1.7 2017-12-23 19:40:30 +01:00
Eric Meadows-Jönsson 87bf050e2c Fix precedence of bitwise XOR (^^^) in formatter (#7036)
Closes #7034.
2017-11-15 19:53:20 +01:00
José Valim 9c95ee96b3 Consider comments inside function calls
Closes #6994
2017-11-07 10:50:11 +01:00
José Valim ef43b25f85 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 f0a74482da Respect the user's choice on calls
Closes #6977
2017-10-26 13:19:21 +02:00
José Valim 3fba28e0ee 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 703e3000a6 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 292a14466d Support columns: true in string_to_quoted, closes #3554 2017-10-25 11:02:53 +02:00
Andrea Leopardi b5211deec0 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 782a4a59c3 Formatter should not fail on empty clauses, closes #6924 2017-10-12 11:30:41 +02:00
José Valim a33cbcd32a Format errors_test.exs 2017-10-12 09:35:58 +02:00
José Valim 06bda15736 Do not add parens for var.field before do/end blocks 2017-10-10 16:13:10 +02:00
José Valim bf3fa2646a Do not apply next_break_fits if eol is present 2017-10-09 23:55:49 +02:00
José Valim 21e44bdb09 Keep the user's choice on non-module remote calls with no args 2017-10-09 22:43:08 +02:00
José Valim 541f56d950 When when and | also respect new lines 2017-10-09 17:13:39 +02:00
José Valim 8e5d31d875 Only keep locals_without_parens if they never had parens to start with 2017-10-09 15:57:57 +02:00
José Valim 5bd91a4cb3 Warn on trailing commas in calls 2017-10-09 10:43:10 +02:00
José Valim 3335c73847 Also preserve user newlines if trailing commas exist 2017-10-09 09:17:35 +02:00