From e49ce569771b6ad5ae1cca2a18b8eca3738c6389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Mon, 9 Oct 2023 23:04:53 +0200 Subject: [PATCH] fix(linter): fix validateDependenciesSectionExistance fixer (#19512) --- .../eslint-plugin/src/rules/dependency-checks.spec.ts | 1 + packages/eslint-plugin/src/rules/dependency-checks.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/src/rules/dependency-checks.spec.ts b/packages/eslint-plugin/src/rules/dependency-checks.spec.ts index 3c2f18a347d45..98b540b7c39fa 100644 --- a/packages/eslint-plugin/src/rules/dependency-checks.spec.ts +++ b/packages/eslint-plugin/src/rules/dependency-checks.spec.ts @@ -329,6 +329,7 @@ describe('Dependency checks (eslint)', () => { "{ "name": "@mycompany/liba", "dependencies": { + "external1": "~16.1.2" } }" `); diff --git a/packages/eslint-plugin/src/rules/dependency-checks.ts b/packages/eslint-plugin/src/rules/dependency-checks.ts index d31bb2f6edb73..190ef955d40d4 100644 --- a/packages/eslint-plugin/src/rules/dependency-checks.ts +++ b/packages/eslint-plugin/src/rules/dependency-checks.ts @@ -299,15 +299,15 @@ export default createESLintRule({ .join(), }, fix: (fixer) => { - const dependencies = Object.keys(projPackageJsonDeps) - .map((d) => `\n "${d}": "${projPackageJsonDeps[d]}"`) - .join(','); - expectedDependencyNames.sort().reduce((acc, d) => { acc[d] = rootPackageJsonDeps[d] || dependencies[d]; return acc; }, projPackageJsonDeps); + const dependencies = Object.keys(projPackageJsonDeps) + .map((d) => `\n "${d}": "${projPackageJsonDeps[d]}"`) + .join(','); + if (!node.properties.length) { return fixer.replaceText( node as any,