ESLint Plugin Configuration
Complete guide to configuring eslint-plugin-ai-guard with ESLint Flat Config and legacy .eslintrc setups.
AI Guard is a standards-compliant ESLint plugin that works seamlessly with modern ESLint 9 flat configs as well as legacy ESLint 8 setups.
ESLint 9 Flat Config (Recommended)
In modern repositories using eslint.config.js or eslint.config.mjs, import the plugin and spread the recommended preset:
// eslint.config.mjs
import aiGuard from 'eslint-plugin-ai-guard';
export default [
{
plugins: {
'ai-guard': aiGuard,
},
rules: {
...aiGuard.configs.recommended.rules,
// Customize specific rules if needed:
'ai-guard/no-await-in-loop': 'warn',
},
},
];For strict CI enforcement, replace recommended with aiGuard.configs.strict.rules.
ESLint 8 Legacy Config (.eslintrc)
If your project still relies on .eslintrc.js or .eslintrc.json:
{
"plugins": ["ai-guard"],
"extends": ["plugin:ai-guard/recommended"]
}Configuring Individual Rules
Every rule can be independently set to off, warn, or error:
export default [
{
plugins: { 'ai-guard': aiGuard },
rules: {
'ai-guard/no-floating-promise': 'error',
'ai-guard/no-hardcoded-secret': 'error',
'ai-guard/no-sql-string-concat': 'error',
'ai-guard/no-console-in-handler': ['warn', { allowWarn: true, allowError: true }],
},
},
];Inline Disable Comments
When you have intentional exceptions in your codebase, use scoped disable comments:
// ai-guard-disable-next-line no-floating-promise
fireAndForgetMetricsSync();You can also disable AI Guard rules across an entire file:
/* ai-guard-disable no-console-in-handler */Comparison with @typescript-eslint
Developers often ask how AI Guard compares to @typescript-eslint:
- Zero Type-Information Penalty:
@typescript-eslint/no-floating-promisesrequiresparserOptions.project, forcing full TypeScript semantic compilation on every lint run (slowing down linting 5–10x). AI Guard uses fast AST structural heuristics, completing scans in milliseconds. - Works on Plain JavaScript: AI Guard does not require a
tsconfig.jsonfile. It inspects pure JS, Node.js scripts, and React codebases equally well. - AI-Pattern Specialization: Rules like
no-dead-branchandno-async-array-callbackspecifically target hallucinations common in Copilot and Claude outputs that standard linters ignore.