chore: add --fix option to lint:cpp (#14977)
* chore: add --fix option to lint:cpp * fix lint errors
This commit is contained in:
parent
af0ac9b95c
commit
2a4f5c3284
4 changed files with 44 additions and 28 deletions
|
@ -49,13 +49,12 @@ class AtomPermissionManager : public content::PermissionControllerDelegate {
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const base::Callback<void(blink::mojom::PermissionStatus)>& callback)
|
const base::Callback<void(blink::mojom::PermissionStatus)>& callback)
|
||||||
override;
|
override;
|
||||||
int RequestPermissionWithDetails(
|
int RequestPermissionWithDetails(content::PermissionType permission,
|
||||||
content::PermissionType permission,
|
content::RenderFrameHost* render_frame_host,
|
||||||
content::RenderFrameHost* render_frame_host,
|
const GURL& requesting_origin,
|
||||||
const GURL& requesting_origin,
|
bool user_gesture,
|
||||||
bool user_gesture,
|
const base::DictionaryValue* details,
|
||||||
const base::DictionaryValue* details,
|
const StatusCallback& callback);
|
||||||
const StatusCallback& callback);
|
|
||||||
int RequestPermissions(
|
int RequestPermissions(
|
||||||
const std::vector<content::PermissionType>& permissions,
|
const std::vector<content::PermissionType>& permissions,
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
|
|
|
@ -25,9 +25,8 @@ class WebContentsPermissionHelper
|
||||||
|
|
||||||
// Asynchronous Requests
|
// Asynchronous Requests
|
||||||
void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
|
void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
|
||||||
void RequestMediaAccessPermission(
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
||||||
const content::MediaStreamRequest& request,
|
content::MediaResponseCallback callback);
|
||||||
content::MediaResponseCallback callback);
|
|
||||||
void RequestWebNotificationPermission(
|
void RequestWebNotificationPermission(
|
||||||
const base::Callback<void(bool)>& callback);
|
const base::Callback<void(bool)>& callback);
|
||||||
void RequestPointerLockPermission(bool user_gesture);
|
void RequestPointerLockPermission(bool user_gesture);
|
||||||
|
|
|
@ -51,6 +51,11 @@ const LINTERS = [ {
|
||||||
roots: ['atom', 'brightray'],
|
roots: ['atom', 'brightray'],
|
||||||
test: filename => filename.endsWith('.cc') || filename.endsWith('.h'),
|
test: filename => filename.endsWith('.cc') || filename.endsWith('.h'),
|
||||||
run: (opts, filenames) => {
|
run: (opts, filenames) => {
|
||||||
|
if (opts.fix) {
|
||||||
|
spawnAndCheckExitCode('python', ['script/run-clang-format.py', '--fix', ...filenames])
|
||||||
|
} else {
|
||||||
|
spawnAndCheckExitCode('python', ['script/run-clang-format.py', ...filenames])
|
||||||
|
}
|
||||||
const result = childProcess.spawnSync('cpplint.py', filenames, { encoding: 'utf8' })
|
const result = childProcess.spawnSync('cpplint.py', filenames, { encoding: 'utf8' })
|
||||||
// cpplint.py writes EVERYTHING to stderr, including status messages
|
// cpplint.py writes EVERYTHING to stderr, including status messages
|
||||||
if (result.stderr) {
|
if (result.stderr) {
|
||||||
|
@ -61,7 +66,6 @@ const LINTERS = [ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
if (opts.fix) spawnAndCheckExitCode('python', ['script/run-clang-format.py', ...filenames])
|
|
||||||
process.exit(result.status)
|
process.exit(result.status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +161,7 @@ async function findFiles (args, linter) {
|
||||||
if (args.changed) {
|
if (args.changed) {
|
||||||
whitelist = await findChangedFiles(SOURCE_ROOT)
|
whitelist = await findChangedFiles(SOURCE_ROOT)
|
||||||
if (!whitelist.size) {
|
if (!whitelist.size) {
|
||||||
return filenames
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +187,10 @@ async function findFiles (args, linter) {
|
||||||
filenames = filenames.filter(x => whitelist.has(x))
|
filenames = filenames.filter(x => whitelist.has(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
return filenames
|
// it's important that filenames be relative otherwise clang-format will
|
||||||
|
// produce patches with absolute paths in them, which `git apply` will refuse
|
||||||
|
// to apply.
|
||||||
|
return filenames.map(x => path.relative(SOURCE_ROOT, x))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
|
|
|
@ -105,6 +105,8 @@ def run_clang_format_diff(args, file_name):
|
||||||
except IOError as exc:
|
except IOError as exc:
|
||||||
raise DiffError(str(exc))
|
raise DiffError(str(exc))
|
||||||
invocation = [args.clang_format_executable, file_name]
|
invocation = [args.clang_format_executable, file_name]
|
||||||
|
if args.fix:
|
||||||
|
invocation.append('-i')
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
' '.join(invocation),
|
' '.join(invocation),
|
||||||
|
@ -129,6 +131,8 @@ def run_clang_format_diff(args, file_name):
|
||||||
if proc.returncode:
|
if proc.returncode:
|
||||||
raise DiffError("clang-format exited with status {}: '{}'".format(
|
raise DiffError("clang-format exited with status {}: '{}'".format(
|
||||||
proc.returncode, file_name), errs)
|
proc.returncode, file_name), errs)
|
||||||
|
if args.fix:
|
||||||
|
return None, errs
|
||||||
return make_diff(file_name, original, outs), errs
|
return make_diff(file_name, original, outs), errs
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,6 +194,10 @@ def main():
|
||||||
help='comma separated list of file extensions (default: {})'.format(
|
help='comma separated list of file extensions (default: {})'.format(
|
||||||
DEFAULT_EXTENSIONS),
|
DEFAULT_EXTENSIONS),
|
||||||
default=DEFAULT_EXTENSIONS)
|
default=DEFAULT_EXTENSIONS)
|
||||||
|
parser.add_argument(
|
||||||
|
'--fix',
|
||||||
|
help='if specified, reformat files in-place',
|
||||||
|
action='store_true')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-r',
|
'-r',
|
||||||
'--recursive',
|
'--recursive',
|
||||||
|
@ -281,8 +289,9 @@ def main():
|
||||||
njobs = multiprocessing.cpu_count() + 1
|
njobs = multiprocessing.cpu_count() + 1
|
||||||
njobs = min(len(files), njobs)
|
njobs = min(len(files), njobs)
|
||||||
|
|
||||||
patch_file = tempfile.NamedTemporaryFile(delete=False,
|
if not args.fix:
|
||||||
prefix='electron-format-')
|
patch_file = tempfile.NamedTemporaryFile(delete=False,
|
||||||
|
prefix='electron-format-')
|
||||||
|
|
||||||
if njobs == 1:
|
if njobs == 1:
|
||||||
# execute directly instead of in a pool,
|
# execute directly instead of in a pool,
|
||||||
|
@ -316,20 +325,22 @@ def main():
|
||||||
sys.stderr.writelines(errs)
|
sys.stderr.writelines(errs)
|
||||||
if outs == []:
|
if outs == []:
|
||||||
continue
|
continue
|
||||||
if not args.quiet:
|
if not args.fix:
|
||||||
print_diff(outs, use_color=colored_stdout)
|
if not args.quiet:
|
||||||
for line in outs:
|
print_diff(outs, use_color=colored_stdout)
|
||||||
patch_file.write(line)
|
for line in outs:
|
||||||
patch_file.write('\n')
|
patch_file.write(line)
|
||||||
if retcode == ExitStatus.SUCCESS:
|
patch_file.write('\n')
|
||||||
retcode = ExitStatus.DIFF
|
if retcode == ExitStatus.SUCCESS:
|
||||||
|
retcode = ExitStatus.DIFF
|
||||||
|
|
||||||
if patch_file.tell() == 0:
|
if not args.fix:
|
||||||
patch_file.close()
|
if patch_file.tell() == 0:
|
||||||
os.unlink(patch_file.name)
|
patch_file.close()
|
||||||
else:
|
os.unlink(patch_file.name)
|
||||||
print("\nTo patch these files, run:\n$ git apply {}\n"
|
else:
|
||||||
.format(patch_file.name))
|
print("\nTo patch these files, run:\n$ git apply {}\n"
|
||||||
|
.format(patch_file.name))
|
||||||
|
|
||||||
return retcode
|
return retcode
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue