agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
90 lines (80 loc) • 2.25 kB
JavaScript
/**
* @file Apply context-specific analysis rules
* @description Single responsibility: Configure analysis rules based on file context
*/
function applyContextRules(context) {
const { isTestFile, isConfigFile, isGeneratedFile, framework } = context;
// Default rules
context.rules = {
minLines: 5,
minComplexity: 2,
similarityThreshold: 0.8,
skipAnalysis: false,
allowedPatterns: []
};
// Test files have more lenient rules
if (isTestFile) {
context.rules.minLines = 10;
context.rules.minComplexity = 1;
context.rules.similarityThreshold = 0.9;
context.rules.allowedPatterns.push(
'test-fixtures',
'mock-data',
'test-helpers',
'assertion-patterns'
);
context.acceptablePatterns.push(
'Test fixture data is expected to be duplicated',
'Test setup/teardown patterns are acceptable'
);
}
// Config files often have boilerplate
if (isConfigFile) {
context.rules.minLines = 15;
context.rules.allowedPatterns.push(
'config-boilerplate',
'environment-setup'
);
context.acceptablePatterns.push(
'Configuration boilerplate is often necessary'
);
}
// Generated files should be skipped
if (isGeneratedFile) {
context.rules.skipAnalysis = true;
context.acceptablePatterns.push(
'Generated files should not be manually edited'
);
}
// Migration files have specific patterns
if (context.isMigrationFile) {
context.rules.minLines = 20;
context.rules.allowedPatterns.push(
'migration-boilerplate',
'schema-definitions'
);
}
// Framework-specific rules
if (framework.includes('react')) {
context.rules.allowedPatterns.push(
'react-component-boilerplate',
'prop-types-definitions',
'default-props'
);
}
if (framework.includes('express')) {
context.rules.allowedPatterns.push(
'route-handlers',
'middleware-patterns',
'error-handlers'
);
}
if (framework.includes('jest') || framework.includes('mocha')) {
context.rules.minLines = 8;
context.rules.allowedPatterns.push(
'test-assertions',
'mock-implementations'
);
}
}
module.exports = applyContextRules;