feat: package Pi extensions as Bun workspaces
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
id: typescript-no-dynamic-import-ts
|
||||
language: TypeScript
|
||||
severity: warning
|
||||
message: Avoid dynamic imports unless runtime loading is intentional.
|
||||
rule:
|
||||
pattern: import($MODULE)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
id: typescript-no-dynamic-import-tsx
|
||||
language: Tsx
|
||||
severity: warning
|
||||
message: Avoid dynamic imports unless runtime loading is intentional.
|
||||
rule:
|
||||
pattern: import($MODULE)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
id: typescript-no-non-null-assertion-ts
|
||||
language: TypeScript
|
||||
severity: warning
|
||||
message: Avoid TypeScript non-null assertions.
|
||||
rule:
|
||||
kind: non_null_expression
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
id: typescript-no-non-null-assertion-tsx
|
||||
language: Tsx
|
||||
severity: warning
|
||||
message: Avoid TypeScript non-null assertions.
|
||||
rule:
|
||||
kind: non_null_expression
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { VerificationPolicy } from "@_jb/pi-native-hooks/policy";
|
||||
const manifests = new Set(["package.json", "bun.lock", "tsconfig.json"]);
|
||||
const behavior = (path: string) => /^(extensions|scripts|services|skills|config)\//.test(path) || manifests.has(path);
|
||||
const types = (path: string) => /\.tsx?$/.test(path) || manifests.has(path);
|
||||
export default { kind: "verification", id: "harness-tools-verification", project: { matches: (project) => project.packageName === "harness-tools" }, requirements: [
|
||||
{ id: "tests", command: "bun run test", cwd: "project-root", affects: behavior },
|
||||
{ id: "typecheck", command: "bun run typecheck", cwd: "project-root", affects: types },
|
||||
] } satisfies VerificationPolicy;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { VerificationPolicy } from "@_jb/pi-native-hooks/policy";
|
||||
const manifests = new Set(["package.json", "bun.lock", "tsconfig.json"]);
|
||||
const behavior = (path: string) => /^(extensions|src|tests|examples|skills)\//.test(path) || manifests.has(path);
|
||||
const types = (path: string) => /\.tsx?$/.test(path) || manifests.has(path);
|
||||
export default { kind: "verification", id: "pi-native-hooks-verification", project: { matches: (project) => project.packageName === "@_jb/pi-native-hooks" }, requirements: [
|
||||
{ id: "tests", command: "bun run test", cwd: "project-root", affects: behavior },
|
||||
{ id: "typecheck", command: "bun run typecheck", cwd: "project-root", affects: types },
|
||||
] } satisfies VerificationPolicy;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import type { DiagnosticPolicy } from "@_jb/pi-native-hooks/policy";
|
||||
const ruleIds = new Set(["typescript-no-dynamic-import-ts", "typescript-no-dynamic-import-tsx"]);
|
||||
export default {
|
||||
kind: "diagnostic", id: "typescript-no-dynamic-import", analyzerKeys: ["ast-grep:personal"],
|
||||
appliesTo: (_project, paths) => paths.some((path) => /\.tsx?$/.test(path)),
|
||||
evaluate: (analysis) => (analysis.get("ast-grep:personal")?.findings ?? []).filter((finding) => ruleIds.has(finding.ruleId)).map((finding) => ({ policyId: "typescript-no-dynamic-import", ruleId: finding.ruleId, path: finding.path, line: finding.range.start.line, column: finding.range.start.column, message: finding.message, guidance: "Prefer a static import unless lazy loading, code splitting, an optional dependency, or runtime module selection is intentional.", exception: `Use ast-grep-ignore: ${finding.ruleId} -- <short rationale> for an intentional dynamic import.`, matchedTextHash: finding.matchedTextHash })),
|
||||
} satisfies DiagnosticPolicy;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import type { DiagnosticPolicy } from "@_jb/pi-native-hooks/policy";
|
||||
const ruleIds = new Set(["typescript-no-non-null-assertion-ts", "typescript-no-non-null-assertion-tsx"]);
|
||||
export default {
|
||||
kind: "diagnostic", id: "typescript-no-non-null-assertion", analyzerKeys: ["ast-grep:personal"],
|
||||
appliesTo: (_project, paths) => paths.some((path) => /\.tsx?$/.test(path)),
|
||||
evaluate: (analysis) => (analysis.get("ast-grep:personal")?.findings ?? []).filter((finding) => ruleIds.has(finding.ruleId)).map((finding) => ({ policyId: "typescript-no-non-null-assertion", ruleId: finding.ruleId, path: finding.path, line: finding.range.start.line, column: finding.range.start.column, message: finding.message, guidance: "Prefer a guard, refinement, assertion function, or corrected type.", exception: `Use ast-grep-ignore: ${finding.ruleId} -- <short rationale> when the invariant is intentional.`, matchedTextHash: finding.matchedTextHash })),
|
||||
} satisfies DiagnosticPolicy;
|
||||
@@ -0,0 +1,2 @@
|
||||
ruleDirs:
|
||||
- ast-grep/rules
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"target": "ES2023",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"allowImportingTsExtensions": true,
|
||||
"paths": { "@_jb/pi-native-hooks/policy": ["__PI_NATIVE_HOOKS_PACKAGE_ROOT__/src/policy.ts"] }
|
||||
},
|
||||
"include": ["policies/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user