HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/plugins/pojo-accessibility/modules/scanner/assets/js/utils/sort-violations.js
import {
	INITIAL_SORTED_VIOLATIONS,
	VIOLATION_TYPES,
} from '@ea11y-apps/scanner/constants';

export const sortViolations = (violations) => {
	const sorted = structuredClone(INITIAL_SORTED_VIOLATIONS);

	violations.forEach((item) => {
		let type = '';
		const outer = item.node.outerHTML;
		const gtIndex = outer.indexOf('>');
		item.snippet = gtIndex !== -1 ? outer.slice(0, gtIndex + 1) : item.snippet;

		Object.keys(VIOLATION_TYPES).forEach((key) => {
			if (VIOLATION_TYPES[key].includes(item.ruleId)) {
				type = key;
			}
		});
		sorted[type || 'other'].push(item);
	});

	return sorted;
};

export const sortRemediation = (remediations) => {
	const sorted = structuredClone(INITIAL_SORTED_VIOLATIONS);
	remediations.forEach((remediation) => {
		sorted[remediation.group].push(remediation);
	});
	return sorted;
};