Rules Reference

Built-in Rules

AI Guard includes 5 built-in rules that detect common AI-generated code patterns:

1. excessive-comments

Detects files where the ratio of comment lines to total lines exceeds the configured threshold.

PropertyValue
Rule Nameexcessive-comments
Default Threshold15% (0.15)
ConfigurableYes (maxCommentsRatio)
Severityerror

Example violation:

typescript
// This function processes user data
// It takes a user object as input
// Then it validates the data
// After validation it returns the result
function processUser(user) {
// First we check if user exists
if (!user) {
// No user provided
return null;
}
// Continue processing...
}
// Line 1: [excessive-comments] Comment ratio 45% exceeds threshold of 15%

How to fix: Remove redundant comments and let code speak for itself.

2. obvious-comments

Flags comments that simply restate what the code does, adding no value.

PropertyValue
Rule Nameobvious-comments
Pattern DetectionAST-based + heuristics
ConfigurableNo
Severityerror

Common obvious comment patterns:

typescript
// Loop through users
for (const user of users) {
// Active users only
if (user.isActive) {
// Add to active list
activeUsers.push(user);
}
}
// All three comments are obvious - the code is self-explanatory

How to fix: Remove comments that don't add information beyond what's in the code.

3. generic-names

Detects use of generic variable and function names that don't convey meaning.

PropertyValue
Rule Namegeneric-names
Default Listdata, result, item, temp, value, obj, arr, info, content, response
ConfigurableYes (forbidGenericNames)
Severityerror

Example violations:

typescript
// Bad: generic names
async function fetchData() {
const response = await api.get("/users");
const data = response.data;
const result = processData(data);
return result;
}
// Good: descriptive names
async function fetchUsers() {
const apiResponse = await api.get("/users");
const users = apiResponse.data;
const validatedUsers = validateUsers(users);
return validatedUsers;
}

How to fix: Use domain-specific, descriptive names that convey the data's purpose.

4. large-functions

Flags functions that exceed the maximum line count threshold.

PropertyValue
Rule Namelarge-functions
Default Threshold60 lines
ConfigurableYes (maxFunctionLines)
Severityerror

Example violation:

typescript
function processOrder(order) {
// 80 lines of code...
// Multiple responsibilities
// Hard to test and maintain
}
// Line 1: [large-functions] Function 'processOrder' has 80 lines (max: 60)

How to fix: Break large functions into smaller, focused functions with single responsibilities.

5. ai-patterns

Detects phrases commonly used by AI code generators that indicate machine-generated content.

PropertyValue
Rule Nameai-patterns
Default Patternsthis function, we will, we need to, let's, in order to, going to, simply, just
ConfigurableYes (aiPatterns.forbid)
Severityerror

Common AI phrase examples:

typescript
// This function will process the user data
function processUserData(user) {
// First, we need to validate the input
if (!user) {
return null;
}
// Next step: transform into output format
const transformed = transform(user);
// Finally, in order to complete the process, we return the result
return transformed;
}
// Multiple AI-typical phrases detected

How to fix: Rewrite comments in a more natural, human style, or remove them if they're not needed.

Configuring Rules

Adjust rule thresholds in your configuration file:

typescript
export default defineConfig({
// Allow more comments in documentation-heavy projects
maxCommentsRatio: 0.20,
// Stricter function length for microservices
maxFunctionLines: 40,
// Add project-specific generic names to avoid
forbidGenericNames: [
'data',
'result',
'item',
'temp',
'value',
'myVar', // custom
'helper', // custom
],
// Add custom AI patterns specific to your LLM
aiPatterns: {
forbid: [
'this function',
'we will',
'we need to',
'as mentioned above', // custom
'it is worth noting', // custom
],
},
});
All rules run on every analysis. There is currently no way to disable individual rules, but you can adjust thresholds to be more or less strict.

Support

Need help or found a bug? We're here to assist you!

  • 📧 Email: opensource@promise.codes
  • 🐛 GitHub Issues: https://github.com/promise-inc/ai-guard/issues
  • 📖 Full documentation at /open-source/ai-guard/docs