Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/stylelint.js
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
// @ts-check
6
7
const es = require('event-stream');
8
const vfs = require('vinyl-fs');
9
const { stylelintFilter } = require('./filters');
10
const { getVariableNameValidator } = require('./lib/stylelint/validateVariableNames');
11
12
module.exports = gulpstylelint;
13
14
/**
15
* use regex on lines
16
*
17
* @param {function(string, boolean):void} reporter
18
*/
19
function gulpstylelint(reporter) {
20
const variableValidator = getVariableNameValidator();
21
let errorCount = 0;
22
return es.through(function (file) {
23
/** @type {string[]} */
24
const lines = file.__lines || file.contents.toString('utf8').split(/\r\n|\r|\n/);
25
file.__lines = lines;
26
27
lines.forEach((line, i) => {
28
variableValidator(line, unknownVariable => {
29
reporter(file.relative + '(' + (i + 1) + ',1): Unknown variable: ' + unknownVariable, true);
30
errorCount++;
31
});
32
});
33
34
this.emit('data', file);
35
}, function () {
36
if (errorCount > 0) {
37
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);
38
}
39
this.emit('end');
40
}
41
);
42
}
43
44
function stylelint() {
45
return vfs
46
.src(stylelintFilter, { base: '.', follow: true, allowEmpty: true })
47
.pipe(gulpstylelint((message, isError) => {
48
if (isError) {
49
console.error(message);
50
} else {
51
console.info(message);
52
}
53
}))
54
.pipe(es.through(function () { /* noop, important for the stream to end */ }));
55
}
56
57
if (require.main === module) {
58
stylelint().on('error', (err) => {
59
console.error();
60
console.error(err);
61
process.exit(1);
62
});
63
}
64
65