Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent 4166a91 commit 180db7c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/config/plugin/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { list, set } from '../../normalize/lib/wild_wild_path/main.js'
import { parseQuery } from '../../normalize/lib/wild_wild_path/main.js'
import { pick } from '../../normalize/lib/wild_wild_path_utils/main.js'

// Retrieve top-level properties that are shared with all plugins of a specific
// type. Those are merged with plugin-specific properties.
export const getSharedConfig = function (sharedConfig, item = []) {
const sharedPropNames = [...new Set(item.map(getRuleName))]
const sharedConfigProps = sharedPropNames.flatMap((sharedPropName) =>
list(sharedConfig, sharedPropName),
)
const sharedConfigA = sharedConfigProps.reduce(addSharedConfigProp, {})
const sharedConfigA = pick(sharedConfig, sharedPropNames.flatMap(parseQuery))
return { sharedConfig: sharedConfigA, sharedPropNames }
}

const getRuleName = function ({ name }) {
return name
}

const addSharedConfigProp = function (sharedConfig, { path, value }) {
return set(sharedConfig, path, value)
}

0 comments on commit 180db7c

Please sign in to comment.