debt-collector
Version:
a nodejs tool to identify, track and mesure technical debt
26 lines (25 loc) • 859 B
JavaScript
import { findJsImportFrom, countAll, findOne, findOneOf, countAllOf, findAttributesInTag } from '../rulesUtils/index.js';
const getFileRulesErrors = (config, file, data) => {
const utils = {
content: data,
file,
countAll: countAll(data),
findOne: findOne(data),
findOneOf: findOneOf(data),
countAllOf: countAllOf(data),
findJsImportFrom: findJsImportFrom(data),
findAttributesInTag: findAttributesInTag(data),
};
return (config?.fileRules?.reduce((acc, rule) => {
const nbErrors = rule.matchRule({ ...utils });
if (nbErrors > 0) {
acc.push({
ruleTitle: rule.title,
ruleId: rule.id,
occurences: nbErrors,
});
}
return acc;
}, []) ?? []);
};
export default getFileRulesErrors;