MCPcopy Create free account
hub / github.com/facebook/Rapid / _validateEntity

Method _validateEntity

modules/core/ValidationSystem.js:625–670  ·  view source on GitHub ↗

* _validateEntity * Runs all validation rules on a single entity. * Some things to note: * - Graph is passed in from whenever the validation was started. Validators shouldn't use * the staging/stable graphs because this all happens async, and the graph might have changed * (for

(entity, graph)

Source from the content-addressed store, hash-verified

623 * }
624 */
625 _validateEntity(entity, graph) {
626
627 // If there are any override rules that match the issue type/subtype,
628 // adjust severity (or disable it) and keep/discard as quickly as possible.
629 const applySeverityOverrides = (issue) => {
630 const type = issue.type;
631 const subtype = issue.subtype ?? '';
632
633 for (const error of this._errorOverrides) {
634 if (error.type.test(type) && error.subtype.test(subtype)) {
635 issue.severity = 'error';
636 return true;
637 }
638 }
639 for (const warning of this._warningOverrides) {
640 if (warning.type.test(type) && warning.subtype.test(subtype)) {
641 issue.severity = 'warning';
642 return true;
643 }
644 }
645 for (const disable of this._disableOverrides) {
646 if (disable.type.test(type) && disable.subtype.test(subtype)) {
647 return false;
648 }
649 }
650 return true;
651 };
652
653
654 const result = { issues: [], provisional: false };
655 for (const [key, rule] of this._rules) { // run all validators
656 if (typeof rule !== 'function') {
657 console.error(`no such validation rule = ${key}`); // eslint-disable-line no-console
658 continue;
659 }
660 let detected = rule(entity, graph);
661 if (detected.provisional) { // this validation should be run again later
662 result.provisional = true;
663 }
664
665 detected = detected.filter(applySeverityOverrides);
666 result.issues = result.issues.concat(detected);
667 }
668
669 return result;
670 }
671
672
673 /**

Callers 1

Calls 2

errorMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected