style: Fix incorrect style checker option name

The style used to support the option -w to automatically fix white
space issues. However, this option was actually wired up to fix all
styles issues the checker encountered. This changeset cleans up the
code that handles automatic fixing and adds an option to fix all
issues, and separate options for white spaces and include ordering.
This commit is contained in:
Andreas Sandberg 2015-02-11 10:23:33 -05:00
parent 9738f34411
commit 267443fa22

View file

@ -126,14 +126,10 @@ def modregions(wctx, fname):
return mod_regions return mod_regions
class UserInterface(object): class UserInterface(object):
def __init__(self, verbose=False, auto=False): def __init__(self, verbose=False):
self.auto = auto
self.verbose = verbose self.verbose = verbose
def prompt(self, prompt, results, default): def prompt(self, prompt, results, default):
if self.auto:
return self.auto
while True: while True:
result = self.do_prompt(prompt, results, default) result = self.do_prompt(prompt, results, default)
if result in results: if result in results:
@ -436,10 +432,17 @@ def do_check_style(hgui, repo, *pats, **opts):
""" """
from mercurial import mdiff, util from mercurial import mdiff, util
opt_fix_all = opts.get('fix_all', False)
if not opt_fix_all:
opt_fix_white = opts.get('fix_white', False) opt_fix_white = opts.get('fix_white', False)
opt_fix_include = opts.get('fix_include', False)
else:
opt_fix_white = True
opt_fix_include = True
opt_all = opts.get('all', False) opt_all = opts.get('all', False)
opt_no_ignore = opts.get('no_ignore', False) opt_no_ignore = opts.get('no_ignore', False)
ui = MercurialUI(hgui, hgui.verbose, opt_fix_white) ui = MercurialUI(hgui, verbose=hgui.verbose)
def prompt(name, func, regions=all_regions): def prompt(name, func, regions=all_regions):
result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a') result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a')
@ -450,6 +453,12 @@ def do_check_style(hgui, repo, *pats, **opts):
return False return False
def no_prompt(name, func, regions=all_regions):
func(name, regions)
return False
prompt_white = prompt if not opt_fix_white else no_prompt
prompt_include = prompt if not opt_fix_include else no_prompt
# Import the match (repository file name matching helper) # Import the match (repository file name matching helper)
# function. Different versions of Mercurial keep it in different # function. Different versions of Mercurial keep it in different
@ -481,16 +490,16 @@ def do_check_style(hgui, repo, *pats, **opts):
if not opt_no_ignore and check_ignores(fname): if not opt_no_ignore and check_ignores(fname):
continue continue
if whitespace.apply(fname, prompt, mod_regions): if whitespace.apply(fname, prompt_white, mod_regions):
return True return True
if sorted_includes.apply(fname, prompt, mod_regions): if sorted_includes.apply(fname, prompt_include, mod_regions):
return True return True
return False return False
def do_check_format(hgui, repo, **args): def do_check_format(hgui, repo, **args):
ui = MercurialUI(hgui, hgui.verbose, auto) ui = MercurialUI(hgui, hgui.verbose)
modified, added, removed, deleted, unknown, ignore, clean = repo.status() modified, added, removed, deleted, unknown, ignore, clean = repo.status()
@ -544,7 +553,9 @@ except ImportError:
cmdtable = { cmdtable = {
'^m5style' : ( '^m5style' : (
do_check_style, [ do_check_style, [
('w', 'fix-white', False, _("automatically fix whitespace")), ('f', 'fix-all', False, _("automatically fix style issues")),
('', 'fix-white', False, _("automatically fix white space issues")),
('', 'fix-include', False, _("automatically fix include ordering")),
('a', 'all', False, ('a', 'all', False,
_("include clean files and unmodified parts of modified files")), _("include clean files and unmodified parts of modified files")),
('', 'no-ignore', False, _("ignore the style ignore list")), ('', 'no-ignore', False, _("ignore the style ignore list")),