Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent def2bc7 commit f72a719
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/config/plugin/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import { list, parent, set } from '../../normalize/lib/star_dot_path/main.js'
import { list, set } from '../../normalize/lib/star_dot_path/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 = getSharedConfigPropNames(item)
const sharedPropNames = [...new Set(item.map(getRuleName))]
const sharedConfigProps = sharedPropNames.flatMap((sharedPropName) =>
list(sharedConfig, sharedPropName),
)
const sharedConfigA = sharedConfigProps.reduce(addSharedConfigProp, {})
return { sharedConfig: sharedConfigA, sharedPropNames }
}

// Retrieve all unique `name` of shared config properties, excluding their
// children
const getSharedConfigPropNames = function (item) {
const sharedPropNames = item.map(getRuleName)
return [...new Set(sharedPropNames)].filter(hasNoParent)
}

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

const hasNoParent = function (nameA, indexA, names) {
return names.every(
(nameB, indexB) => indexB === indexA || !parent(nameB, nameA),
)
}

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

0 comments on commit f72a719

Please sign in to comment.