refactor(comment-checker): simplify binary path resolution and add separator warning
- Remove platform-specific package lookup logic - Remove homebrew path resolution - Add code smell warning for comment separators 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -15,36 +15,13 @@ function debugLog(...args: unknown[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Platform = "darwin" | "linux" | "win32" | "unsupported"
|
|
||||||
|
|
||||||
function getPlatformPackageName(): string | null {
|
|
||||||
const platform = process.platform as Platform
|
|
||||||
const arch = process.arch
|
|
||||||
|
|
||||||
const platformMap: Record<string, string> = {
|
|
||||||
"darwin-arm64": "@code-yeongyu/comment-checker-darwin-arm64",
|
|
||||||
"darwin-x64": "@code-yeongyu/comment-checker-darwin-x64",
|
|
||||||
"linux-arm64": "@code-yeongyu/comment-checker-linux-arm64",
|
|
||||||
"linux-x64": "@code-yeongyu/comment-checker-linux-x64",
|
|
||||||
"win32-x64": "@code-yeongyu/comment-checker-windows-x64",
|
|
||||||
}
|
|
||||||
|
|
||||||
return platformMap[`${platform}-${arch}`] ?? null
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBinaryName(): string {
|
function getBinaryName(): string {
|
||||||
return process.platform === "win32" ? "comment-checker.exe" : "comment-checker"
|
return process.platform === "win32" ? "comment-checker.exe" : "comment-checker"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously find comment-checker binary path.
|
|
||||||
* Checks installed packages, homebrew, cache, and system PATH.
|
|
||||||
* Does NOT trigger download.
|
|
||||||
*/
|
|
||||||
function findCommentCheckerPathSync(): string | null {
|
function findCommentCheckerPathSync(): string | null {
|
||||||
const binaryName = getBinaryName()
|
const binaryName = getBinaryName()
|
||||||
|
|
||||||
// 1. Try to find from @code-yeongyu/comment-checker package
|
|
||||||
try {
|
try {
|
||||||
const require = createRequire(import.meta.url)
|
const require = createRequire(import.meta.url)
|
||||||
const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json")
|
const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json")
|
||||||
@@ -59,46 +36,12 @@ function findCommentCheckerPathSync(): string | null {
|
|||||||
debugLog("main package not installed")
|
debugLog("main package not installed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Try platform-specific package directly (legacy, for backwards compatibility)
|
|
||||||
const platformPkg = getPlatformPackageName()
|
|
||||||
if (platformPkg) {
|
|
||||||
try {
|
|
||||||
const require = createRequire(import.meta.url)
|
|
||||||
const pkgPath = require.resolve(`${platformPkg}/package.json`)
|
|
||||||
const pkgDir = dirname(pkgPath)
|
|
||||||
const binaryPath = join(pkgDir, "bin", binaryName)
|
|
||||||
|
|
||||||
if (existsSync(binaryPath)) {
|
|
||||||
debugLog("found binary in platform package:", binaryPath)
|
|
||||||
return binaryPath
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
debugLog("platform package not installed:", platformPkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Try homebrew installation (macOS)
|
|
||||||
if (process.platform === "darwin") {
|
|
||||||
const homebrewPaths = [
|
|
||||||
"/opt/homebrew/bin/comment-checker",
|
|
||||||
"/usr/local/bin/comment-checker",
|
|
||||||
]
|
|
||||||
for (const path of homebrewPaths) {
|
|
||||||
if (existsSync(path)) {
|
|
||||||
debugLog("found binary via homebrew:", path)
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Try cached binary (lazy download location)
|
|
||||||
const cachedPath = getCachedBinaryPath()
|
const cachedPath = getCachedBinaryPath()
|
||||||
if (cachedPath) {
|
if (cachedPath) {
|
||||||
debugLog("found binary in cache:", cachedPath)
|
debugLog("found binary in cache:", cachedPath)
|
||||||
return cachedPath
|
return cachedPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Try system PATH (as fallback)
|
|
||||||
debugLog("no binary found in known locations")
|
debugLog("no binary found in known locations")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ PRIORITY-BASED ACTION GUIDELINES:
|
|||||||
\t-> Make the code itself clearer so it can be understood without comments/docstrings.
|
\t-> Make the code itself clearer so it can be understood without comments/docstrings.
|
||||||
\t-> For verbose docstrings: refactor code to be self-documenting instead of adding lengthy explanations.
|
\t-> For verbose docstrings: refactor code to be self-documenting instead of adding lengthy explanations.
|
||||||
|
|
||||||
|
CODE SMELL WARNING: Using comments as visual separators (e.g., "// =========", "# ---", "// *** Section ***")
|
||||||
|
is a code smell. If you need separators, your file is too long or poorly organized.
|
||||||
|
Refactor into smaller modules or use proper code organization instead of comment-based section dividers.
|
||||||
|
|
||||||
MANDATORY REQUIREMENT: You must acknowledge this hook message and take one of the above actions.
|
MANDATORY REQUIREMENT: You must acknowledge this hook message and take one of the above actions.
|
||||||
Review in the above priority order and take the corresponding action EVERY TIME this appears.
|
Review in the above priority order and take the corresponding action EVERY TIME this appears.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user