Skip to content

Commit

Permalink
ISSUE protofire#206 - Plugins can be in any path
Browse files Browse the repository at this point in the history
Change loadPlugin function at index.js to receive the plugin path.
  • Loading branch information
lhemerly committed Mar 24, 2023
1 parent 0b016da commit bcfb705
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,21 @@ function coreRules(meta) {
]
}

function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {
function loadPlugin(pluginPath, { reporter, config, inputSrc, fileName }) {
let plugins
try {
plugins = require(`solhint-plugin-${pluginName}`)
plugins = require(`${pluginPath}`)
} catch (e) {
console.error(
chalk.red(
`[solhint] Error: Could not load solhint-plugin-${pluginName}, make sure it's installed.`
)
chalk.red(`[solhint] Error: Could not load ${pluginPath}, make sure it's installed.`)
)
process.exit(1)
}

if (!Array.isArray(plugins)) {
console.warn(
chalk.yellow(
`[solhint] Warning: Plugin solhint-plugin-${pluginName} doesn't export an array of rules. Ignoring it.`
`[solhint] Warning: Plugin ${pluginPath} doesn't export an array of rules. Ignoring it.`
)
)
return []
Expand All @@ -92,7 +90,7 @@ function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {
return plugins
.map((Plugin) => new Plugin(reporter, config, inputSrc, fileName))
.map((plugin) => {
plugin.ruleId = `${pluginName}/${plugin.ruleId}`
plugin.ruleId = `${pluginPath}/${plugin.ruleId}`
return plugin
})
}
Expand Down

0 comments on commit bcfb705

Please sign in to comment.