-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Consider Parsing .gitignore #1319
Comments
yes please, this would be awesome to have |
I believe this could be done using something like [email protected]. |
I agree that it is very useful. Parsing the file is easy. The internal The issue is the logic around loading the
When processing Also needed:
It is not a lot of code, it is more the time to make sure it is correct. |
Thank you for the thoughtful guidance! That makes good sense. How would you feel about the notion of running git-check-ignore and only supporting this feature when Git is installed? According to that documentation there is quite a lot more complexity involved in matching Git's behavior than I had realized (e.g., handling the |
This is how we are handling files ignored by git (including import spawnAsync from '@expo/spawn-async';
import path, { dirname } from 'path';
import { readdirSync, statSync } from 'fs';
import simpleGit from 'simple-git';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const git = simpleGit();
const files: string[] = [];
async function throughDirectory(directory: string): Promise<void> {
for (const file of readdirSync(directory)) {
const absolutePath = path.join(directory, file);
await new Promise<void>((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
git.checkIgnore(absolutePath, async (error: unknown, data?: string[]) => {
if (error || !data) throw error;
if (data.length === 0) {
//not ignored
if (statSync(absolutePath).isDirectory()) await throughDirectory(absolutePath);
else files.push(absolutePath);
}
resolve();
});
});
}
}
const getNotIgnoredFiles = async (): Promise<string[]> => {
await throughDirectory(path.resolve(__dirname, '..'));
return files;
};
const shouldChunkFiles = (): boolean => {
return process.platform === 'win32';
};
const checkFileSpelling = async (files: string[]): Promise<void> => {
const resultPromise = spawnAsync('cspell', files);
try {
const { stdout, stderr } = await resultPromise;
// when there is NO issue found
console.log(stdout, stderr);
} catch (e) {
// when there is issue found
const { stdout, stderr } = e;
console.log(stdout, stderr);
if (stdout !== '' && process.env.CI === 'true') {
// when the issue is reported (e.g. when the word is NOT ignored)
// use fail-fast approach for CI only
process.exit(e.status);
}
}
};
const notIgnoredFiles = await getNotIgnoredFiles();
if (shouldChunkFiles()) {
notIgnoredFiles.forEach((file: string): Promise<void> => checkFileSpelling([file]));
} else {
await checkFileSpelling(notIgnoredFiles);
} In short:
One downside is terrible performance on Windows, because when we spawn cspell - |
@Maxim-Mazurok, I may have misinterpreted your message, but it sounds like you are asking for a feature that @Jason3S already implemented? If I got that right, cspell's release cycle is typically very short, so I would encourage you to give the new support for .gitignore when it comes out in a few days. In case you are on an even tighter timeline, cspell has long offered an |
@Kurt-von-Laven, #1823 adds support for My solution uses an actual git client to determine if the file is ignored or not. My message had two objectives:
|
Oh, ha ha, that seems a lot more obvious in retrospect, but thank you for spelling it out for me. |
@Kurt-von-Laven and @Maxim-Mazurok, Thank you for the lively discussion. I implemented a basic @Maxim-Mazurok, thank you for sharing your solution. Hitting command-line limits is annoying. Please make a New Feature request on ways that would help you. I.e. Other than |
Excited to try it out! Yes, speaking only for one project, parsing |
I definitely agree about 80/20 and appreciate that you added gitignore support! I just usually try to hit 100 in my projects when I have resources :D So, I created feature request #1850 to accept stdio, I think it'll help. If you need use-case example - imagine someone using Local History plugin for VS Code. It creates Probably this use-case can be worked around by adding |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is a convenience feature I have appreciated in a few other actions that cuts down on the number of separate exclude lists downstream projects have to maintain. The idea is to have a boolean parameter that tells the action whether you want to automatically exclude everything in the .gitignore file.
The text was updated successfully, but these errors were encountered: