Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Diff output? #11

Open
trevorsummerssmith opened this issue Feb 18, 2016 · 1 comment
Open

Diff output? #11

trevorsummerssmith opened this issue Feb 18, 2016 · 1 comment

Comments

@trevorsummerssmith
Copy link

It would be great if ocamlint could be ran in a way that produced a unified diff, instead of a warning. Linting, in my opinion, is so useful because it is, by definition, things that don't require much thought eg trailing whitespace, an the things ocamllint is currently doing. If ocamlint could return a diff, then it can be used interactively which tools such as arcanist to either autocorrect problems, or interactively ask the user if they want the corrections.

I didn't look into the implementation, so I do not know how feasible this is. I did notice that you state the rules work on the abstract syntax tree. Is the original syntax still around?

Curious to hear your thoughts on the usefulness of this idea, as well as the difficulty in implementing.

Thanks!

@emillon
Copy link
Contributor

emillon commented Feb 19, 2016

Hey,

Glad you like it!

I agree that such a feature would be great. Hlint got something similar quite recently and I think it's improved the tool a lot.

I'm afraid that ppx modules are a bit too far in the chain, acting on the AST. Most of the elements have a location attached, which makes it possible to know some information, but not everything. For example you can't see tokens like begin/end at all (and they are parsed in the same way as (/).

It is possible to pretty-print an AST using functions like Pprintast.string_of_expression but it will just display the code without honoring the locations. ocp_indent does this job to fix the indentation, but I think it has its own parser. I think that merlin would be able to do this too, so we'd have to see if some interop is possible.

One first step in this direction (that would be required anyway to have a diff mode) is to start by adding a "suggestion" part to each rule, as it is not done at the moment.

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

No branches or pull requests

2 participants