Skip to content

Commit 42708f7

Browse files
committed
Fix typescript-eslint
1 parent ec3cec3 commit 42708f7

File tree

2 files changed

+92
-21
lines changed

2 files changed

+92
-21
lines changed

src/git.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ const getDiffFileList = (staged = false): string[] => {
6363
return diffFileListCache;
6464
};
6565

66+
let gitFileListCache: string[];
67+
const getGitFileList = (): string[] => {
68+
if (gitFileListCache === undefined) {
69+
const command = ["git", "ls-files"].filter(Boolean).join(" ");
70+
71+
gitFileListCache = child_process
72+
.execSync(command)
73+
.toString()
74+
.trim()
75+
.split("\n")
76+
.map((filePath) => path.resolve(filePath));
77+
}
78+
return gitFileListCache;
79+
};
80+
81+
const getIgnorePatterns = (staged = false): string[] => {
82+
const diffFileList = getDiffFileList(staged);
83+
const gitFileList = getGitFileList();
84+
// console.log({diffFileList, gitFileList})
85+
86+
const newList = gitFileList.filter((x) => !diffFileList.includes(x));
87+
const willBeChecked = gitFileList.filter((x) => diffFileList.includes(x));
88+
89+
// throw new Error("Function not implemented.");
90+
const result = newList.map((x) =>
91+
path.join("/", path.relative(process.cwd(), x))
92+
);
93+
94+
console.log({ willBeChecked });
95+
return result;
96+
};
97+
6698
const isHunkHeader = (input: string) => {
6799
const hunkHeaderRE = new RegExp(/^@@ .* @@/g);
68100
return input.match(hunkHeaderRE);
@@ -106,5 +138,11 @@ const getRangesForDiff = (diff: string): Range[] => {
106138
.filter(removeNullRanges);
107139
};
108140

109-
export { getDiffForFile, getRangesForDiff, getDiffFileList };
141+
export {
142+
getDiffForFile,
143+
getGitFileList,
144+
getIgnorePatterns,
145+
getRangesForDiff,
146+
getDiffFileList,
147+
};
110148
export type { Range };

src/processors.ts

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
import type { Linter } from "eslint";
2-
import type { Range } from "./git";
3-
import { getDiffFileList, getDiffForFile, getRangesForDiff } from "./git";
2+
import { getDiffFileList, getDiffForFile, getIgnorePatterns, getRangesForDiff, Range } from "./git";
3+
44

55
const STAGED = true;
66

77
const isLineWithinRange = (line: number) => (range: Range) =>
88
range.isWithinRange(line);
99

10-
const diff = {
11-
preprocess: (
12-
text: string,
13-
filename: string
14-
): { text: string; filename: string }[] =>
15-
getDiffFileList().includes(filename) ? [{ text, filename }] : [],
1610

11+
12+
const diff = {
1713
postprocess: (
1814
messages: Linter.LintMessage[][],
1915
filename: string
20-
): Linter.LintMessage[] =>
21-
messages
22-
.map((message) =>
23-
message.filter(({ line }) =>
24-
getRangesForDiff(getDiffForFile(filename)).some(
25-
isLineWithinRange(line)
26-
)
27-
)
28-
)
29-
.reduce((a, b) => a.concat(b), []),
16+
): Linter.LintMessage[] => {
17+
if (!getDiffFileList().includes(filename)) {
18+
console.log(
19+
"🧠 skipping " +
20+
JSON.stringify(filename) +
21+
" because it's not in the diff list"
22+
);
23+
return [];
24+
}
25+
const result = messages
26+
.map((message) => {
27+
console.log("diff/diff", message, JSON.stringify(filename));
28+
return message.filter(({ fatal, line }) => {
29+
if (fatal) {
30+
console.log("❌ fatal error in " + JSON.stringify(filename));
31+
return fatal;
32+
}
33+
34+
if (
35+
!getRangesForDiff(getDiffForFile(filename)).some(
36+
isLineWithinRange(line)
37+
)
38+
) {
39+
console.log(
40+
"🔵 skipping " +
41+
JSON.stringify(filename) +
42+
" because it's not in the diff list"
43+
);
44+
}
45+
46+
return (
47+
fatal ||
48+
getRangesForDiff(getDiffForFile(filename)).some(
49+
isLineWithinRange(line)
50+
)
51+
);
52+
});
53+
})
54+
.reduce((a, b) => a.concat(b), []);
55+
console.log("diff kjrngkjsngksnj", { result, filename, messages });
56+
return result;
57+
},
3058

3159
supportsAutofix: true,
3260
};
@@ -39,14 +67,19 @@ const diffConfig = {
3967
processor: "diff/diff",
4068
},
4169
],
70+
ignorePatterns: getIgnorePatterns()
4271
};
4372

4473
const staged = {
4574
preprocess: (
4675
text: string,
4776
filename: string
48-
): { text: string; filename: string }[] =>
49-
getDiffFileList(STAGED).includes(filename) ? [{ text, filename }] : [],
77+
): ({ text: string; filename: string } & Record<any, any>)[] => {
78+
console.log({ text: text, filename: filename, lol: "zooooooooooomg" });
79+
return getDiffFileList(STAGED).includes(filename)
80+
? [{ text, filename }]
81+
: [];
82+
},
5083

5184
postprocess: (
5285
messages: Linter.LintMessage[][],

0 commit comments

Comments
 (0)