Skip to content

Simpler check-typo - #1910

Merged
gasche merged 12 commits into
ocaml:trunkfrom
gasche:simpler-check-typo
Oct 19, 2018
Merged

gasche merged 12 commits into
ocaml:trunkfrom
gasche:simpler-check-typo

Conversation

@gasche

@gasche gasche commented Jul 17, 2018

Copy link
Copy Markdown
Member

I wanted this to fix this particular comment of @dra27 in the review of #1905. If the present PR is accepted, I will rebase #1905 on top of it.

@gasche
gasche requested a review from dra27 July 17, 2018 09:23
@gasche

gasche commented Jul 17, 2018

Copy link
Copy Markdown
Member Author

@dra27 where is the use of check-typo (and maybe the pre-commit-hook) documented? If you have committed any documentation in the repository (I could only find a mention in passing in CONTRIBUTING.md), I think that it would be nice to have something in HACKING.adoc -- either the toplevel one, or a new tools/HACKING.adoc.

@gasche
gasche force-pushed the simpler-check-typo branch 2 times, most recently from 3098fd1 to 6a7dcd0 Compare July 18, 2018 22:50
@damiendoligez
damiendoligez self-requested a review July 20, 2018 13:37
@dra27

dra27 commented Jul 24, 2018

Copy link
Copy Markdown
Member

@gasche - I'm slightly embarrassed to say that while it's on my TODO list, documentation beyond the mention in CONTRIBUTING is all that I've committed so far.

@gasche

gasche commented Jul 27, 2018

Copy link
Copy Markdown
Member Author

@dra27: I'm hoping that you will eventually review this PR (and later #1905). There is nothing urgent about it, so feel free to prioritize other things.

@dra27

dra27 commented Jul 27, 2018

Copy link
Copy Markdown
Member

I had started to review it! I think the changes are great, just that going through it was taking time - I'll definitely come to it when I'm back from vacation in the second week of Aug.

@gasche

gasche commented Jul 27, 2018

Copy link
Copy Markdown
Member Author

Thanks for the update, and have nice vacations :-)

@gasche

gasche commented Aug 15, 2018

Copy link
Copy Markdown
Member Author

(gentle ping)

@gasche

gasche commented Sep 6, 2018

Copy link
Copy Markdown
Member Author

Would maybe someone else be interested in looking at this? @nojb, @Octachron, @trefis?

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay reviewing this. I have reviewed very carefully the changes to .gitattributes and reckon that all the pertinent logic which was hard-coded in check-typo is now transferred to .gitattributes.

The changes to the script itself look good to me - perhaps @damiendoligez could cast a quick eye over it for any concerns about coding style?

Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread tools/check-typo Resolved
Comment thread tools/check-typo
env $OCAML_CT_GIT_INDEX git check-attr --all $OCAML_CT_CA_FLAG "$1" \
| grep -o " typo\\..*$" | sed "s/ typo\\.//g" \
| grep -v ": unset" | grep -v ": false" \
| sed "s/: set//g" | sed "s/: true//g" | sed "s/: may/?/g"

@dra27 dra27 Sep 6, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pipe can be more simply (or at least compactly): sed -ne '/: \(set\|true\|may\)/s/.* typo\.//p' -e 's/: \(set\|true\)//' -e 's/:.*/?/'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My sed-fu is not high enough to understand your version, so I'll stick with dumb pipes for now.

Comment thread tools/check-typo Resolved
Comment thread tools/check-typo Resolved

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay reviewing this. I have reviewed very carefully the changes to .gitattributes and reckon that all the pertinent logic which was hard-coded in check-typo is now transferred to .gitattributes.

The changes to the script itself look good to me - perhaps @damiendoligez could cast a quick eye over it for any concerns about coding style?

@damiendoligez damiendoligez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
Comment thread .gitattributes Resolved
@dra27

dra27 commented Oct 17, 2018

Copy link
Copy Markdown
Member

