Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-dockerignore-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@docker-doctor/cli": patch
---

Fix workspace discovery to correctly track and validate `.dockerignore` files, resolving false-positive warnings in the `useDockerignore` performance rule.
6 changes: 6 additions & 0 deletions packages/core/src/project-info/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ export const discoverProject = async (
const allFiles = await walk(rootDir);
const dockerfiles: string[] = [];
const composeFiles: string[] = [];
const dockerignores: string[] = [];

for (const file of allFiles) {
const base = path.basename(file).toLowerCase();

if (base === ".dockerignore") {
dockerignores.push(path.relative(rootDir, file));
}

// Match Dockerfile, Dockerfile.*, *.dockerfile
if (
base === "dockerfile" ||
Expand All @@ -65,5 +70,6 @@ export const discoverProject = async (
return {
composeFiles,
dockerfiles,
dockerignores,
};
};
1 change: 1 addition & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Diagnostic {
export interface ProjectInfo {
dockerfiles: string[];
composeFiles: string[];
dockerignores?: string[];
}

export interface DiagnoseResult {
Expand Down
37 changes: 24 additions & 13 deletions packages/docker-doctor/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,25 @@ const runRulesEngine = async (
return diagnostics;
};

const filterDiagnostics = (
diagnostics: Diagnostic[],
categories?: Record<string, RuleSeverity>
): Diagnostic[] => {
if (!categories) {
return diagnostics;
}
return diagnostics.filter((d) => {
const ruleDef = findRule(d.rule);
if (ruleDef) {
const catSeverity = categories[ruleDef.category];
if (catSeverity === "off") {
return false;
}
}
return true;
});
};

const program = new Command();

program
Expand Down Expand Up @@ -417,6 +436,7 @@ program
const projectFilesList = [
...project.dockerfiles,
...project.composeFiles,
...(project.dockerignores || []),
];

const diagnostics = await runRulesEngine(
Expand All @@ -430,19 +450,10 @@ program
);

// Filter by category config if needed
let filteredDiagnostics = diagnostics;
if (config.categories) {
filteredDiagnostics = diagnostics.filter((d) => {
const ruleDef = findRule(d.rule);
if (ruleDef) {
const catSeverity = config.categories?.[ruleDef.category];
if (catSeverity === "off") {
return false;
}
}
return true;
});
}
const filteredDiagnostics = filterDiagnostics(
diagnostics,
config.categories
);

// Calculate score
const { score, label } = calculateScore(filteredDiagnostics);
Expand Down
Loading