-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathparseEslintConfigForKnownGlobals.js
More file actions
executable file
·45 lines (37 loc) · 1.09 KB
/
parseEslintConfigForKnownGlobals.js
File metadata and controls
executable file
·45 lines (37 loc) · 1.09 KB
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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const searchLines = [
' no-restricted-globals:',
' node-core/prefer-primordials:',
];
const restrictedGlobalLine = /^\s{4}- name:\s?([^#\s]+)/;
const closingLine = /^\s{0,3}[^#\s]/;
const jsonFile = fs.openSync(path.join(__dirname, 'knownGlobals.json'), 'w');
fs.writeSync(jsonFile, '["process"');
const eslintConfig = readline.createInterface({
input: fs.createReadStream(
path.join(__dirname, '..', '..', 'lib', '.eslintrc.yaml')
),
crlfDelay: Infinity,
});
let isReadingGlobals = false;
eslintConfig.on('line', (line) => {
if (isReadingGlobals) {
const match = restrictedGlobalLine.exec(line);
if (match != null) {
fs.writeSync(jsonFile, ',' + JSON.stringify(match[1]));
} else if (closingLine.test(line)) {
isReadingGlobals = false;
}
} else if (line === searchLines[0]) {
searchLines.shift();
isReadingGlobals = true;
}
});
eslintConfig.once('close', () => {
fs.writeSync(jsonFile, ']');
fs.closeSync(jsonFile);
});