This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (65 loc) · 1.47 KB
/
index.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
67
68
69
70
71
import path from "node:path";
import { parseArgs } from "node:util";
import { walk, checkFile } from './util.js'
const { positionals, values: options } = parseArgs({
options: {
fix: {
type: 'boolean'
},
help: {
type: 'boolean',
short: 'h'
}
}
})
const wrapInOctothorpe = (line) => `# ${line}`
const wrapInSlashAsterisks = (line) => `/* ${line} */`
const wrapInDoubleSlash = (line) => `// ${line}`
const wrapInXMLComment = (line) => `<!-- ${line} -->`
const config = {
info: {
license: 'MPL-2.0',
year: '2023',
name: 'Edwin Kofler'
},
rootDir: path.resolve(positionals.length > 0 ? positionals[0] : '.'),
cliOptions: options,
ignoredDirectories: ['.git', 'node_modules'],
globalApply: {
skipLine: (line) => /^#!/.test(line)
},
perApply: [
{
match: ['.html'],
wrapInComment: wrapInXMLComment
},
{
match: ['.css', '.postcss'],
wrapInComment: wrapInSlashAsterisks
},
{
match: ['.js', '.jsx', '.ts', '.tsx'],
wrapInComment: wrapInDoubleSlash
},
{
match: ['.py'],
wrapInComment: wrapInOctothorpe
},
{
match: ['.yaml', '.yml'],
skipLine: (line) => line === '#cloud-config',
wrapInComment: wrapInOctothorpe
},
{
match: ['.toml'],
wrapInComment: wrapInOctothorpe
}
]
}
let badFiles = []
for await (const filepath of walk(config.rootDir, config)) {
if (filepath === null) continue
const files = await checkFile(filepath, config)
badFiles = badFiles.concat(files)
}
console.log(`Total Bad: ${badFiles.length}`)