-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { inspect } from 'util' | ||
|
||
// Retrieve the list of possible rule properties | ||
export const getRuleProps = function (keywords) { | ||
return new Set([...CORE_PROPS, ...keywords.map(getKeywordName)]) | ||
} | ||
|
||
const getKeywordName = function ({ name }) { | ||
return name | ||
} | ||
|
||
// Rule properties that are not keywords | ||
const CORE_PROPS = ['name'] | ||
export const CORE_PROPS_SET = new Set(CORE_PROPS) | ||
|
||
// Validate that a `definitions` object has only allowed properties | ||
export const validateRuleProps = function (definitions, ruleProps, message) { | ||
// `definitions` is a plain object, i.e. does not have inherited properties | ||
// eslint-disable-next-line fp/no-loops, guard-for-in | ||
for (const ruleProp in definitions) { | ||
validateRuleProp({ ruleProp, ruleProps, message, definitions }) | ||
} | ||
} | ||
|
||
const validateRuleProp = function ({ | ||
ruleProp, | ||
ruleProps, | ||
message, | ||
definitions, | ||
}) { | ||
if (ruleProps.has(ruleProp)) { | ||
return | ||
} | ||
|
||
// eslint-disable-next-line fp/no-mutating-methods | ||
const rulePropsA = [...ruleProps].sort().join(', ') | ||
throw new Error( | ||
`${message}'s "${ruleProp}" property must be valid: ${inspect(definitions)} | ||
It must be one of the following values instead: | ||
${rulePropsA} | ||
Did you misspell "${ruleProp}"? | ||
If "${ruleProp}" is not misspelled, its keyword must be passed to the "keywords" option.`, | ||
) | ||
} |