From 7f4abd9e3ce456caae3b75c99bcc7bcaae8abe07 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 9 Jun 2022 09:27:31 -0400 Subject: [PATCH] fix(linter): plugin-lint-checks should allow some strings as valid versions (#10647) --- .../src/rules/nx-plugin-checks.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts index 904f2e105e220..9c252f53cd6e7 100644 --- a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts +++ b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts @@ -21,6 +21,7 @@ type Options = [ executorsJson?: string; migrationsJson?: string; packageJson?: string; + allowedVersionStrings: string[]; } ]; @@ -29,6 +30,7 @@ const DEFAULT_OPTIONS = { executorsJson: 'executors.json', migrationsJson: 'migrations.json', packageJson: 'package.json', + allowedVersionStrings: ['*', 'latest', 'next'], }; export type MessageIds = @@ -135,6 +137,7 @@ function normalizeOptions( ): Options[0] { const base = { ...DEFAULT_OPTIONS, ...options }; return { + ...base, executorsJson: base.executorsJson ? `${sourceProject.data.root}/${base.executorsJson}` : undefined, @@ -437,7 +440,9 @@ export function validatePackageGroup( const key = (packageNode?.value as AST.JSONLiteral)?.value ?? 'unknown'; if (versionPropertyNode) { - if (!validateVersionJsonExpression(versionPropertyNode.value)) + if ( + !validateVersionJsonExpression(versionPropertyNode.value, context) + ) context.report({ messageId: 'invalidVersion', data: { key }, @@ -456,7 +461,7 @@ export function validatePackageGroup( const properties = packageGroupNode.value.properties; // For each property, ensure its value is a valid version for (const propertyNode of properties) { - if (!validateVersionJsonExpression(propertyNode.value)) { + if (!validateVersionJsonExpression(propertyNode.value, context)) { context.report({ messageId: 'invalidVersion', data: { @@ -470,11 +475,15 @@ export function validatePackageGroup( } } -export function validateVersionJsonExpression(node: AST.JSONExpression) { +export function validateVersionJsonExpression( + node: AST.JSONExpression, + context: TSESLint.RuleContext +) { return ( node && node.type === 'JSONLiteral' && typeof node.value === 'string' && - valid(node.value) + (valid(node.value) || + context.options[0]?.allowedVersionStrings.includes(node.value)) ); }