chore: fix `npm run lint` not working on Windows (#42905)

* 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: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: reito <cnschwarzer@qq.com>
This commit is contained in:
trop[bot] 2024-07-16 12:32:12 +02:00 коммит произвёл GitHub
Родитель ef4896b37f
Коммит c4d9e79021
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 13 добавлений и 10 удалений

1
.gitattributes поставляемый
Просмотреть файл

@ -22,6 +22,7 @@ patches/**/.patches merge=union
*.md text eol=lf
*.mm text eol=lf
*.mojom text eol=lf
*.patches text eol=lf
*.proto text eol=lf
*.py text eol=lf
*.ps1 text eol=lf

Просмотреть файл

@ -55,7 +55,7 @@ const CPPLINT_FILTERS = [
];
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);
if (error) {
// the subprocess failed or timed out
@ -100,9 +100,12 @@ const LINTERS = [{
roots: ['shell'],
test: filename => filename.endsWith('.cc') || (filename.endsWith('.h') && !isObjCHeader(filename)),
run: (opts, filenames) => {
const env = {
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
};
const clangFormatFlags = opts.fix ? ['--fix'] : [];
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]);
}
}
@ -111,8 +114,11 @@ const LINTERS = [{
roots: ['shell'],
test: filename => filename.endsWith('.mm') || (filename.endsWith('.h') && isObjCHeader(filename)),
run: (opts, filenames) => {
const env = {
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
};
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'];
cpplint(['--extensions=mm,h', `--filter=${filter.join(',')}`, ...filenames]);
}
@ -124,7 +130,7 @@ const LINTERS = [{
const rcfile = path.join(DEPOT_TOOLS, 'pylintrc-2.17');
const args = ['--rcfile=' + rcfile, ...filenames];
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',
@ -170,8 +176,6 @@ const LINTERS = [{
DEPOT_TOOLS_WIN_TOOLCHAIN: '0',
...process.env
};
// Users may not have depot_tools in PATH.
env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`;
const args = ['format', filename];
if (!opts.fix) args.push('--dry-run');
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,
stderr=subprocess.PIPE,
universal_newlines=True,
encoding='utf-8',
shell=True) as proc:
outs = list(proc.stdout.readlines())
errs = list(proc.stderr.readlines())
@ -186,10 +187,7 @@ def colorize(diff_lines):
def print_diff(diff_lines, use_color):
if use_color:
diff_lines = colorize(diff_lines)
if sys.version_info[0] < 3:
sys.stdout.writelines((l.encode('utf-8') for l in diff_lines))
else:
sys.stdout.writelines(diff_lines)
sys.stdout.writelines(diff_lines)
def print_trouble(prog, message, use_colors):