Skip to content

Commit 16e2240

Browse files
committed
Use histogram to get more relevant diffs
1 parent a0a2474 commit 16e2240

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("getDiffForFile", () => {
5656
const diffFromFile = getDiffForFile("./mockfile.js", true);
5757

5858
const expectedArguments =
59-
'git --no-pager diff --diff-filter=ACM --relative --staged --unified=0 "1234567"';
59+
'git diff --diff-algorithm=histogram --diff-filter=ACM --relative --staged --unified=0 "1234567"';
6060
expect(
6161
mockedChildProcess.execSync.mock.calls[
6262
mockedChildProcess.execSync.mock.calls.length - 1

src/git.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getDiffForFile = (filePath: string, staged = false): string => {
2323
const command = [
2424
"git",
2525
"diff",
26+
"--diff-algorithm=histogram",
2627
"--diff-filter=ACM",
2728
"--relative",
2829
staged && "--staged",
@@ -48,6 +49,7 @@ const getDiffFileList = (): string[] => {
4849
const command = [
4950
"git",
5051
"diff",
52+
"--diff-algorithm=histogram",
5153
"--diff-filter=ACM",
5254
"--name-only",
5355
"--relative",
@@ -69,7 +71,6 @@ const getDiffFileList = (): string[] => {
6971

7072
let gitFileListCache: string[] | undefined;
7173
const getGitFileList = (): string[] => {
72-
console.log("getGitFileList");
7374
if (RUNNING_INSIDE_VSCODE || gitFileListCache === undefined) {
7475
const command = ["git", "ls-files"].filter(Boolean).join(" ");
7576

src/processors.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as child_process from "child_process";
22
import type { Linter } from "eslint";
33
import { mocked } from "jest-mock";
4-
import * as git from "./git";
54
import { diff, diffConfig, staged, stagedConfig } from "./processors";
65
import {
76
diff as fixtureDiff,
@@ -11,12 +10,15 @@ import { postprocessArguments } from "./__fixtures__/postprocessArguments";
1110

1211
jest.mock("child_process");
1312
const mockedChildProcess = mocked(child_process, true);
14-
const mockFilename = '/mock filename with quotes ", semicolons ; and spaces.js';
15-
mockedChildProcess.execSync.mockReturnValue(Buffer.from(mockFilename));
16-
const mockedGit = mocked(git, true);
17-
mockedGit.getDiffFileList = jest
18-
.fn()
19-
.mockReturnValue([mockFilename, "README.md"]);
13+
mockedChildProcess.execSync.mockReturnValue(
14+
Buffer.from('/mock filename ", ; .js')
15+
);
16+
jest.mock("./git", () => ({
17+
...jest.requireActual("./git"),
18+
getDiffFileList: jest
19+
.fn()
20+
.mockReturnValue(['/mock filename ", ; .js', "README.md"]),
21+
}));
2022

2123
const [messages, filename] = postprocessArguments;
2224

src/processors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const getPostProcessor =
7575
.reduce((a, b) => a.concat(b), []);
7676
};
7777

78-
const getProcessors = (staged = false): Linter.Processor => ({
78+
const getProcessors = (staged = false): Required<Linter.Processor> => ({
7979
preprocess: getPreProcessor(staged),
8080
postprocess: getPostProcessor(staged),
8181
supportsAutofix: true,

0 commit comments

Comments
 (0)