-
Notifications
You must be signed in to change notification settings - Fork 16
Keep tracked files instead of refreshing list of untracked files #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { | |
getDiffFileList, | ||
getDiffForFile, | ||
getRangesForDiff, | ||
getUntrackedFileList, | ||
getTrackedFileList, | ||
hasCleanIndex, | ||
} from "./git"; | ||
import type { Range } from "./Range"; | ||
|
@@ -28,18 +28,12 @@ if (process.env.CI !== undefined) { | |
* This is increasingly useful the more files there are in the repository. | ||
*/ | ||
const getPreProcessor = | ||
(diffFileList: string[], staged: boolean) => | ||
(trackedFileSet: Set<string>, diffFileList: string[]) => | ||
(text: string, filename: string) => { | ||
let untrackedFileList = getUntrackedFileList(staged); | ||
const shouldRefresh = | ||
!diffFileList.includes(filename) && !untrackedFileList.includes(filename); | ||
Comment on lines
-34
to
-35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition not only matches new files but actually all unchanged files, so instead of speeding things up this actually slows the entire lint process. |
||
if (shouldRefresh) { | ||
untrackedFileList = getUntrackedFileList(staged, true); | ||
} | ||
const shouldBeProcessed = | ||
process.env.VSCODE_PID !== undefined || | ||
diffFileList.includes(filename) || | ||
untrackedFileList.includes(filename); | ||
!trackedFileSet.has(filename); | ||
|
||
return shouldBeProcessed ? [text] : []; | ||
}; | ||
|
@@ -72,7 +66,7 @@ const getUnstagedChangesError = (filename: string): [Linter.LintMessage] => { | |
}; | ||
|
||
const getPostProcessor = | ||
(staged: boolean) => | ||
(trackedFileSet: Set<string>, staged: boolean) => | ||
( | ||
messages: Linter.LintMessage[][], | ||
filename: string | ||
|
@@ -81,8 +75,7 @@ const getPostProcessor = | |
// No need to filter, just return | ||
return []; | ||
} | ||
const untrackedFileList = getUntrackedFileList(staged); | ||
if (untrackedFileList.includes(filename)) { | ||
if (!trackedFileSet.has(filename)) { | ||
// We don't need to filter the messages of untracked files because they | ||
// would all be kept anyway, so we return them as-is. | ||
return messages.flat(); | ||
|
@@ -117,11 +110,12 @@ const getProcessors = ( | |
processorType: ProcessorType | ||
): Required<Linter.Processor> => { | ||
const staged = processorType === "staged"; | ||
const trackedFileSet = new Set(getTrackedFileList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wrapping this in a |
||
const diffFileList = getDiffFileList(staged); | ||
|
||
return { | ||
preprocess: getPreProcessor(diffFileList, staged), | ||
postprocess: getPostProcessor(staged), | ||
preprocess: getPreProcessor(trackedFileSet, diffFileList), | ||
postprocess: getPostProcessor(trackedFileSet, staged), | ||
supportsAutofix: true, | ||
}; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the tests also works with a file called
file-with-dirty-index.js
so we have to add it to the "tracked" list too.