Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Aug 9, 2023
1 parent 4290d73 commit 7a7dfce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
32 changes: 29 additions & 3 deletions lib/utils/issue-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const ERROR_UX = {
//#endregion
//#region utils
/**
* @typedef { NonNullable<NonNullable<(Awaited<ReturnType<import('@socketsecurity/sdk').SocketSdk['postSettings']>> & {success: true})['data']['entries'][number]['settings'][string]['issueRules']>>[string] | boolean } NonNormalizedIssueRule
* @typedef { NonNullable<NonNullable<NonNullable<(Awaited<ReturnType<import('@socketsecurity/sdk').SocketSdk['postSettings']>> & {success: true})['data']['entries'][number]['settings'][string]>['issueRules']>>[string] | boolean } NonNormalizedIssueRule
*/
/**
* @typedef { NonNullable<NonNullable<(Awaited<ReturnType<import('@socketsecurity/sdk').SocketSdk['postSettings']>> & {success: true})['data']['defaults']['issueRules']>[string]> | boolean } NonNormalizedResolvedIssueRule
* @typedef { (NonNullable<NonNullable<(Awaited<ReturnType<import('@socketsecurity/sdk').SocketSdk['postSettings']>> & {success: true})['data']['defaults']['issueRules']>[string]> & { action: string }) | boolean } NonNormalizedResolvedIssueRule
*/
/**
* Iterates over all entries with ordered issue rule for deferal
Expand All @@ -32,6 +32,15 @@ const ERROR_UX = {
* @returns {RuleActionUX}
*/
function resolveIssueRuleUX (entriesOrderedIssueRules, defaultValue) {
if (defaultValue === true || defaultValue == null) {
defaultValue = {
action: 'error'
}
} else if (defaultValue === false) {
defaultValue = {
action: 'ignore'
}
}
let block = false
let display = false
let needDefault = true
Expand Down Expand Up @@ -145,7 +154,24 @@ module.exports = {
entriesOrderedIssueRules.push(orderedIssueRules)
}
const defaultValue = settings.defaults.issueRules[key]
ux = resolveIssueRuleUX(entriesOrderedIssueRules, defaultValue ?? { action: 'error' })
/**
* @type {NonNormalizedResolvedIssueRule}
*/
let resolvedDefaultValue = {
action: 'error'
}
// @ts-ignore backcompat, cover with tests
if (defaultValue === false) {
resolvedDefaultValue = {
action: 'ignore'
}
// @ts-ignore backcompat, cover with tests
} else if (defaultValue && defaultValue !== true) {
resolvedDefaultValue = {
action: defaultValue.action ?? 'error'
}
}
ux = resolveIssueRuleUX(entriesOrderedIssueRules, resolvedDefaultValue)
cachedUX.set(key, ux)
return ux
}
Expand Down
5 changes: 4 additions & 1 deletion test/issue-rule-ux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ describe('Issue Rule UX', () => {
deferTo: 'repository',
issueRules: {
fromDeferString: { action: 'defer' },
frumUndefinedAction: { }
// @ts-ignore paranoia
fromUndefinedAction: { }
}
},
repository: {
deferTo: null,
issueRules: {
fromMiddleConfig: {
action: 'warn'
Expand Down Expand Up @@ -291,6 +293,7 @@ describe('Issue Rule UX', () => {
start: 'organization',
settings: {
organization: {
deferTo: null,
issueRules: {
willWarn: {
action: 'ignore'
Expand Down

0 comments on commit 7a7dfce

Please sign in to comment.