Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Diff formatting #588

Closed
wants to merge 15 commits into from
Closed

[WIP] Diff formatting #588

wants to merge 15 commits into from

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented Nov 14, 2016

This PR introduces a new feature called "diff formatting". With scalafmt --diff, you only format the lines that are touched by a diff. Examples

# via stdin
$ git diff -U0 master | scalafmt --diff --stdin
... # writes to files
$ svn diff --diff-cmd=diff -x-U0 | scalafmt --diff --stdin # untested, but should work
# via configuration
$ cat .scalafmt.conf
project.git = true
project.baseBranch = master
$ scalafmt --diff
... # writes to file

Use cases:

  • Interactive IDE setting in a codebase that's not formatted with scalafmt. You could reformat a subsection you edited.
  • (hypothetical) gradually introduce scalafmt into a project, or allow a subset of developers to use scalafmt in a codebase (caveat below)
  • faster formatting (although nice, I wouldn't call it a selling feature unless for maybe huge source files).

Caveats:

  • in a partially formatted codebase, scalafmt may still introduce unnecessarily large diffs. Example
// line limit    |
-  class Foo extends A with B with C
+  class Foo extends A with B with C with D
// after formatting
class Foo
    extends A
    with B
    with C
    with D

A blank enforcement of diff formatting might therefore be unwanted.

Challenges:

  • need to guarantee that formatting a sequence of diffs will always produce the same output as formatting everything all the time.

Opening this PR to collect feedback. I would like to get this feature ready for 0.5.

TODOs:

  • handle indent for Case
  • handle indent for Term.Lambda
  • setup test that goes through git repo history and formats diff on every commit. Assert the output is identical to formatting the entire project on every commit.
  • select chains
  • large config style lists

@olafurpg olafurpg changed the title Diff formatting [WIP] Diff formatting Nov 14, 2016
@olafurpg
Copy link
Member Author

@olafurpg
Copy link
Member Author

0.5 made big progress on config argument lists, so this PR is somewhat closer to being ready. However, I'm a bit busy with other tasks at the moment so I'm gonna close this PR.

@olafurpg olafurpg closed this Jan 26, 2017
@olafurpg olafurpg deleted the diff-fmt branch March 12, 2017 19:25
@olafurpg olafurpg restored the diff-fmt branch March 12, 2017 19:25
@olafurpg olafurpg deleted the diff-fmt branch March 12, 2017 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant