-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.filename-lint.js
More file actions
52 lines (43 loc) · 1.77 KB
/
script.filename-lint.js
File metadata and controls
52 lines (43 loc) · 1.77 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
46
47
48
49
50
51
52
const path = require('node:path');
const micromatch = require('micromatch');
const weblog = require('webpack-log');
const ENV = require('./app.env');
const UTILS = require('./webpack.utils');
const config = require('./.filenamelintrc.json');
const VERBOSE = ENV.ARGV.verbose;
const logger = weblog({ name: 'filename-lint' });
const lintIgnore = UTILS.readIgnoreFile('./.filenamelintignore');
const statMessages = { skipped: 0, errors: 0, ignored: 0 };
const patterns = [...UTILS.processArgs._];
config.rules
.filter((rule) => (patterns.length > 0 ? patterns.some((i) => micromatch.isMatch(i, rule.pattern)) : true))
.forEach((rule) => {
const files = UTILS.globSync(rule.pattern, {
ignore: [...rule.ignore, `${ENV.OUTPUT_PATH}/**/*`],
nodir: true,
});
const ruleTest = new RegExp(rule.test);
files.forEach((resourcePath) => {
const relativePath = UTILS.slash(path.relative(__dirname, resourcePath));
if (lintIgnore.ignores(relativePath)) {
statMessages.ignored += 1;
if (VERBOSE) {
logger.info(`${relativePath}: ignored`);
}
return;
}
const filename = path.basename(resourcePath);
if (patterns.length > 0 && !patterns.some((i) => micromatch.isMatch(i, relativePath))) {
return;
}
if (ruleTest.test(filename)) {
statMessages.skipped += 1;
} else {
logger.error(`${relativePath}: expected to match "${rule.convention}" convention.`, ruleTest);
statMessages.errors += 1;
process.exitCode = 1;
}
});
});
console.log('');
logger.info('stats:', statMessages);