@sujithx1/optimizeguard 1.0.2 โ†’ 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,69 @@
1
- To install dependencies:
2
- ```sh
3
- bun install
4
- ```
1
+ # ๐Ÿš€ OptimizeGuard
2
+
3
+ OptimizeGuard is a lightweight **code optimization guard** that helps developers check whether their code is **optimized, safe, and type-correct before committing or pushing**.
4
+
5
+ It runs with **one simple command** and gives **clear, human-readable feedback** โ€” no complex setup needed.
6
+
7
+ ---
8
+
9
+ ## ๐ŸŒŸ Why OptimizeGuard?
10
+
11
+ Many code issues are found **after pushing** or during **code review**.
12
+ OptimizeGuard catches them **early**, right on your machine.
13
+
14
+ โœ” Faster feedback
15
+ โœ” Cleaner commits
16
+ โœ” Better code quality
17
+ โœ” Developer-friendly output
18
+
19
+ ---
20
+
21
+ ## ๐Ÿ” What does it check?
22
+
23
+ ### โšก Performance
24
+ - `await` inside loops
25
+ - Blocking or inefficient patterns
26
+
27
+ ### ๐Ÿง  Type Safety
28
+ - Usage of `any`
29
+ - Unsafe or missing TypeScript types
30
+
31
+ ### ๐Ÿ” Security
32
+ - Hardcoded secrets
33
+ - `eval()` and unsafe executions
34
+
35
+ ### ๐Ÿงน Code Quality
36
+ - Common anti-patterns
37
+ - Unoptimized logic hints
38
+
39
+ ---
40
+
41
+ ## ๐Ÿ“ฆ Installation
42
+
43
+ ```bash
44
+ npm install -g @sujithx1/optimizeguard
45
+
46
+
47
+ โ–ถ๏ธ Usage
48
+ optimizeguard
49
+
50
+ Example output
51
+ โŒ OptimizeGuard failed
52
+
53
+ โ€ข Performance issue: await inside loop (src/api/user.ts)
54
+ โ€ข Type issue: usage of 'any' (src/services/auth.ts)
55
+
56
+ Fix the issues and try again.
57
+
58
+
59
+ If everything is good:
60
+ โœ… OptimizeGuard passed
61
+ Your code is optimized and safe to commit ๐ŸŽ‰
62
+
63
+
64
+ ๐Ÿ”— Use as Pre-Commit Hook (Recommended)
65
+
66
+ Automatically block bad commits.
67
+ npx husky add .husky/pre-commit "optimizeguard"
5
68
 
6
- To run:
7
- ```sh
8
- bun run dev
9
- ```
10
69
 
11
- open http://localhost:3000
package/bun.lock CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "lockfileVersion": 1,
3
+ "configVersion": 0,
3
4
  "workspaces": {
4
5
  "": {
5
6
  "name": "sdk-server",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sujithx1/optimizeguard",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
 
6
6
  "bin": {
package/sdk.md CHANGED
@@ -1,5 +1,5 @@
1
- 84f314b3ed646e5b431a36dd5aae66d0e10c67e5397c25c4b6ca3b58b6626d0f
2
- 9130c7d5e62160aaa72e33696b4282ed4b9f73f2a8e13925caaaf167fd0de31f
3
- d2456011201d030099de954eda56a8be9ab94d32e87241b19cbce98ad7a1d410
4
- c2b041f9d8a7f333350d8233c4357eaa3398ccc51aa3dd2d20dc46c552450947
1
+ 84f314b3ed646e5b431a36dd5aae66d0e10c67e5397c25c4b6ca3b58b6626d0f
2
+ 9130c7d5e62160aaa72e33696b4282ed4b9f73f2a8e13925caaaf167fd0de31f
3
+ d2456011201d030099de954eda56a8be9ab94d32e87241b19cbce98ad7a1d410
4
+ c2b041f9d8a7f333350d8233c4357eaa3398ccc51aa3dd2d20dc46c552450947
5
5
  56bea1d7da7273c042fef8764f82e7e6e89e36e32abdf40f9f320bf5be9e8ab7
package/src/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
- import { runOptimizeGuard } from "./engine.js";
3
-
4
- const result = await runOptimizeGuard();
5
-
6
- if (!result.ok) process.exit(1);
2
+ import { runOptimizeGuard } from "./engine.js";
3
+
4
+ const result = await runOptimizeGuard();
5
+
6
+ if (!result.ok) process.exit(1);
package/src/engine.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { scanProject } from "./scanner.js";
2
- import { runRules } from "./rules/index.js";
3
- import { report } from "./rules/reporter.js";
4
-
5
- export async function runOptimizeGuard() {
6
- console.log("โšก OptimizeGuard v1 running...\n");
7
-
8
- const files = await scanProject();
9
- const issues = await runRules(files);
10
-
11
- report(issues);
12
-
13
- return { ok: issues.length === 0 };
14
- }
1
+ import { scanProject } from "./scanner.js";
2
+ import { runRules } from "./rules/index.js";
3
+ import { report } from "./rules/reporter.js";
4
+
5
+ export async function runOptimizeGuard() {
6
+ console.log("โšก OptimizeGuard v1 running...\n");
7
+
8
+ const files = await scanProject();
9
+ const issues = await runRules(files);
10
+
11
+ report(issues);
12
+
13
+ return { ok: issues.length === 0 };
14
+ }
@@ -1,16 +1,16 @@
1
- import { perfRules } from "./performance";
2
- import { securityRules } from "./security";
3
- import { typeRules } from "./type";
4
-
5
- export async function runRules(files: string[]) {
6
- const all = [...perfRules, ...securityRules, ...typeRules];
7
- const issues: any[] = [];
8
-
9
- for (const file of files) {
10
- for (const rule of all) {
11
- issues.push(...(await rule.check(file)));
12
- }
13
- }
14
-
15
- return issues;
16
- }
1
+ import { perfRules } from "./performance";
2
+ import { securityRules } from "./security";
3
+ import { typeRules } from "./type";
4
+
5
+ export async function runRules(files: string[]) {
6
+ const all = [...perfRules, ...securityRules, ...typeRules];
7
+ const issues: any[] = [];
8
+
9
+ for (const file of files) {
10
+ for (const rule of all) {
11
+ issues.push(...(await rule.check(file)));
12
+ }
13
+ }
14
+
15
+ return issues;
16
+ }
@@ -1,12 +1,12 @@
1
- import * as fs from "fs";
2
- export const perfRules = [
3
- {
4
- name: "await-in-loop",
5
- async check(file: string) {
6
- const content = fs.readFileSync(file, "utf8");
7
- return /for\s*\(.*\)\s*{[\s\S]*await/.test(content)
8
- ? [{ type: "PERF", file, msg: "await inside loop" }]
9
- : [];
10
- },
11
- },
12
- ];
1
+ import * as fs from "fs";
2
+ export const perfRules = [
3
+ {
4
+ name: "await-in-loop",
5
+ async check(file: string) {
6
+ const content = fs.readFileSync(file, "utf8");
7
+ return /for\s*\(.*\)\s*{[\s\S]*await/.test(content)
8
+ ? [{ type: "PERF", file, msg: "await inside loop" }]
9
+ : [];
10
+ },
11
+ },
12
+ ];
@@ -1,9 +1,9 @@
1
- export function report(issues: any[]) {
2
- if (!issues.length) return console.log("โœ… Code is optimized and safe!\n");
3
-
4
- for (const i of issues) {
5
- console.log(`โŒ [${i.type}] ${i.msg} โ†’ ${i.file}`);
6
- }
7
-
8
- console.log(`\nScore: ${Math.max(0, 100 - issues.length * 5)} / 100`);
9
- }
1
+ export function report(issues: any[]) {
2
+ if (!issues.length) return console.log("โœ… Code is optimized and safe!\n");
3
+
4
+ for (const i of issues) {
5
+ console.log(`โŒ [${i.type}] ${i.msg} โ†’ ${i.file}`);
6
+ }
7
+
8
+ console.log(`\nScore: ${Math.max(0, 100 - issues.length * 5)} / 100`);
9
+ }
@@ -1,13 +1,13 @@
1
- import * as fs from "fs";
2
-
3
- export const securityRules = [
4
- {
5
- name: "hardcoded-secret",
6
- async check(file: string) {
7
- const content = fs.readFileSync(file, "utf8");
8
- return /(API_KEY|SECRET|TOKEN)\s*=\s*['"]/i.test(content)
9
- ? [{ type: "SEC", file, msg: "Hardcoded secret detected" }]
10
- : [];
11
- },
12
- },
13
- ];
1
+ import * as fs from "fs";
2
+
3
+ export const securityRules = [
4
+ {
5
+ name: "hardcoded-secret",
6
+ async check(file: string) {
7
+ const content = fs.readFileSync(file, "utf8");
8
+ return /(API_KEY|SECRET|TOKEN)\s*=\s*['"]/i.test(content)
9
+ ? [{ type: "SEC", file, msg: "Hardcoded secret detected" }]
10
+ : [];
11
+ },
12
+ },
13
+ ];
package/src/rules/type.ts CHANGED
@@ -1,23 +1,23 @@
1
- // src/rules/types.ts
2
- import { execSync } from "child_process";
3
-
4
- export const typeRules = [
5
- {
6
- name: "typescript-check",
7
- async check(_file: string) {
8
- try {
9
- // Run tsc in noEmit mode
10
- execSync("tsc --noEmit", { stdio: "pipe" });
11
- return [];
12
- } catch (e: any) {
13
- // Extract errors
14
- const output = e.stdout?.toString() || e.message || "Type check failed";
15
- const errors = output
16
- .split("\n")
17
- .filter((line: string) => line.trim() !== "")
18
- .map((line: string) => ({ type: "TYPE", file: "ts", msg: line }));
19
- return errors;
20
- }
21
- },
22
- },
23
- ];
1
+ // src/rules/types.ts
2
+ import { execSync } from "child_process";
3
+
4
+ export const typeRules = [
5
+ {
6
+ name: "typescript-check",
7
+ async check(_file: string) {
8
+ try {
9
+ // Run tsc in noEmit mode
10
+ execSync("tsc --noEmit", { stdio: "pipe" });
11
+ return [];
12
+ } catch (e: any) {
13
+ // Extract errors
14
+ const output = e.stdout?.toString() || e.message || "Type check failed";
15
+ const errors = output
16
+ .split("\n")
17
+ .filter((line: string) => line.trim() !== "")
18
+ .map((line: string) => ({ type: "TYPE", file: "ts", msg: line }));
19
+ return errors;
20
+ }
21
+ },
22
+ },
23
+ ];
package/src/scanner.ts CHANGED
@@ -1,32 +1,17 @@
1
-
2
- import { readdir } from "node:fs/promises";
3
- import path from "node:path";
4
-
5
- const IGNORE = new Set([
6
- "node_modules",
7
- "dist",
8
- "build",
9
- ".git",
10
- ".next",
11
- ".turbo"
12
- ]);
13
-
14
- export async function scanProject(dir = process.cwd(), files: string[] = []) {
15
- const entries = await readdir(dir, { withFileTypes: true });
16
-
17
- await Promise.all(
18
- entries.map(async (entry) => {
19
- if (IGNORE.has(entry.name)) return;
20
-
21
- const fullPath = path.join(dir, entry.name);
22
-
23
- if (entry.isDirectory()) {
24
- await scanProject(fullPath, files);
25
- } else if (entry.name.endsWith(".ts")) {
26
- files.push(fullPath);
27
- }
28
- })
29
- );
30
-
31
- return files;
32
- }
1
+ import { glob } from "glob";
2
+ import fs from "node:fs";
3
+
4
+ export async function scanProject() {
5
+ if (!fs.existsSync("src")) {
6
+ console.log(
7
+ "๐Ÿšซ No src folder found. Run from project root or skipping scan."
8
+ );
9
+ return [];
10
+ }
11
+
12
+ return glob("src/**/*.{ts,tsx,js,jsx}", {
13
+ nodir: true,
14
+ cwd: process.cwd(),
15
+ ignore: ["**/node_modules/**"],
16
+ });
17
+ }