forked from dracula/visual-studio-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.js
66 lines (54 loc) · 2.14 KB
/
lint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
const https = require('https');
const path = require('path');
const loadThemes = require('./loadThemes');
const get = url =>
new Promise((resolve, reject) => {
https.get(url, res => {
let body = '';
res.setEncoding('utf8');
res.on('data', data => (body += data));
res.on('end', () => resolve(body));
res.on('error', reject);
});
});
const THEME_COLOR_REFERENCE_URL =
'https://code.visualstudio.com/docs/getstarted/theme-color-reference';
const NOT_THEME_KEYS = [
'workbench.colorCustomizations',
'editor.tokenColorCustomizations',
];
const THEME_YAML_FILE = path.join(__dirname, '..', 'src', 'dracula.yml');
async function scrapeThemeAvailableKeys() {
const data = await get(THEME_COLOR_REFERENCE_URL);
const matches = data.match(new RegExp('<code>.+?</code>', 'g'));
if (!matches) {
throw new Error(
"Couldn't find any matches with <code>...</code>, maybe docs have chaged?"
);
}
const availableKeys = [...matches]
.map(key => key.replace('<code>', '').replace('</code>', ''))
.filter(key => !/ /.test(key)) // Remove if contains spaces
.filter(key => !/#.../.test(key)) // Remove if is a hex color
.filter(key => !/"/.test(key)) // Remove if contains quotes
.filter(key => key.length > 4) // Remove if it's very small
.filter(key => !NOT_THEME_KEYS.includes(key)); // Remove if its in the blacklist
return availableKeys;
}
(async () => {
const [availableKeys, { standardTheme }] = await Promise.all([
scrapeThemeAvailableKeys(),
loadThemes(THEME_YAML_FILE),
]);
Object.keys(standardTheme.colors).forEach(key => {
if (!availableKeys.includes(key)) {
console.warn(`Unsupported key "${key}", probably deprecated?`);
}
});
availableKeys.forEach(key => {
if (!Object.keys(standardTheme.colors).includes(key)) {
console.warn(`Missing key "${key}" in theme`);
}
});
})().catch(err => console.error(err));