Skip to content

Conversation

chrismwendt
Copy link
Contributor

This is a pretty hacky way to keep the trailing newline to avoid undo/redo jankiness, but it's probably a good stopgap. If I understand correctly, the refact library loses this information during refactoring (see mpickering/apply-refact#14).

@mpickering
Copy link
Owner

I didn't think the plugin stripped trailing newlines. It doesn't, at least in my tests.

@chrismwendt
Copy link
Contributor Author

I was mistaken - apply-refact doesn't strip trailing newlines, as seen by this example:

$ printf "module A where\n" > newline.hs
$ cat newline.hs | hlint - "--refactor-options=--pos 1,1" --refactor 
module A where
$ 

I believe the problem is this join("\n"):

text: lines.join '\n'

@mpickering
Copy link
Owner

OK, could you suggest how to fix it there rather than the hack added later? If you don't think there's a way then I will just merge this.

@chrismwendt
Copy link
Contributor Author

I reverted the hacky solution and committed a proper fix, which does not strip the last character of each chunk of data (resulting in the trailing newline being stripped after calling join).

On a related note, hlint actually adds a trailing newline if it doesn't exist.

$ printf "module A where" > no-newline.hs
$ cat no-newline.hs | wc
      0       3      14
$ cat no-newline.hs | hlint - "--refactor-options=--pos 1,1" --refactor | wc
      1       3      15

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.

2 participants