Commit Graph
214 Commits
Author SHA1 Message Date
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
José Valim f7741f29b5 When when and | also respect new lines 2017-10-09 17:13:39 +02:00
José Valim f1776da4f1 Only keep locals_without_parens if they never had parens to start with 2017-10-09 15:57:57 +02:00
José Valim 8e25bdbb09 Warn on trailing commas in calls 2017-10-09 10:43:10 +02:00
José Valim 9b5af3303d Also preserve user newlines if trailing commas exist 2017-10-09 09:17:35 +02:00
José Valim 22c6311e9d More improvements to the formatter grammar, docs, and locals without bindings 2017-10-08 19:28:36 +02:00
José Valim 82e93512e9 Do not raise on clauses with newlines before and after -> 2017-10-07 10:13:53 +02:00
José Valim 748ae34f0e Add end_lines to do/end blocks and represent empty ones with empty blocks 2017-10-07 09:50:17 +02:00
José Valim 4387576126 Add more metadata to containers 2017-10-07 00:18:22 +02:00
José Valim df6a67dd88 Return empty block for empty parens instead of nil 2017-10-06 19:34:25 +02:00
José Valim eadcc92ff3 Do not match on empty block meta 2017-10-06 15:19:37 +02:00
José Valim ace11872f1 Add endline for functions and blocks 2017-10-06 15:01:23 +02:00
José Valim 2738594886 Add end_line to interpolation 2017-10-05 19:00:37 +02:00
José Valim e8d5c70baa Move & up in the operator table to avoid conflicts with | in cons, closes #6613 2017-09-28 18:32:52 +02:00
José Valim fe7efd6969 Only add eol marker with both begin-end in containers have eol 2017-09-12 14:42:15 +02:00
José Valim 93f79543ae Do not use __block__ and __aliases__ as literal identifiers 2017-09-01 01:45:08 +02:00
José Valim a8bafae468 Store eol info in arrow ops 2017-09-01 00:58:15 +02:00
José Valim 58b498c90f Store if containers and stab are followed by eol 2017-09-01 00:35:14 +02:00
José Valim 2d1e00264e Push blocks to parser 2017-08-31 15:58:03 +02:00
José Valim 97ece16b11 Add more formatter metadata 2017-08-30 17:21:17 +02:00
José Valim 6030be5ae5 Add literal annotation for aliases 2017-08-28 23:59:45 +02:00
José Valim 4fdeba67f6 Add parser rule for call with unary and do-end block 2017-08-28 23:15:45 +02:00
José Valim 89752e724c Also wrap keyword literals in blocks 2017-08-28 22:27:43 +02:00
José Valim a378154652 Make terminator binaries 2017-08-27 12:39:40 +02:00
José Valim dcb76f8882 Do not translate empty files to nil 2017-08-25 14:56:15 +02:00
Andrea Leopardi 82dfe6f56e Add :format metadata to strings and charlist literals (#6505) 2017-08-25 01:33:02 +02:00
José Valim 8914d2c5f0 unquote_splicing has arity of 1 2017-08-24 13:55:35 +02:00
Andrea Leopardi 4cfce073c1 Keep the representation of "float" tokens like we do for "int" tokens (#6501) 2017-08-23 12:57:10 +02:00