Closed Bug 1312081 Opened 8 years ago Closed 7 years ago

Add option for pre-push mozlint integration

Categories

(Developer Infrastructure :: Lint and Formatting, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1361972

People

(Reporter: erahm, Unassigned)

Details

As a user it would be nice if |mach mercurial-setup| configured a hook to run eslint before pushing (maybe only to certain repos). mossop pointed me to a blogpost on a pre-commit extension [1], I'm not sure if we'd want to reuse/update that or not.

For example if I did:
> hg push mozilla-inbound
> // or
> hg push review

It would be helpful to have eslint run with our mozilla-specific rules so I don't have to deal with getting backed out (it looks like we're planning on turning on the linter in treeherder) or review-nit-picked-to-death for style issues.

If pre-push isn't an option, pre-commit would be okay too although I imagine fewer people would opt for that.

[1] https://www.oxymoronical.com/blog/2015/12/Running-ESLint-on-commit
Just going to genericize this to not only run eslint, but all linters. This should be pretty easy to setup as a custom mercurial hook. It just needs to run:

./mach lint -r <all revs in push>

This will run not only eslint, but flake8, wpt and whatever other linters may be applicable in the future. And only on the files that are touched, so it should be fast too.
Component: Mercurial: configwizard → Lint
Product: Developer Services → Testing
Summary: Add option for eslint pre-push integration → Add option for pre-push mozlint integration
There is already (hacky) code in the reviewboard client extension to run some Java checks as part of review submission. We should additionally change that to invoke `mach lint` when it is ready.

I'm also fine with adding a commit hook to the reviewboard client extension to run lints. If someone has that extension installed, they intend to submit code to Mozilla for review. So we might as well have it run lints automatically too.

ahal: if lints can process content that comes from a buffer (as opposed to the filesystem), it is possible to feed file content directly from Mercurial into the linter (yay Python). If you code things to use the FileFinder interface from mozpack, there is code in python/mozbuild/mozpack/hg.py for finding files and loading file content from Mercurial revisions without having to write files on the filesystem. We don't have an equivalent for Git (yet), however.
eslint can lint stdin with the --stdin and --stdin-filename command line arguments, but it will still use whatever state the local filesystem is in to find the configuration files. This makes linting an arbitrary revision a potential problem.
That's a good point about the configuration, I don't really see a way around that aside from updating to the proper revision, at which point I assume the benefit of using buffers is mainly negated.

The current behaviour by the way is to not update at all, so -r will lint the existing state of the filesystem regardless. I was kind of thinking of it like "Lint files touched by these revisions at whatever the filesystem is", but in hindsight, this is probably a bad and confusing idea.

Thinking about it, I think --rev should be removed and replaced with something like --outgoing (lint all files touched by changesets that "would" get pushed to the specified repo). This has the benefit of only linting changesets which you are currently updated to, which is mostly what I was trying to accomplish when initially writing --rev.
This is fixed on autoland (sorry, I forgot about this older bug)! For instructions on how to set up both pre-push and pre-commit hooks in hg and git, see the commit message:
https://hg.mozilla.org/integration/autoland/rev/ea6fb7712a57

Since my last comment, I also got rid of the --rev option. This new thing uses `hg outgoing` so the files are guaranteed to be checked out at the proper revision.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Oh and the |mach mercurial-setup| portion of this will be handled in bug 1295833.
Product: Testing → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.