Skip to content

Commit

Permalink
chore: lint project
Browse files Browse the repository at this point in the history
  • Loading branch information
duniul committed Feb 16, 2024
1 parent 8cf0089 commit efcc25c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/__test__/getMockedFileStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function getMockedFileStructure(): Promise<Record<string, any>> {

return {
[DEFAULT_GLOBS_FILE_PATH]: defaultGlobs,
'node_modules': {
node_modules: {
dep1: {
__tests__: {
'test1.js': '.',
Expand Down
9 changes: 3 additions & 6 deletions src/__test__/path.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ function normalizePath(str: string) {
function shouldNormalizePath(val: any) {
if (typeof val === 'string') {
return normalizePath(val) !== val;
} else if (typeof val === 'object') {
Object.keys(val).forEach(key => {
const objectValue = val[key];
return shouldNormalizePath(objectValue);
});
}

return false;
Expand All @@ -30,7 +25,9 @@ export const pathSerializer: Serializer = {
if (typeof val === 'string') {
const normalizedVal = normalizePath(val);
return printer(normalizedVal, config, indentation, depth, refs);
} else if (typeof val === 'object') {
}

if (typeof val === 'object') {
const normalizedVal = Object.fromEntries(
Object.entries(val).map(([key, value]) => [
key,
Expand Down
3 changes: 1 addition & 2 deletions src/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ describe(analyze.name, () => {
},
]
`);
})

});

it('accepts custom globs', async () => {
const result = await analyze({ globs: ['**/nonDefaultFile.ext'] });
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export async function analyze(options: AnalyzeOptions = {}): Promise<AnalyzeResu
const includedByDefault = includedByDefaultMatcher(filePath);
const includedByGlobs: { original: string; derived: string }[] = [];

globMatchers.forEach(({ original, derived, matcher }) => {
for (const { original, derived, matcher } of globMatchers) {
if (matcher(filePath)) {
includedByGlobs.push({ original, derived });
}
});
}

return { filePath, includedByDefault, includedByGlobs };
});
Expand Down
2 changes: 1 addition & 1 deletion src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function clean(options: CleanOptions = {}): Promise<CleanResult> {
const globLists = await getGlobLists({ globs, noDefaults, globFile });
const files = await findFilesByGlobLists(directory, globLists);
const reducedSize = await removeFiles(files, { dryRun });
const removedEmptyDirs = (dryRun || keepEmpty) ? 0 : await removeEmptyDirs(files);
const removedEmptyDirs = dryRun || keepEmpty ? 0 : await removeEmptyDirs(files);

return { files, reducedSize, removedEmptyDirs };
}
4 changes: 3 additions & 1 deletion src/utils/filesystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ describe('removeEmptyDirs', () => {
];

// remove files before testing
filePaths.forEach(filePath => fs.unlinkSync(filePath));
for (const filePath of filePaths) {
fs.unlinkSync(filePath);
}

await removeEmptyDirs(filePaths);

Expand Down
3 changes: 1 addition & 2 deletions src/utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export async function removeEmptyDirs(filePaths: string[]): Promise<number> {
return removedEmptyDirs;
}


/**
* Find all files in a directory as fast as possible, without any extra checks or validations.
*/
Expand Down Expand Up @@ -152,7 +151,7 @@ export async function crawlDirWithChecks(

export type RemoveFilesOptions = {
dryRun?: boolean;
}
};

/**
* Removes files and returns the total size of the removed files.
Expand Down
14 changes: 8 additions & 6 deletions src/utils/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ export function optimizeGlobs(globs: string[]): string[] {
const globstarStartGlobs: string[] = [];
const fixedPathGlobs: string[] = [];

globs.forEach(glob => {
for (const glob of globs) {
if (glob.match(GLOBSTAR_START_REGEX)) {
globstarStartGlobs.push(glob);
} else {
fixedPathGlobs.push(glob);
}
});
}

const result: string[] = [];

Expand Down Expand Up @@ -158,13 +158,15 @@ export function formatGlob(glob: string): string {
export function processGlobs(globs: string[]): GlobLists {
const globLists = initGlobLists();

globs.forEach(glob => {
for (const glob of globs) {
const isExcluded = !!glob.match(EXCLAMATION_START);
const formattedGlob = formatGlob(glob);

if (!formattedGlob) {
return;
} else if (isExcluded) {
continue;
}

if (isExcluded) {
globLists.excluded.push(formattedGlob);
} else {
if (formattedGlob.endsWith('/**')) {
Expand All @@ -174,7 +176,7 @@ export function processGlobs(globs: string[]): GlobLists {
globLists.included.push(formattedGlob);
globLists.originalIncluded.push(glob.trim());
}
});
}

return globLists;
}
Expand Down

0 comments on commit efcc25c

Please sign in to comment.