Skip to content

Commit

Permalink
Merge pull request #7402 from brave/fix/lint-format
Browse files Browse the repository at this point in the history
run git cl format without '--full' by default
  • Loading branch information
diracdeltas committed Dec 11, 2020
2 parents 603f34b + f827414 commit 7e397a5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/commands/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ const util = {
let cmd_options = config.defaultOptions
cmd_options.cwd = config.braveCoreDir
cmd_options = mergeWithDefault(cmd_options)
util.run('vpython', [path.join(config.braveCoreDir, 'build', 'commands', 'scripts', 'format.py')], cmd_options)
util.run('vpython', [path.join(config.braveCoreDir, 'build', 'commands', 'scripts', 'format.py'), options.full ? '--full' : ''], cmd_options)
},


Expand Down
1 change: 1 addition & 0 deletions build/commands/scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ program

program
.command('format')
.option('--full', 'format all lines in changed files instead of only the changed lines')
.action(util.format)

program
Expand Down
5 changes: 3 additions & 2 deletions build/commands/scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
def main(args):
"""Runs clang-format and gn format on the current changelist."""
parser = git_cl.OptionParser()
options, args = parser.parse_args(args)
parser.parse_args([])

# Change the current working directory before calling so that it
# shows the correct base.
settings = git_cl.settings
previous_cwd = os.getcwd()
os.chdir(settings.GetRoot())
try:
cmd = ['cl', 'format', '--full'] + args
cmd = ['cl', 'format'] + args
print('git ' + ' '.join(cmd))
git_cl.RunGit(cmd)
except:
e = sys.exc_info()[1]
Expand Down
16 changes: 8 additions & 8 deletions build/commands/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import git_cl
import git_common

def HasFormatErrors():
print('Running git cl format and gn format...')
def HasFormatErrors(base_commit):
print('Running git cl format and gn format on the diff from %s...' % base_commit)
# For more options, see vendor/depot_tools/git_cl.py
cmd = ['cl', 'format', '--diff']
diff = git_cl.RunGit(cmd)
Expand Down Expand Up @@ -55,11 +55,11 @@ def main(args):

# Check for clang/gn format errors.
cl = git_cl.Changelist()
upstream_branch = cl.GetUpstreamBranch()
upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch])
try:
if HasFormatErrors():
upstream_branch = cl.GetUpstreamBranch()
upstream_commit = git_cl.RunGit(['merge-base', 'HEAD', upstream_branch])
print('Format check failed against commit %s. Run npm format to fix.' % upstream_commit)
if HasFormatErrors(upstream_commit):
print('Format check failed. Run npm format to fix.')
exit_code = 1
except:
e = sys.exc_info()[1]
Expand All @@ -69,7 +69,7 @@ def main(args):
if exit_code == 0:
print('Format check succeeded.')

print('Running lint...')
print('Running cpplint...')
try:
files = cl.GetAffectedFiles(git_common.get_or_create_merge_base(cl.GetBranch(), options.base_branch))
if not files:
Expand Down Expand Up @@ -98,7 +98,7 @@ def main(args):
print('Skipping file %s' % filename)
finally:
os.chdir(previous_cwd)
print('Total errors found: %d\n' % cpplint._cpplint_state.error_count)
print('cpplint errors found: %d\n' % cpplint._cpplint_state.error_count)
if cpplint._cpplint_state.error_count != 0:
return 1
return exit_code
Expand Down

0 comments on commit 7e397a5

Please sign in to comment.