diff --git a/.eslintrc.js b/.eslintrc.js index 787edae242..54f9e69576 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,13 +24,17 @@ module.exports = { 'error', { // TODO: Fix these either by right role or by moving things to new packages - // TODO: Additionally remove the '**/*.{test,spec}.[jt]s?(x)' from `excludedFiles` in `no-mixed-plugin-imports` - // and fix the errors excludedTargetPackages: [ '@backstage/plugin-catalog', '@backstage/plugin-techdocs', '@backstage/plugin-app', - '@backstage/plugin-catalog-backend' + '@backstage/plugin-catalog-backend', + '@backstage/test-utils', + '@backstage/plugin-auth-backend', + '@backstage/plugin-permission-backend', + '@backstage/plugin-kubernetes-backend', + '@backstage/config-loader', + '@backstage/plugin-app-backend' ], } ], diff --git a/packages/eslint-plugin/rules/no-mixed-plugin-imports.js b/packages/eslint-plugin/rules/no-mixed-plugin-imports.js index 0ed4367ce2..b5e79b509e 100644 --- a/packages/eslint-plugin/rules/no-mixed-plugin-imports.js +++ b/packages/eslint-plugin/rules/no-mixed-plugin-imports.js @@ -68,6 +68,7 @@ module.exports = { 'Use web library {{targetPackage}}-react or common library instead.', useNodePlugin: 'Use node library {{targetPackage}}-node or common library instead.', + useCommonPlugin: 'Use common library {{targetPackage}}-common instead.', removeImport: 'Remove this import to avoid mixed plugin imports. Fix the code by refactoring it to use the correct plugin type.', }, @@ -90,6 +91,11 @@ module.exports = { items: { type: 'string' }, uniqueItems: true, }, + includedFiles: { + type: 'array', + items: { type: 'string' }, + uniqueItems: true, + }, }, additionalProperties: false, }, @@ -115,12 +121,14 @@ module.exports = { /** @type {string[]} */ const ignoreTargetPackages = options.excludedTargetPackages || []; /** @type {string[]} */ - const ignorePatterns = options.excludedFiles || [ - '**/*.{test,spec}.[jt]s?(x)', - '**/dev/index.[jt]s?(x)', - ]; + const excludePatterns = options.excludedFiles || []; + /** @type {string[]} */ + const includePatterns = options.includedFiles || ['**/src/**']; - if (ignorePatterns.some(pattern => matchesPattern(pattern, filePath))) { + if ( + !includePatterns.some(pattern => matchesPattern(pattern, filePath)) || + excludePatterns.some(pattern => matchesPattern(pattern, filePath)) + ) { return {}; } @@ -170,6 +178,19 @@ module.exports = { return fixer.replaceText(imp.node, newImport); }, }); + suggest.push({ + messageId: 'useCommonPlugin', + data: { + targetPackage: targetName, + }, + /** @param {import('eslint').Rule.RuleFixer} fixer */ + fix(fixer) { + const source = context.sourceCode; + const nodeSource = source.getText(imp.node); + const newImport = nodeSource.replace(/'$/, "-common'"); + return fixer.replaceText(imp.node, newImport); + }, + }); } else if ( (sourceRole === 'backend-plugin' || sourceRole === 'backend-plugin-module') && @@ -188,6 +209,19 @@ module.exports = { return fixer.replaceText(imp.node, newImport); }, }); + suggest.push({ + messageId: 'useCommonPlugin', + data: { + targetPackage: targetName, + }, + /** @param {import('eslint').Rule.RuleFixer} fixer */ + fix(fixer) { + const source = context.sourceCode; + const nodeSource = source.getText(imp.node); + const newImport = nodeSource.replace(/-backend'$/, '-common'); + return fixer.replaceText(imp.node, newImport); + }, + }); } else { suggest.push({ messageId: 'removeImport', diff --git a/plugins/catalog-backend-module-logs/package.json b/plugins/catalog-backend-module-logs/package.json index 3fad09bcb1..481ffba3ad 100644 --- a/plugins/catalog-backend-module-logs/package.json +++ b/plugins/catalog-backend-module-logs/package.json @@ -35,7 +35,6 @@ "dependencies": { "@backstage/backend-plugin-api": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", - "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-events-node": "workspace:^" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index ebb1d05132..d3fc3ea273 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5995,7 +5995,6 @@ __metadata: "@backstage/backend-test-utils": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" - "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-events-backend-test-utils": "workspace:^" "@backstage/plugin-events-node": "workspace:^" languageName: unknown