Improve stylelint variable checking (#178002)
parent
2ea2c80d63
commit
3f5600c324
|
@ -187,9 +187,13 @@ function hygiene(some, linting = true) {
|
|||
)
|
||||
);
|
||||
streams.push(
|
||||
result.pipe(filter(stylelintFilter)).pipe(gulpstylelint((error => {
|
||||
console.error(error);
|
||||
result.pipe(filter(stylelintFilter)).pipe(gulpstylelint(((message, isError) => {
|
||||
if (isError) {
|
||||
console.error(message);
|
||||
errorCount++;
|
||||
} else {
|
||||
console.warn(message);
|
||||
}
|
||||
})))
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,25 +13,37 @@ module.exports = gulpstylelint;
|
|||
/** use regex on lines */
|
||||
function gulpstylelint(reporter) {
|
||||
const variableValidator = getVariableNameValidator();
|
||||
let errorCount = 0;
|
||||
return es.through(function (file) {
|
||||
const lines = file.__lines || file.contents.toString('utf8').split(/\r\n|\r|\n/);
|
||||
file.__lines = lines;
|
||||
|
||||
lines.forEach((line, i) => {
|
||||
variableValidator(line, unknownVariable => {
|
||||
reporter(file.relative + '(' + (i + 1) + ',1): Unknown variable: ' + unknownVariable);
|
||||
reporter(file.relative + '(' + (i + 1) + ',1): Unknown variable: ' + unknownVariable, true);
|
||||
errorCount++;
|
||||
});
|
||||
});
|
||||
|
||||
this.emit('data', file);
|
||||
});
|
||||
}, function () {
|
||||
if (errorCount > 0) {
|
||||
reporter('All valid variable names are in `build/lib/stylelint/vscode-known-variables.json`\nTo update that file, run `./scripts/test-documentation.sh|bat.`', false);
|
||||
}
|
||||
this.emit('end');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function stylelint() {
|
||||
return vfs
|
||||
.src(stylelintFilter, { base: '.', follow: true, allowEmpty: true })
|
||||
.pipe(gulpstylelint(error => {
|
||||
console.error(error);
|
||||
.pipe(gulpstylelint((message, isError) => {
|
||||
if (isError) {
|
||||
console.error(message);
|
||||
} else {
|
||||
console.info(message);
|
||||
}
|
||||
}))
|
||||
.pipe(es.through(function () { /* noop, important for the stream to end */ }));
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ const knwonVariablesFileName = 'vscode-known-variables.json';
|
|||
|
||||
suite('Color Registry', function () {
|
||||
|
||||
test('all colors listed in ./lib/stylelint/vscode-variables.json', async function () {
|
||||
test(`update colors in ${knwonVariablesFileName}`, async function () {
|
||||
const varFilePath = FileAccess.asFileUri(`vs/../../build/lib/stylelint/${knwonVariablesFileName}`).fsPath;
|
||||
const content = (await pfs.Promises.readFile(varFilePath)).toString();
|
||||
|
||||
|
@ -50,6 +50,7 @@ suite('Color Registry', function () {
|
|||
|
||||
const colors = new Set(colorsArray);
|
||||
|
||||
const updatedColors = [];
|
||||
const missing = [];
|
||||
const themingRegistry = Registry.as<IColorRegistry>(Extensions.ColorContribution);
|
||||
for (const color of themingRegistry.getColors()) {
|
||||
|
@ -62,20 +63,25 @@ suite('Color Registry', function () {
|
|||
} else {
|
||||
colors.delete(id);
|
||||
}
|
||||
updatedColors.push(id);
|
||||
}
|
||||
|
||||
const superfluousKeys = [...colors.keys()];
|
||||
|
||||
let errorText = '';
|
||||
if (missing.length > 0) {
|
||||
errorText += `\n\Add the following colors:\n\n${JSON.stringify(missing, undefined, '\t')}\n`;
|
||||
errorText += `\n\Adding the following colors:\n\n${JSON.stringify(missing, undefined, '\t')}\n`;
|
||||
}
|
||||
if (superfluousKeys.length > 0) {
|
||||
errorText += `\n\Remove the following colors:\n\n${superfluousKeys.join('\n')}\n`;
|
||||
errorText += `\n\Removing the following colors:\n\n${superfluousKeys.join('\n')}\n`;
|
||||
}
|
||||
|
||||
if (errorText.length > 0) {
|
||||
assert.fail(`\n\nOpen ${path.normalize(varFilePath)}\n\n${errorText}\n`);
|
||||
updatedColors.sort();
|
||||
variablesInfo.colors = updatedColors;
|
||||
await pfs.Promises.writeFile(varFilePath, JSON.stringify(variablesInfo, undefined, '\t'));
|
||||
|
||||
assert.fail(`\n\Updating ${path.normalize(varFilePath)}.\nPlease verify and commit.\n\n${errorText}\n`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue