HomePhabricator

Add a linter to detect python % format and convert them to use .format()

Description

Add a linter to detect python % format and convert them to use .format()

Summary:
Given a python script at input, the linter will output a list of the
code snippets embedding a % format and suggest .format replacement for
them.
If called with no argument, the linter will run the doctests to check
its behavior.
This is intended to be integrated into arcanist in a later diff as an
autofix linter.

Note: the linter suggestion will transform multiline code into a single
line.

Current limitation (would require a tokenizer):

  • This linter does not support inlined comments in the middle of a formatting (see last test case from test-python-format.txt for an example). This case should be handled manually.

Test Plan:
Should return no error (no output, return code 0):

./test/lint/lint-python-format.py

Should return 31 errors:

./test/lint/lint-python-format.py

test/functional/test_framework/messages.py
Check the errors are not false-positive and that the suggestions are
correct.

Reviewers: #bitcoin_abc, deadalnix, jasonbcox

Reviewed By: #bitcoin_abc, deadalnix, jasonbcox

Subscribers: jasonbcox, teamcity, schancel

Differential Revision: https://reviews.bitcoinabc.org/D2557

Details

Provenance
FabienAuthored on Feb 14 2019, 15:59
FabienPushed on Mar 1 2019, 13:43
Reviewer
Restricted Project
Differential Revision
D2557: Add a linter to detect python % format and convert them to use .format()
Parents
rSTAGING8c68e96fd677: Fix debug build test failures
Branches
Unknown
Tags
Unknown