-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from bmish/eslint-extend-config
- Loading branch information
Showing
9 changed files
with
177 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Plugin, Config, Rules, ConfigsToRules } from './types.js'; | ||
|
||
/** | ||
* ESLint configs can extend other configs, so for convenience, let's resolve all the rules in each config upfront. | ||
*/ | ||
export async function resolveConfigsToRules( | ||
plugin: Plugin | ||
): Promise<ConfigsToRules> { | ||
const configs: Record<string, Rules> = {}; | ||
for (const [configName, config] of Object.entries(plugin.configs || {})) { | ||
configs[configName] = await resolveConfigRules(config); | ||
} | ||
return configs; | ||
} | ||
|
||
/** | ||
* Recursively gather all the rules from a config that may extend other configs. | ||
*/ | ||
async function resolveConfigRules(config: Config): Promise<Rules> { | ||
if (!config.extends) { | ||
return config.rules; | ||
} | ||
const rules = { ...config.rules }; | ||
for (const extend of config.extends) { | ||
const { default: config } = await import(extend); | ||
const nestedRules = await resolveConfigRules(config); | ||
Object.assign(rules, nestedRules); | ||
} | ||
return rules; | ||
} |
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
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