chore: fix npm run lint
not working on Windows (#42281)
* fix: fixed the `npm run lint` not working on Windows. * chore: more fixes for lint on Windows * chore: revert change to patch linting --------- Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
parent
ae1a684d10
commit
f173a0637a
3 changed files with 13 additions and 10 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -22,6 +22,7 @@ patches/**/.patches merge=union
|
||||||
*.md text eol=lf
|
*.md text eol=lf
|
||||||
*.mm text eol=lf
|
*.mm text eol=lf
|
||||||
*.mojom text eol=lf
|
*.mojom text eol=lf
|
||||||
|
*.patches text eol=lf
|
||||||
*.proto text eol=lf
|
*.proto text eol=lf
|
||||||
*.py text eol=lf
|
*.py text eol=lf
|
||||||
*.ps1 text eol=lf
|
*.ps1 text eol=lf
|
||||||
|
|
|
@ -55,7 +55,7 @@ const CPPLINT_FILTERS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
function spawnAndCheckExitCode (cmd, args, opts) {
|
function spawnAndCheckExitCode (cmd, args, opts) {
|
||||||
opts = { stdio: 'inherit', ...opts };
|
opts = { stdio: 'inherit', shell: IS_WINDOWS, ...opts };
|
||||||
const { error, status, signal } = childProcess.spawnSync(cmd, args, opts);
|
const { error, status, signal } = childProcess.spawnSync(cmd, args, opts);
|
||||||
if (error) {
|
if (error) {
|
||||||
// the subprocess failed or timed out
|
// the subprocess failed or timed out
|
||||||
|
@ -100,9 +100,12 @@ const LINTERS = [{
|
||||||
roots: ['shell'],
|
roots: ['shell'],
|
||||||
test: filename => filename.endsWith('.cc') || (filename.endsWith('.h') && !isObjCHeader(filename)),
|
test: filename => filename.endsWith('.cc') || (filename.endsWith('.h') && !isObjCHeader(filename)),
|
||||||
run: (opts, filenames) => {
|
run: (opts, filenames) => {
|
||||||
|
const env = {
|
||||||
|
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
|
||||||
|
};
|
||||||
const clangFormatFlags = opts.fix ? ['--fix'] : [];
|
const clangFormatFlags = opts.fix ? ['--fix'] : [];
|
||||||
for (const chunk of chunkFilenames(filenames)) {
|
for (const chunk of chunkFilenames(filenames)) {
|
||||||
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', ...clangFormatFlags, ...chunk]);
|
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', ...clangFormatFlags, ...chunk], { env });
|
||||||
cpplint([`--filter=${CPPLINT_FILTERS.join(',')}`, ...chunk]);
|
cpplint([`--filter=${CPPLINT_FILTERS.join(',')}`, ...chunk]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,8 +114,11 @@ const LINTERS = [{
|
||||||
roots: ['shell'],
|
roots: ['shell'],
|
||||||
test: filename => filename.endsWith('.mm') || (filename.endsWith('.h') && isObjCHeader(filename)),
|
test: filename => filename.endsWith('.mm') || (filename.endsWith('.h') && isObjCHeader(filename)),
|
||||||
run: (opts, filenames) => {
|
run: (opts, filenames) => {
|
||||||
|
const env = {
|
||||||
|
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
|
||||||
|
};
|
||||||
const clangFormatFlags = opts.fix ? ['--fix'] : [];
|
const clangFormatFlags = opts.fix ? ['--fix'] : [];
|
||||||
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', '-r', ...clangFormatFlags, ...filenames]);
|
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', '-r', ...clangFormatFlags, ...filenames], { env });
|
||||||
const filter = [...CPPLINT_FILTERS, '-readability/braces'];
|
const filter = [...CPPLINT_FILTERS, '-readability/braces'];
|
||||||
cpplint(['--extensions=mm,h', `--filter=${filter.join(',')}`, ...filenames]);
|
cpplint(['--extensions=mm,h', `--filter=${filter.join(',')}`, ...filenames]);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +130,7 @@ const LINTERS = [{
|
||||||
const rcfile = path.join(DEPOT_TOOLS, 'pylintrc-2.17');
|
const rcfile = path.join(DEPOT_TOOLS, 'pylintrc-2.17');
|
||||||
const args = ['--rcfile=' + rcfile, ...filenames];
|
const args = ['--rcfile=' + rcfile, ...filenames];
|
||||||
const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env };
|
const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env };
|
||||||
spawnAndCheckExitCode('pylint-2.17', args, { env });
|
spawnAndCheckExitCode(IS_WINDOWS ? 'pylint-2.17.bat' : 'pylint-2.17', args, { env });
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'javascript',
|
key: 'javascript',
|
||||||
|
@ -170,8 +176,6 @@ const LINTERS = [{
|
||||||
DEPOT_TOOLS_WIN_TOOLCHAIN: '0',
|
DEPOT_TOOLS_WIN_TOOLCHAIN: '0',
|
||||||
...process.env
|
...process.env
|
||||||
};
|
};
|
||||||
// Users may not have depot_tools in PATH.
|
|
||||||
env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`;
|
|
||||||
const args = ['format', filename];
|
const args = ['format', filename];
|
||||||
if (!opts.fix) args.push('--dry-run');
|
if (!opts.fix) args.push('--dry-run');
|
||||||
const result = childProcess.spawnSync('gn', args, { env, stdio: 'inherit', shell: true });
|
const result = childProcess.spawnSync('gn', args, { env, stdio: 'inherit', shell: true });
|
||||||
|
|
|
@ -134,6 +134,7 @@ def run_clang_format_diff(args, file_name):
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
|
encoding='utf-8',
|
||||||
shell=True) as proc:
|
shell=True) as proc:
|
||||||
outs = list(proc.stdout.readlines())
|
outs = list(proc.stdout.readlines())
|
||||||
errs = list(proc.stderr.readlines())
|
errs = list(proc.stderr.readlines())
|
||||||
|
@ -186,10 +187,7 @@ def colorize(diff_lines):
|
||||||
def print_diff(diff_lines, use_color):
|
def print_diff(diff_lines, use_color):
|
||||||
if use_color:
|
if use_color:
|
||||||
diff_lines = colorize(diff_lines)
|
diff_lines = colorize(diff_lines)
|
||||||
if sys.version_info[0] < 3:
|
sys.stdout.writelines(diff_lines)
|
||||||
sys.stdout.writelines((l.encode('utf-8') for l in diff_lines))
|
|
||||||
else:
|
|
||||||
sys.stdout.writelines(diff_lines)
|
|
||||||
|
|
||||||
|
|
||||||
def print_trouble(prog, message, use_colors):
|
def print_trouble(prog, message, use_colors):
|
||||||
|
|
Loading…
Reference in a new issue