-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add odoc lint command for mli and mld validation #226
Conversation
- Implement the `odoc lint FILE.{ml,mld}` command. - Remove unused `id` argument from `Loader.Attrs.read_attributes`. - Expose `Attrs` module in `Loader` interface. - Add `Compat.Filename.remove_extension`.
As expected there are some failures with the 4.02 compiler in the CI. Specifically:
What is not expected is the fact that only the 327.8 build job (the esy configuration) is reported as failed while 327.1 and 327.2 actually failed too (both use the 4.02 compiler). Other jobs don't seem to have any issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good technically.
It seems that the main differences between this and odoc compile
is that odoc lint
reads .mli
files, while odoc compile
reads .cmti
(etc.) files (both read .mld
files, but that is not an issue in this point).
This is simpler for the user, but will it be problematic in case of
cppo
being used, for example?Sticking with
odoc compile
and Dune (and bsb?), don't we get, for free, a nice way to lint whole projects?Note that
odoc lint foo.mli
and
ocamlfind opt -bin-annot -c foo.mli odoc compile --package foo foo.cmti
produce identical output in terms of errors displayed. The difference, of course, is that the second set of commands produce intermediate files.
Given that, my suggestion would be to use existing commands instead of adding odoc lint
, and hide it all behind Dune and/or bsb.
odoc compile
's error handling needs improvement. I wrote some text about that but decided to leave it out of this comment, perhaps that is a separate discussion. Even with the current error handling, though, the output is the same.
Some other notes:
-
Some old versions of the compiler don't seem to produce the
[@@ocaml.doc]
attribute on polymorphic variants (the CI should report all the culprits). I don't have a workaround for this.IIRC 4.02 is very broken. At least ocamldoc would lose free text in the middle of a
.mli
file. I don't know if doc attributes were affected. I suggest to add an unassociated doc comment to the test cases. The one that is there now is at the top of the module, but I suggest to add one in the middle. -
The column number reported in errors seems to be slightly shifted (I'll investigate this soon).
Update: seems like it is already present in
master
. The location of the attributes is off by -3, I assume it's because it's not counting(**
.Indeed. IIRC it's the responsibility of the calling code to pass an adjusted "base" location into the parser (
~location
argument). Looking at the code inattrs.ml
right now, we might not be adjusting it correctly even duringodoc compile
.As a little note, we can't unconditionally add 3 because
.mld
files don't have(**
.
(targets parser_errors.output) | ||
(action (with-stderr-to parser_errors.output | ||
(run %{workspace_root}/src/odoc/bin/main.exe lint %{input})))) | ||
(alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This alias should be called from the Makefile
. We are triggering the @runtest
aliases manually there, IIRC to control the execution order.
Actually, it occurs to me that we might be able to express the order using dependencies in the dune
files.
@@ -0,0 +1,19 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only real nit at this point is that I think this should be in test/lint
, not test/parser/lint
.
I'm not exactly sure what this is trying to achieve. One of the improvement with Working again directly on |
The
These are both good points, but |
For reference I assume this is an example of what you were talking about, @dbuenzli: b0-system/odig#12. |
I verified that, yes.
The Reported in #227. |
I don't know what the "entire opam codebase" is. But you really rather want to check I can certainly see a use for this, but again I don't think it is the right answer to the problem that was highlighted there. |
Ok. Are you also opposed to the idea of supporting I can close this PR if this doesn't seem useful. |
Note that I'm not opposed, I'm just asking how this fits in the picture to understand where this should go -- if it should -- and what problem it solves. It's always easy to pile up the features and produce code, but it has costs. Personally I still don't understand the problem it solves. I think |
To further agree with the above, running It's possible that in some projects conditional compilation, unmet optional dependencies, OS constraints, etc., will cause However, are we actually having a problem with these uncovered We likely don't need So, agreeing with the above, I don't see a need for For comparison, |
A new test in this PR, |
That makes sense, thanks for putting things into perspective. I'll submit a separate PR with |
The new tests are "end-to-end" tests, meaning rather than examining the error ASTs emitted by the parser, they check what is printed by odoc compile to the user. See #226 (comment).
The new tests are "end-to-end" tests, meaning rather than examining the error ASTs emitted by the parser, they check what is printed by odoc compile to the user. See #226 (comment). Code is by @rizo, porting and commit text by @aantron.
The new tests are "end-to-end" tests, meaning rather than examining the error ASTs emitted by the parser, they check what is printed by odoc compile to the user. See #226 (comment). Code is by @rizo, porting and commit text by @aantron.
The new tests are "end-to-end" tests, meaning rather than examining the error ASTs emitted by the parser, they check what is printed by odoc compile to the user. See ocaml/odoc#226 (comment). Code is by @rizo, porting and commit text by @aantron.
The new tests are "end-to-end" tests, meaning rather than examining the error ASTs emitted by the parser, they check what is printed by odoc compile to the user. See ocaml/odoc#226 (comment). Code is by @rizo, porting and commit text by @aantron.
From #217 (comment) by @avsm:
This PR implements an
odoc lint
command that does exactly that. It parsermli
andmld
files and uses an AST mapper to go through all[@@ocaml.doc ...]
/[@@ocaml.text ...]
attributes running odoc's parser on them and producing errors (see the test expect files in this PR for examples).I got excited about this and started implementing a ppx (#147) to validate docstings and report errors with merlin. Unfortunately I was surprised to discover that merlin doesn't convert docstrings into documentation attributes (see ocaml/merlin#876). After that is fixed implementing the ppx should be simple.
Changes
odoc lint FILE.{ml,mld}
command.id
argument fromLoader.Attrs.read_attributes
.Attrs
module inLoader
interface.Compat.Filename.remove_extension
.Notes
mld
files that have multiple errors only the first one will be reported (related to New docstrings parser too strict #108).[@@ocaml.doc]
attribute onpolymorphic variants (the CI should report all the culprits). I don't have a workaround for this.
master
. The location of the attributes is off by -3, I assume it's because it's not counting(**
.ml
) should be easy to implement and can be done separately.Thoughts and suggestions are welcome!