📝 Split up and document `getApplicableReplacements`

cycles-detection-with-context
Alexandre Hajjar 2020-09-08 18:07:58 +02:00
parent 4723eb39d6
commit cfd6f8d813
1 changed files with 24 additions and 11 deletions

View File

@ -9,21 +9,17 @@ import parseRule from './parseRule'
import { disambiguateRuleReference } from './ruleUtils'
import { areUnitConvertible, serializeUnit } from './units'
const getApplicableReplacements = (
filter,
contextRuleName,
cache,
situation,
rules,
rule
) => {
let missingVariableList = []
const applicableReplacements = rule.replacedBy
/**
* Statically filter out replacements from `replaceBy`.
* Note: whitelist and blacklist filtering are applicable to the replacement
* itself or any parent namespace.
*/
export const getApplicableReplacedBy = (contextRuleName, replacedBy) =>
replacedBy
.sort(
(replacement1, replacement2) =>
!!replacement2.whiteListedNames - !!replacement1.whiteListedNames
)
// Remove remplacement not in whitelist
.filter(
({ whiteListedNames }) =>
!whiteListedNames ||
@ -35,6 +31,23 @@ const getApplicableReplacements = (
blackListedNames.every(name => !contextRuleName.startsWith(name))
)
.filter(({ referenceNode }) => contextRuleName !== referenceNode.dottedName)
/**
* Filter-out replacements at runtime.
*/
const getApplicableReplacements = (
filter,
contextRuleName,
cache,
situation,
rules,
rule
) => {
let missingVariableList = []
const applicableReplacements = getApplicableReplacedBy(
contextRuleName,
rule.replacedBy
)
// Remove remplacement defined in a not applicable node
.filter(({ referenceNode }) => {
const referenceRule = rules[referenceNode.dottedName]