Skip to content

Commit 60a23c7

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Lint] Fix issue with window
Windows max line argument is around 8000, if you pass that the command will fail, we need to split the LitAnalyzer files when we spawn it. No-Presubmit: true Bug: none Change-Id: I68dd71228b02a8ae01555b23a229f5fcc69b2a11 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5923563 Reviewed-by: Danil Somsikov <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent 6caf7b0 commit 60a23c7

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

scripts/test/run_lint_check.js

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const globby = require('globby');
1212
const yargs = require('yargs/yargs');
1313
const {hideBin} = require('yargs/helpers');
1414
const childProcess = require('child_process');
15+
const {promisify} = require('util');
16+
const spawnAsync = promisify(childProcess.spawnSync);
17+
1518
const {
1619
devtoolsRootPath,
1720
litAnalyzerExecutablePath,
@@ -30,12 +33,7 @@ const flags = yargs(hideBin(process.argv))
3033
yargs.positional('files', {
3134
describe: 'File(s), glob(s), or directories',
3235
type: 'array',
33-
default: [
34-
'front_end',
35-
'inspector_overlay',
36-
'scripts',
37-
'test',
38-
],
36+
default: ['front_end', 'inspector_overlay', 'scripts', 'test'],
3937
});
4038
})
4139
.parse();
@@ -56,7 +54,9 @@ async function runESLint(files) {
5654
// This was originally reported in https://github.com/eslint/eslint/issues/9977
5755
// The suggested workaround is to use the CLIEngine to pre-emptively filter out these
5856
// problematic paths.
59-
files = await Promise.all(files.map(async file => (await cli.isPathIgnored(file)) ? null : file));
57+
files = await Promise.all(
58+
files.map(async file => ((await cli.isPathIgnored(file)) ? null : file)),
59+
);
6060
files = files.filter(file => file !== null);
6161

6262
const results = await cli.lintFiles(files);
@@ -90,19 +90,63 @@ async function runStylelint(files) {
9090
return !errored;
9191
}
9292

93-
function runLitAnalyzer(files) {
94-
const rules = {'no-missing-import': 'error', 'no-unknown-tag-name': 'error', 'no-complex-attribute-binding': 'off'};
95-
const args =
96-
[litAnalyzerExecutablePath(), ...Object.entries(rules).flatMap(([k, v]) => [`--rules.${k}`, v]), ...files];
97-
const result =
98-
childProcess.spawnSync(nodePath(), args, {encoding: 'utf-8', cwd: devtoolsRootPath(), stdio: 'inherit'});
99-
return result.status === 0;
93+
/**
94+
* @param {string[]} files
95+
*/
96+
async function runLitAnalyzer(files) {
97+
const rules = {
98+
'no-missing-import': 'error',
99+
'no-unknown-tag-name': 'error',
100+
'no-complex-attribute-binding': 'off',
101+
};
102+
const getLitAnalyzerResult = async subsetFiles => {
103+
const args = [
104+
litAnalyzerExecutablePath(),
105+
...Object.entries(rules).flatMap(([k, v]) => [`--rules.${k}`, v]),
106+
...subsetFiles,
107+
];
108+
const result = await spawnAsync(nodePath(), args, {
109+
encoding: 'utf-8',
110+
cwd: devtoolsRootPath(),
111+
stdio: 'inherit',
112+
});
113+
return result.status === 0;
114+
};
115+
116+
const getSplitFiles = filesToSplit => {
117+
if (process.platform !== 'win32') {
118+
return [filesToSplit];
119+
}
120+
121+
const splitFiles = [[]];
122+
let index = 0;
123+
for (const file of filesToSplit) {
124+
// Windows max input is 8191 so we should be conservative
125+
if (splitFiles[index].join(' ').length + file.length < 6144) {
126+
splitFiles[index].push(file);
127+
} else {
128+
index++;
129+
splitFiles[index] = [file];
130+
}
131+
}
132+
return splitFiles;
133+
};
134+
135+
const result = await Promise.all(
136+
getSplitFiles(files).map(filesBatch => {
137+
return getLitAnalyzerResult(filesBatch);
138+
}),
139+
);
140+
141+
return result.every(r => r);
100142
}
101143

102144
async function run() {
103145
const scripts = [];
104146
const styles = [];
105-
for (const path of globby.sync(flags.files, {expandDirectories: {extensions: ['css', 'js', 'ts']}})) {
147+
for (const path of globby.sync(flags.files, {
148+
expandDirectories: {extensions: ['css', 'js', 'ts']},
149+
})) {
106150
if (extname(path) === '.css') {
107151
styles.push(path);
108152
} else {
@@ -113,7 +157,7 @@ async function run() {
113157
let succeed = true;
114158
if (scripts.length !== 0) {
115159
succeed &&= await runESLint(scripts);
116-
succeed &&= runLitAnalyzer(scripts);
160+
succeed &&= await runLitAnalyzer(scripts);
117161
}
118162
if (styles.length !== 0) {
119163
succeed &&= await runStylelint(styles);

0 commit comments

Comments
 (0)