@codacy/tools-detekt-1

中文文档
0.28.0发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 1.2万

detekt adapter — CLI-mode Kotlin static analyzer

原始使用文档
文档目录6 节
  1. Table of Contents
  2. Overview
  3. Updating patterns
  4. Updating the detekt version
  5. Development
  6. Notes for maintainers

@codacy/tools-detekt-1

Table of Contents


Overview

Kotlin static analyzer using the detekt CLI JAR. Uses the CLI execution strategy -- spawns java -jar detekt-cli-all.jar via spawnTool() and parses its Checkstyle XML output.

PropertyValue
Tool IDdetekt
Codacy UUIDcb36c32d-fc0d-4b4c-8f21-66e536ef4513
StrategyCLI
LanguagesKotlin
Binarydetekt-cli-1.23.8-all.jar (downloaded from GitHub)
File patterns**/*.kt, **/*.kts

Updating patterns

# Re-fetch pattern metadata from the Codacy API
pnpm prefetch

# Commit the result
git add src/patterns.json

Pattern IDs are bare rule names (no prefix): LongMethod, MagicNumber, ComplexCondition, etc.

Updating the detekt version

  1. Update DETEKT_VERSION and JAR_NAME in src/adapter.ts
  2. Update JAR_URL to point to the new release
  3. Run pnpm prefetch to check for new/removed rules
  4. Run pnpm test to verify compatibility
  5. If the major version changes, create a new adapter package (detekt-2/)

Development

pnpm build    # Build with tsup
pnpm test     # Run tests (requires java in PATH + detekt JAR)

To install detekt locally for testing:

# Download the all-in-one JAR
curl -L -o /tmp/codacy-detekt-test-tools/detekt-cli-1.23.8-all.jar \
  https://github.com/detekt/detekt/releases/download/v1.23.8/detekt-cli-1.23.8-all.jar

Notes for maintainers

  • Preset mappings (src/pattern-mappings.json): the seven coroutines rules are gated on kotlinx-coroutines, detected from any kotlinx-coroutines-* Maven artifact. All seven are default-off upstream, so before this they could never be enabled by init --auto — not even in a coroutines project. Five carry detekt's own coroutines tag; GlobalCoroutineUsage and InjectDispatcher carry no tag and are matched by their bare rule name (detekt pattern IDs have no tool prefix).

  • detekt requires Java 8+ as a runtime. The adapter uses ensureJre() to download Adoptium Temurin JDK 21 if no system Java is found.

  • The detekt CLI JAR is an all-in-one fat JAR downloaded from GitHub releases to ctx.toolInstallDir.

  • Output format is Checkstyle 4.3 XML written to a temp file via --report xml:<path>.

  • --base-path <repoRoot> ensures file paths in the XML are relative to the repository root.

  • --parallel enables multi-threaded analysis for performance.

  • The source attribute in XML has format detekt.RuleName or detekt.ruleset.RuleName. The adapter strips the detekt. prefix and any ruleset prefix to get just the rule name.

  • Pattern IDs in patterns.json have no prefix -- they are bare rule names (e.g. LongMethod, not detekt_LongMethod).

  • Exit codes: 0 = no findings, 1 = findings found (build failure threshold), 2 = findings found, 3 = invalid config.

  • Config file detection supports detekt.yml and default-detekt-config.yml. When a local config is found, it is passed via --config <path>.

  • Pattern filtering is post-hoc: detekt runs with all default rules, then output is filtered by the enabled patterns set.

版本与发布记录

@codacy/tools-detekt-1 共发布 36 个版本,首次发布于 2026/03/24;过去 12 个月发布了 36 个版本。

版本发布日期距今
0.28.0latest2026/11/09今天
0.27.12026/11/054 天前
0.27.02026/11/036 天前
0.26.02026/10/3010 天前
0.25.02026/10/1921 天前
0.24.02026/09/251 个月前

关于 @codacy/tools-detekt-1 的常见问题

@codacy/tools-detekt-1 是什么?

detekt adapter — CLI-mode Kotlin static analyzer

如何安装 @codacy/tools-detekt-1?

在项目目录运行 npm install @codacy/tools-detekt-1,或使用 pnpm add / yarn add / bun add。

@codacy/tools-detekt-1 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codacy/tools-detekt-1 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codacy/tools-detekt-1 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codacy/tools-detekt-1 可以商用吗?

@codacy/tools-detekt-1 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codacy/tools-detekt-1 的下载量有多少?

根据 npm 官方下载统计,@codacy/tools-detekt-1 在 2026/10/10 – 2026/11/08 这 30 天内被下载 11,965 次,日均约 399 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codacy/tools-detekt-1 还在维护吗?

最新版本 0.28.0 发布于 2026/11/09(今天);至今共发布 36 个版本,其中过去 12 个月发布了 36 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。