Skip to main content

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.

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.