Skip to content
Merged
2 changes: 1 addition & 1 deletion @binkylabs/muzzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"vitest": "^4.0.16"
},
"dependencies": {
"@typespec/compiler": "^1.7.1"
"@typespec/compiler": "^1.8.0-dev.6"
},
"engines": {
"node": ">=20.0.0"
Expand Down
12 changes: 8 additions & 4 deletions @binkylabs/muzzle/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,28 @@ model Foo {
it("should add suppress directives before model keyword when using 'is' keyword", async () => {
const inputTypeSpec = `namespace OpenAI;

/** A Foo model */
model Foo {
}

/** A Bar model */
model Bar {
}

model FooBarArray is (Foo | Bar)[];
/** A model that is a union of Foo and Bar in an array */
model FooBarArray
is (Foo | Bar)[];
`;

const expectedOutput = `namespace OpenAI;

#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
/** A Foo model */
model Foo {}

#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
/** A Bar model */
model Bar {}

#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
/** A model that is a union of Foo and Bar in an array */
#suppress "@azure-tools/typespec-azure-core/no-unnamed-union" "Auto-suppressed warnings non-applicable rules during import."
model FooBarArray is (Foo | Bar)[];
`;
Expand Down
36 changes: 4 additions & 32 deletions @binkylabs/muzzle/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { existsSync } from "node:fs";
import {
compile as typespecCompile,
createSuppressCodeFix,
DiagnosticTarget,
createSuppressCodeFixes,
NodeHost,
NoTarget,
Program,
resolveCompilerOptions,
applyCodeFixes,
formatTypeSpec,
CompilerOptions,
} from "@typespec/compiler";

import { findSuppressTarget } from "./typespec-imports.js";

/**
* Adds suppress directives for all warnings in the TypeSpec program.
* @param p The TypeSpec program
Expand All @@ -24,33 +20,9 @@ export async function suppressEverything(
p: Program,
options: Partial<Omit<SuppressionOptions, "entryPoint" | "ruleSets">> = {},
) {
const codeFixes = Array.from(
Map.groupBy(
p.diagnostics
.filter(
(diag) => diag.severity === "warning" && diag.target !== NoTarget,
)
.map((diag) => {
const suppressTarget = findSuppressTarget(
diag.target as DiagnosticTarget,
);
const groupingKey = suppressTarget
? `${diag.code}-${suppressTarget.file.path}-${suppressTarget.pos}-${suppressTarget.end}`
: `no-target-${diag.code}`;
return {
groupingKey: groupingKey,
fix: createSuppressCodeFix(
diag.target as DiagnosticTarget,
diag.code,
options.message ||
"Warnings auto-suppressed by @binkylabs/muzzle.",
),
};
}),
(fix) => fix.groupingKey,
)
.entries()
.map((group) => group[1][0].fix),
const codeFixes = createSuppressCodeFixes(
p.diagnostics,
options.message || "Warnings auto-suppressed by @binkylabs/muzzle.",
);
await applyCodeFixes(p.host, codeFixes);
}
Expand Down
42 changes: 0 additions & 42 deletions @binkylabs/muzzle/src/typespec-imports.ts

This file was deleted.

3 changes: 2 additions & 1 deletion @binkylabs/muzzle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
/* Linting */
"strict": true
},
"include": ["src", "test", "vitest.d.ts"]
"include": ["src", "vitest.d.ts"],
"exclude": ["**/*.test.ts", "test-fixtures"]
}
4 changes: 3 additions & 1 deletion @binkylabs/muzzle/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default defineConfig({
test: {
globals: true,
environment: "node",
testTimeout: 30000, // 30 seconds for slow TypeSpec compilation
testTimeout: 30000, // 30 seconds for slow TypeSpec compilation,
include: ["**/*.test.ts", "**/*.spec.ts"],
exclude: ["**/node_modules/**", "**/dist/**"],
},
});
49 changes: 43 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"main": "index.js",
"scripts": {
"test": "npm --workspace @binkylabs/muzzle run test",
"test:watch": "npm --workspace @binkylabs/muzzle run test:watch",
"build": "npm --workspace @binkylabs/muzzle run build",
"lint": "npm --workspace @binkylabs/muzzle run lint",
"format": "npm --workspace @binkylabs/muzzle run format",
Expand Down