semlint-cli 0.1.2 → 0.1.3
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.
- package/dist/git.js +12 -26
- package/dist/main.js +1 -1
- package/package.json +1 -1
package/dist/git.js
CHANGED
|
@@ -36,29 +36,6 @@ async function getGitDiff(base, head) {
|
|
|
36
36
|
const result = await runGitCommand(["diff", base, head]);
|
|
37
37
|
return result.stdout;
|
|
38
38
|
}
|
|
39
|
-
function isMissingRefError(message) {
|
|
40
|
-
return /(not a valid object name|unknown revision|bad revision|no upstream configured|no upstream branch)/i.test(message);
|
|
41
|
-
}
|
|
42
|
-
async function resolveLocalComparisonBase() {
|
|
43
|
-
const candidates = ["@{upstream}", "origin/main", "main"];
|
|
44
|
-
for (const candidate of candidates) {
|
|
45
|
-
try {
|
|
46
|
-
const result = await runGitCommand(["merge-base", "HEAD", candidate]);
|
|
47
|
-
const mergeBase = result.stdout.trim();
|
|
48
|
-
if (mergeBase !== "") {
|
|
49
|
-
return mergeBase;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
54
|
-
if (!isMissingRefError(message)) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return "HEAD";
|
|
61
|
-
}
|
|
62
39
|
async function getUntrackedFiles() {
|
|
63
40
|
const result = await runGitCommand(["ls-files", "--others", "--exclude-standard"]);
|
|
64
41
|
return result.stdout
|
|
@@ -70,9 +47,16 @@ async function getNoIndexDiffForFile(filePath) {
|
|
|
70
47
|
const result = await runGitCommand(["diff", "--no-index", "--", node_os_1.devNull, filePath], [0, 1]);
|
|
71
48
|
return result.stdout;
|
|
72
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the diff for the current branch limited to:
|
|
52
|
+
* - Staged changes (--cached: index vs HEAD)
|
|
53
|
+
* - Unstaged changes (working tree vs index)
|
|
54
|
+
* - Untracked files (as full-file diffs)
|
|
55
|
+
* Does not include already-committed changes on the branch.
|
|
56
|
+
*/
|
|
73
57
|
async function getLocalBranchDiff() {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
58
|
+
const stagedResult = await runGitCommand(["diff", "--cached"]);
|
|
59
|
+
const unstagedResult = await runGitCommand(["diff"]);
|
|
76
60
|
const untrackedFiles = await getUntrackedFiles();
|
|
77
61
|
const untrackedDiffChunks = [];
|
|
78
62
|
for (const filePath of untrackedFiles) {
|
|
@@ -81,5 +65,7 @@ async function getLocalBranchDiff() {
|
|
|
81
65
|
untrackedDiffChunks.push(fileDiff);
|
|
82
66
|
}
|
|
83
67
|
}
|
|
84
|
-
return [
|
|
68
|
+
return [stagedResult.stdout, unstagedResult.stdout, ...untrackedDiffChunks]
|
|
69
|
+
.filter((chunk) => chunk !== "")
|
|
70
|
+
.join("\n");
|
|
85
71
|
}
|
package/dist/main.js
CHANGED
|
@@ -91,7 +91,7 @@ async function runSemlint(options) {
|
|
|
91
91
|
const diff = await timedAsync(config.debug, "Computed git diff", () => useLocalBranchDiff ? (0, git_1.getLocalBranchDiff)() : (0, git_1.getGitDiff)(config.base, config.head));
|
|
92
92
|
const changedFiles = timed(config.debug, "Parsed changed files from diff", () => (0, filter_1.extractChangedFilesFromDiff)(diff));
|
|
93
93
|
debugLog(config.debug, useLocalBranchDiff
|
|
94
|
-
? "Using local branch diff (
|
|
94
|
+
? "Using local branch diff (staged + unstaged + untracked only)"
|
|
95
95
|
: `Using explicit ref diff (${config.base}..${config.head})`);
|
|
96
96
|
debugLog(config.debug, `Detected ${changedFiles.length} changed file(s)`);
|
|
97
97
|
const backend = timed(config.debug, "Initialized backend runner", () => (0, backend_1.createBackendRunner)(config));
|