Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Ability to not overwrite source file when using --fix #2125

Closed
ianks opened this issue Jan 26, 2017 · 7 comments
Closed

Ability to not overwrite source file when using --fix #2125

ianks opened this issue Jan 26, 2017 · 7 comments

Comments

@ianks
Copy link

ianks commented Jan 26, 2017

Currently, running --fix replaces the file in place. In certain cases, this causes problem with integrating with other editors, etc. For example, https://github.com/sbdchd/neoformat likes to have a copy of the changed file so it can perform diffs on the current buffer. Would you consider adding an option which allow --fix to emit the changes to stdout optionally?

@nchen63
Copy link
Contributor

nchen63 commented Jan 26, 2017

I'm not sure if this would belong in the this repo, but it would be pretty simple to write a custom formatter to write out the fixes in whatever format you want. The text replacements are available in the API even if --fix isn't used.

See https://palantir.github.io/tslint/develop/custom-formatters/

Each RuleFailure contains fix.innerReplacements which contains the offset and replacement texts. You just have to take that data and output a string in whatever format works for you.

@ianks
Copy link
Author

ianks commented Jan 26, 2017

@nchen63 how would this solve the problem of files being overwritten in place?

@nchen63
Copy link
Contributor

nchen63 commented Jan 26, 2017

don't call with --fix so nothing is overwritten
formatter outputs fix info

@ianks
Copy link
Author

ianks commented Jan 26, 2017

Thanks for the info @nchen63!

I created an MVP here: https://github.com/ianks/tslint-fix-formatter

It might be nice to include this in core, since I imagine it would be useful to many users (VIM users, at least). I will leave that up to the team though.

Cheers!

@adidahiya
Copy link
Contributor

@ianks sure, we'd accept a PR for a fix formatter.

@ianks
Copy link
Author

ianks commented Jan 29, 2017

Continuing off of #2149. Making a copy of the file in a temp for is actually what neoformat attempts to do, however the imports , etc are broken at that point. Overall, that mechanism is a bit too error-prone and complicated to use in most cases.

@JoshuaKGoldberg
Copy link
Contributor

Seems like this is a subset of #1760. Closing for housekeeping, but if I've misinterpreted and this is actually a separate issue, please do comment here!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants