Closed Bug 1379151 Opened 5 years ago Closed 5 years ago

[mozlint] Add support for fixers


(Firefox Build System :: Lint and Formatting, enhancement, P2)



(firefox57 fixed)

Tracking Status
firefox57 --- fixed


(Reporter: ahal, Assigned: ahal)




(1 file)

Many external linters (e.g eslint, clang-tidy) have the ability to fix the errors that they report. We could also implement a python fixer with the autopep8 module.

It would be nice if mozlint had a best effort --fix argument that could call into these various fixer functions. Linters could declare that they support fixing in their mozlint definitions. Linters that do not declare this would get skipped when running ./mach lint --fix.
I think it's better to copy eslint's behaviour here. So with --fix, anything that can be fixed is, and the rest is printed to stdout. This way there's no need for linters to declare that they have "fixing" capability or anything like that. They either make use of the "fix" config or they don't.

I have a further idea for --fix. I want to add an "edit" mode that will open failing files in an editor (one by one). Then there can be a "mixed" mode which will automatically fix what it can, and open the remaining files in an editor.
Assignee: nobody → ahalberstadt
Blocks: 1387555
Comment on attachment 8893635 [details]
Bug 1379151 - Add --fix and --edit to mozlint,

Looks good. We might want some sort of re-lint after all edits done option, but I think as a starter this is an improvement, especially the official --fix option.
Attachment #8893635 - Flags: review?(standard8) → review+
We're sorry, Autoland could not rebase your commits for you automatically. Please manually rebase your commits and try again.

hg error in cmd: hg rebase -s 611fd94b45a0 -d 8e991e3b80f6: rebasing 412354:611fd94b45a0 "Bug 1379151 - Add --fix and --edit to mozlint, r=standard8" (tip)
merging python/mozlint/mozlint/
warning: conflicts while merging python/mozlint/mozlint/! (edit, then use 'hg resolve --mark')
unresolved conflicts (see hg resolve, then hg rebase --continue)
Comment on attachment 8893635 [details]
Bug 1379151 - Add --fix and --edit to mozlint,

Good idea, I'll add that in a follow-up, possibly bug 1387555
Severity: normal → enhancement
Priority: -- → P2
Pushed by
Add --fix and --edit to mozlint, r=standard8
Backed out for breaking Windows builds:

Push with failures:
Failure log:

14:21:15     INFO - ============================= test session starts =============================
14:21:15     INFO - platform win32 -- Python 2.7.11, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 -- z:\build\build\src\obj-firefox\_virtualenv\Scripts\python.exe
14:21:15     INFO - cachedir: ..\python\mozlint\.cache
14:21:15     INFO - rootdir: z:\build\build\src\python\mozlint, inifile:
14:21:15     INFO - collecting ... collected 2 items
14:21:15     INFO - ..\python\mozlint\test\ PASSED
14:21:15     INFO - ..\python\mozlint\test\ FAILED
14:21:15     INFO - ================================== FAILURES ===================================
14:21:15     INFO - ___________________________ test_cli_run_with_edit ____________________________
14:21:15     INFO - run = <function inner at 0x03D4BBB0>
14:21:15     INFO - parser = MozlintParser(prog='', usage=None, description=None, version=None, ...lass=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
14:21:15     INFO - capfd = <_pytest.capture.CaptureFixture instance at 0x03D53288>
14:21:15     INFO -     def test_cli_run_with_edit(run, parser, capfd):
14:21:15     INFO -         os.environ['EDITOR'] = 'echo'
14:21:15     INFO -         ret = run(['-f', 'json', '--edit', '--linter', 'external'])
14:21:15     INFO -         out, err = capfd.readouterr()
14:21:15     INFO -         assert ret == 0
14:21:15     INFO - >       assert out.endswith('foobar.js\n')
14:21:15     INFO - E       AssertionError: assert False
14:21:15     INFO - E        +  where False = <built-in method endswith of unicode object at 0x035190E0>('foobar.js\n')
14:21:15     INFO - E        +    where <built-in method endswith of unicode object at 0x035190E0> = 'z:\build\build\src\python\mozlint\test\files\foobar.js
14:21:15     INFO - \n'.endswith
14:21:15     INFO - ..\python\mozlint\test\ AssertionError
14:21:15     INFO - ===================== 1 failed, 1 passed in 20.01 seconds =====================
Flags: needinfo?(ahalberstadt)
Sorry for the bustage, thought I had tested this on Windows, but turns out I had pushed it along with another patch and it was the other patch that was making this pass. Latest review push should fix this:
Flags: needinfo?(ahalberstadt)
Pushed by
Add --fix and --edit to mozlint, r=standard8
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Product: Testing → Firefox Build System
You need to log in before you can comment on or make changes to this bug.