I just ran the script over the entire repo and found that the yacc/*.[ch] was triggering unused warnings (because it was typo.long-line rather than typo.long-line=may).

I've also pushed a commit which makes it so that typo.very-long-line implies typo.long-line=may.

This needs rebasing, so feel free to squash the first commit and potentially drop the latter commit when you do!

@gasche
gasche force-pushed the simpler-check-typo branch from 54b43fd to de2e82e Compare October 17, 2018 09:06
@gasche

gasche commented Oct 17, 2018

Copy link
Copy Markdown
Member Author

I rebased the PR and I'm in the process of going over the review comments. I hope to finish today to get this PR dealt with.

@gasche

gasche commented Oct 17, 2018

Copy link
Copy Markdown
Member Author

@dra27 I'm sorry, I am just seeing that you did pushes on your own. (I force-pushed when I rebased.) I fixed the yacc-stuff as well, but I'm happy to integrate the long-line/very-long-line commit in the PR, could you push it again?

@dra27

dra27 commented Oct 17, 2018

Copy link
Copy Markdown
Member

No apology needed - it's your branch 🙂 Commit re-pushed...

@gasche
gasche force-pushed the simpler-check-typo branch 2 times, most recently from a5755c7 to e28d05e Compare October 17, 2018 12:28
@gasche

gasche commented Oct 17, 2018

Copy link
Copy Markdown
Member Author

I believe that I should now have addressed all review comments (thanks!).

@gasche
gasche force-pushed the simpler-check-typo branch from e28d05e to b263802 Compare October 17, 2018 12:33

@dra27 dra27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tweak - though mainly a chance to use GitHub's new suggest edit feature :)

Comment thread .gitattributes Outdated
testsuite/tests/lib-unix/win-stat/fakeclock.c typo.missing-header=false
testsuite/tests/misc-unsafe/almabench.ml typo.long-line
testsuite/tests/tool-toplevel/strings.ml typo.utf8
testsuite/tests/typing-unboxed-types/test.ml.reference* typo.white-at-eof

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testsuite/tests/typing-unboxed-types/test.ml.reference* typo.white-at-eof

@gasche

gasche commented Oct 17, 2018

Copy link
Copy Markdown
Member Author

@dra27: the way I read the diff produced by this indeed-intriguing feature, you are propose to remove the reference.ml* white-at-eof line. But if I remove it on my local copy, then I do get an alarm:

$ ./tools/check-typo testsuite/tests/typing-unboxed-types/test.ml.reference*
testsuite/tests/typing-unboxed-types/test.ml.reference-flat:213.1: [white-at-eof] empty line(s) at EOF
testsuite/tests/typing-unboxed-types/test.ml.reference-noflat:179.1: [white-at-eof] empty line(s) at EOF

What's going on here?

@gasche

gasche commented Oct 18, 2018

Copy link
Copy Markdown
Member Author

In the interest of not waiting too much on this issue (its discussion in #2096 (comment) bumped it up in my priority list), I'm thinking of merging this PR today or tomorrow.

@damiendoligez damiendoligez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK except for the unrelated changes.

modules = "tscanf2_io.ml"
files = "tscanf2_slave.ml"
reference = "${test_source_directory}/reference"
files = "tscanf2_worker.ml"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are completely unrelated to check-typo (unless you intend to add a style checker). They should be in a separate PR (and probably touch many more files).

@gasche
gasche force-pushed the simpler-check-typo branch from b263802 to 2c5bde0 Compare October 18, 2018 11:35
gasche and others added 10 commits October 18, 2018 13:44
Before this patch, check-typo is directed by a single git attribute,
ocaml-typo, which is used as a key to set a value:

    ocaml-typo=long-line,missing-header

(the value here is `long-line,missing-header`, and the code splits the
comma later)

This model is very fragile because .gitattributes does not allow to
give attribute keys a collecting/aggregating semantic: each new
setting of the key removes the previous setting, instead of adding to
them. For example,

    testsuite/tests/**                      ocaml-typo=missing-header
    testsuite/tests/win-unicode/*.ml        ocaml-typo=utf8

and

    testsuite/tests/win-unicode/*.ml        ocaml-typo=utf8
    testsuite/tests/**                      ocaml-typo=missing-header

are not equivalent, and instead of using either one we would introduce
redundancy for robustness:

    testsuite/tests/**                      ocaml-typo=missing-header
    testsuite/tests/win-unicode/*.ml        ocaml-typo=missing-header,utf8

With this patch, we switch to a model where each ocaml-typo setting is
its own attribute, of the form `typo.<<attribute>>`. The lines above
would be written, in either order:

    testsuite/tests/**                      typo.missing-header
    testsuite/tests/win-unicode/*.ml        typo.utf8

Not only does this approach make our .gitattributes more robust, it
allows for a more fine-grained treatment of the "unused-prop"
marker. This was used as an attribute to say: don't make it in an
error if the given typo-rule is in fact respected (by default, opting
out of a typo-rule gives an error if the typo-rule is respected). But
because of the single-key nature of ocaml-typo, unused-prop would
range over all settings, not just one of them. For example

    emacs/caml.el ocaml-typo=long-line,unused-prop,missing-header

seems to suggest that 'unused-prop' only qualifies the 'long-line'
rule, but in fact it also ranges over 'missing-header'. In contrast,
with this patch, we write the following:

    emacs/caml.el typo.long-line=may typo.missing-header

the `=may` value setting is used to make an exception to a typo-rule
optional.
Interestingly, most .gitattributes lines worked without extra error
when I turned each unused-prop in a =may setting over the rule just
before, instead of all rules: our checking is now more precise than
before, better capturing the intent of the .gitattributes author.

As I had to rewrite parts of the check-typo code for this, I took the
opportunity to rename a couple variables speaking about SVN (now long
defunct) into more meaningful names:

- `$is_svn` => `$path_in_index`
- `$svnrules` => `$attr_rules`
The initial motivation is to have a `foo.reference` file
instead of `reference`.
typo.long-line can still be explicitly set in .gitattributes (and
typo.long-line typo.very-long-line=may will still issue unused if no
lines are more than 80 columns)
@shindere

shindere commented Oct 18, 2018 via email

Copy link
Copy Markdown
Contributor

@gasche

gasche commented Oct 18, 2018

Copy link
Copy Markdown
Member Author

I'm busy with other things and would like to get done with this PR. Is it possible to leave those further suggestions to future PRs?

@shindere

shindere commented Oct 18, 2018 via email

Copy link
Copy Markdown
Contributor

@damiendoligez

Copy link
Copy Markdown
Member

@gasche just let me push a commit to rename the reference files before you merge.

@damiendoligez

Copy link
Copy Markdown
Member

Done.

@gasche
gasche merged commit ce17ca1 into ocaml:trunk Oct 19, 2018
@gasche

gasche commented Oct 19, 2018

Copy link
Copy Markdown
Member Author

Thanks! Merged.

EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
rboudrouss pushed a commit to rboudfork/ocaml that referenced this pull request Jul 12, 2026
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.

4 participants