agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
95 lines (91 loc) • 4.18 kB
JavaScript
/**
* @file Ambiguous label detector for UI accessibility and usability analysis
* @description Single responsibility: Identify non-descriptive UI labels that harm user experience
*
* This module detects UI labels that provide insufficient context for users, particularly
* affecting accessibility for screen readers and cognitive load for all users. Ambiguous
* labels like "click here" or "more" fail to communicate their purpose clearly, creating
* barriers to effective user interaction and violating accessibility best practices.
*
* Design rationale:
* - Pattern-based detection covers common ambiguous label antipatterns
* - High severity classification reflects significant accessibility impact
* - Actionable recommendations guide developers toward better alternatives
* - Simple string matching provides fast analysis across large codebases
*/
/**
* Detect ambiguous UI labels using pattern matching with accessibility impact assessment
*
* Technical function: Pattern-based detection of non-descriptive UI text with severity classification
*
* Implementation rationale:
* - Predefined pattern list covers most common ambiguous label antipatterns
* - Case-insensitive matching catches variations in capitalization
* - High severity classification reflects serious accessibility and usability impact
* - Structured issue format enables integration with reporting and remediation tools
*
* Ambiguous label detection strategy:
* - Comprehensive pattern list based on accessibility guidelines and UX research
* - String inclusion matching catches embedded patterns in larger text
* - Content category classification helps organize remediation efforts
* - File path tracking enables precise location identification
*
* Accessibility impact analysis:
* - Screen reader users rely on descriptive labels for navigation context
* - Cognitive accessibility suffers when labels don't explain their purpose
* - Keyboard navigation users need clear action descriptions
* - SEO and search accessibility improved with descriptive text
*
* Common ambiguous patterns identified:
* - "click here": Generic action without destination context
* - "submit": Unclear what is being submitted or to where
* - "more": Vague expansion without content preview
* - "ok": Ambiguous confirmation without clear action result
* - "go": Generic navigation without destination indication
* - "next": Sequential navigation without context of sequence
*
* False positive considerations:
* - Simple string matching may catch patterns in comments or strings
* - Context-aware analysis could improve precision (future enhancement)
* - Manual review recommended for patterns in non-UI contexts
* - Pattern refinement based on project-specific vocabulary
*
* Remediation guidance:
* - Replace generic labels with specific action descriptions
* - Include destination or result information in link text
* - Use verb + object pattern for clear action communication
* - Consider ARIA labels for additional context when needed
*
* @param {string} content - UI file content to analyze for ambiguous labels
* @param {string} filePath - File path for issue location tracking
* @returns {Array<Object>} Array of ambiguous label issues with severity and recommendations
* @example
* const issues = detectAmbiguousLabels(`
* <button>Submit</button>
* <a href="/docs">Click here for more info</a>
* `, 'components/Form.jsx');
* // Returns issues for "submit" and "click here" patterns
*/
function detectAmbiguousLabels(content, filePath) {
const issues = [];
const ambiguousPatterns = [
'click here', 'submit', 'more', 'ok', 'go', 'next'
];
ambiguousPatterns.forEach(pattern => {
if (content.toLowerCase().includes(pattern)) {
issues.push({
type: 'ambiguous_labels',
severity: 'HIGH',
category: 'Content',
labelText: pattern,
description: `Ambiguous label text: "${pattern}"`,
file: filePath,
recommendation: `Replace "${pattern}" with more descriptive text`
});
}
});
return issues;
}
module.exports = {
detectAmbiguousLabels
};