pr-checkmate 1.21.3 → 1.21.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@ const delta_1 = require("../utils/delta");
|
|
|
10
10
|
const config_1 = require("../config");
|
|
11
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
12
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
13
14
|
function loadUserMarkdownConfig() {
|
|
14
15
|
const configPath = node_path_1.default.join(process.cwd(), 'pr-checkmate.json');
|
|
15
16
|
if (!node_fs_1.default.existsSync(configPath)) {
|
|
@@ -24,39 +25,64 @@ function loadUserMarkdownConfig() {
|
|
|
24
25
|
return {};
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
function buildMergedConfig(bundledConfigPath, userRules) {
|
|
29
|
+
const bundled = JSON.parse(node_fs_1.default.readFileSync(bundledConfigPath, 'utf-8'));
|
|
30
|
+
const merged = { ...bundled, ...userRules };
|
|
31
|
+
const tmpFile = node_path_1.default.join(node_os_1.default.tmpdir(), `.markdownlint-merged-${process.pid}.json`);
|
|
32
|
+
node_fs_1.default.writeFileSync(tmpFile, JSON.stringify(merged, null, 2));
|
|
33
|
+
return tmpFile;
|
|
34
|
+
}
|
|
27
35
|
async function runMarkdownLint() {
|
|
28
36
|
utils_1.logger.info('[runMarkdownLint]: 📝 Running Markdown lint...');
|
|
29
37
|
const root = process.cwd();
|
|
30
38
|
const changedFiles = await (0, delta_1.getChangedFiles)(['.md', '.mdx']);
|
|
31
39
|
const targets = changedFiles ?? [`${root}/**/*.md`];
|
|
32
40
|
const userConfig = loadUserMarkdownConfig();
|
|
33
|
-
|
|
41
|
+
const userRules = userConfig.rules ?? {};
|
|
42
|
+
const hasUserRules = Object.keys(userRules).length > 0;
|
|
34
43
|
let configArg;
|
|
44
|
+
let tempConfigFile = null;
|
|
35
45
|
if ((0, config_1.hasLocalConfig)(['.markdownlint.json', '.markdownlint.jsonc', '.markdownlint.yaml', '.markdownlint.yml'])) {
|
|
36
46
|
utils_1.logger.info('[runMarkdownLint]: 📋 Using local .markdownlint config');
|
|
37
47
|
configArg = [];
|
|
38
48
|
}
|
|
39
49
|
else {
|
|
40
50
|
const bundledConfig = (0, config_1.getPackageConfigPath)('.markdownlint.json');
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
if (hasUserRules) {
|
|
52
|
+
tempConfigFile = buildMergedConfig(bundledConfig, userRules);
|
|
53
|
+
utils_1.logger.info(`[runMarkdownLint]: 📋 Using bundled config merged with ${Object.keys(userRules).length} user rule(s)`);
|
|
54
|
+
configArg = ['--config', tempConfigFile];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
utils_1.logger.info('[runMarkdownLint]: 📋 Using pr-checkmate bundled markdownlint config');
|
|
58
|
+
configArg = ['--config', bundledConfig];
|
|
59
|
+
}
|
|
43
60
|
}
|
|
44
61
|
const extraIgnores = (userConfig.ignores ?? []).flatMap(p => ['--ignore', p]);
|
|
62
|
+
const gitignorePath = node_path_1.default.join(root, '.gitignore');
|
|
63
|
+
const ignorePath = node_fs_1.default.existsSync(gitignorePath) ? ['--ignore-path', gitignorePath] : [];
|
|
45
64
|
const args = [
|
|
46
65
|
'markdownlint',
|
|
47
66
|
...targets,
|
|
48
67
|
...configArg,
|
|
68
|
+
...ignorePath,
|
|
49
69
|
'--ignore', 'node_modules',
|
|
50
70
|
'--ignore', 'dist',
|
|
51
71
|
'--ignore', 'coverage',
|
|
52
72
|
...extraIgnores,
|
|
53
73
|
];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
try {
|
|
75
|
+
const result = await (0, execa_1.execa)('npx', args, { reject: false, stdio: 'inherit' });
|
|
76
|
+
if (result.exitCode === 0) {
|
|
77
|
+
utils_1.logger.info('[runMarkdownLint]: ✅ Markdown lint passed');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
utils_1.logger.warn('[runMarkdownLint]: ⚠️ Markdown lint found issues (see above)');
|
|
81
|
+
}
|
|
57
82
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
finally {
|
|
84
|
+
if (tempConfigFile && node_fs_1.default.existsSync(tempConfigFile)) {
|
|
85
|
+
node_fs_1.default.unlinkSync(tempConfigFile);
|
|
86
|
+
}
|
|
61
87
|
}
|
|
62
88
|
}
|