Integration·4 min read

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.

In modern repositories using eslint.config.js or eslint.config.mjs, import the plugin and spread the recommended preset:

javascript
// 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:

json
{
  "plugins": ["ai-guard"],
  "extends": ["plugin:ai-guard/recommended"]
}

Configuring Individual Rules

Every rule can be independently set to off, warn, or error:

javascript
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:

typescript
// ai-guard-disable-next-line no-floating-promise
fireAndForgetMetricsSync();

You can also disable AI Guard rules across an entire file:

typescript
/* 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-promises requires parserOptions.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.json file. It inspects pure JS, Node.js scripts, and React codebases equally well.
  • AI-Pattern Specialization: Rules like no-dead-branch and no-async-array-callback specifically target hallucinations common in Copilot and Claude outputs that standard linters ignore.