Skip to content

Commit

Permalink
chore: improve logic for determining package name for scoped plugins (#…
Browse files Browse the repository at this point in the history
…332)

This should mean less thinking as we're going to start depending on more
scoped packages soon as part of upgrading to ESLint v9 such as
`@eslint-community/eslint-plugin-eslint-comments` and
`@stylistic/eslint-plugin-{js,ts,react}`
  • Loading branch information
G-Rath authored Nov 7, 2024
1 parent e77ed64 commit ec69b99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions test/configs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const configFiles = fs
* Generally this is done by returning the plugin name with `eslint-plugin-`
* appended to it (if the name does not already start with that string).
*
* Scoped plugins must be explicitly checked for to handle properly;
* Currently the `@typescript-eslint` is the only supported scoped plugin.
*
* @param {string} plugin
*
* @return {string}
Expand All @@ -32,8 +29,16 @@ const determinePluginPackageName = (plugin: string): string => {
return plugin;
}

if (plugin === '@typescript-eslint') {
return `${plugin}/eslint-plugin`;
if (plugin.startsWith('@')) {
const [scope, name] = plugin.split('/');

let packageName = `${scope}/eslint-plugin`;

if (name) {
packageName += `-${name}`;
}

return packageName;
}

return `eslint-plugin-${plugin}`;
Expand Down
15 changes: 10 additions & 5 deletions tools/generate-configs-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ const requireConfig = (config: string): Required<ESLint.Linter.Config> => {
* Generally this is done by returning the plugin name with `eslint-plugin-`
* appended to it (if the name does not already start with that string).
*
* Scoped plugins must be explicitly checked for to handle properly;
* Currently the `@typescript-eslint` is the only supported scoped plugin.
*
* @param {string} plugin
*
* @return {string}
Expand All @@ -57,8 +54,16 @@ const determinePluginPackageName = (plugin: string): string => {
return plugin;
}

if (plugin === '@typescript-eslint') {
return `${plugin}/eslint-plugin`;
if (plugin.startsWith('@')) {
const [scope, name] = plugin.split('/');

let packageName = `${scope}/eslint-plugin`;

if (name) {
packageName += `-${name}`;
}

return packageName;
}

return `eslint-plugin-${plugin}`;
Expand Down

0 comments on commit ec69b99

Please sign in to comment.