no-secret
Detect hardcoded secrets in code.
Targeted pattern scopeโ
This rule targets string literals and related literal-like values in source files.
What this rule reportsโ
This rule reports values that match secret-like entropy checks or configured secret patterns.
Why this rule existsโ
Hardcoded credentials can leak through source control and build artifacts, creating serious security risk.
โ Incorrectโ
const token = "SECRET_ABCD";
โ Correctโ
const token = process.env.API_TOKEN;
Behavior and migration notesโ
This rule forwards options and behavior to
eslint-plugin-no-secrets/no-secrets.
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
no-secrets/no-secrets - Additional recommendation: Prefer dedicated scanners such as Secretlint or detect-secrets.
Additional examplesโ
const password = "p@ssw0rd-12345";
// โ likely reported by entropy/pattern checks
const password = process.env.APP_PASSWORD;
// โ
preferred
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-secret": "error",
},
},
];
When not to use itโ
Disable this rule only in sanitized fixture directories where false positives are unavoidable.
Package documentationโ
Rule catalog ID: R038
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.