Skip to content

Commit

Permalink
fix(linter): plugin-lint-checks should allow some strings as valid ve…
Browse files Browse the repository at this point in the history
…rsions (#10647)
  • Loading branch information
AgentEnder committed Jun 9, 2022
1 parent 8c4d413 commit 7f4abd9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts
Expand Up @@ -21,6 +21,7 @@ type Options = [
executorsJson?: string;
migrationsJson?: string;
packageJson?: string;
allowedVersionStrings: string[];
}
];

Expand All @@ -29,6 +30,7 @@ const DEFAULT_OPTIONS = {
executorsJson: 'executors.json',
migrationsJson: 'migrations.json',
packageJson: 'package.json',
allowedVersionStrings: ['*', 'latest', 'next'],
};

export type MessageIds =
Expand Down Expand Up @@ -135,6 +137,7 @@ function normalizeOptions(
): Options[0] {
const base = { ...DEFAULT_OPTIONS, ...options };
return {
...base,
executorsJson: base.executorsJson
? `${sourceProject.data.root}/${base.executorsJson}`
: undefined,
Expand Down Expand Up @@ -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 },
Expand All @@ -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: {
Expand All @@ -470,11 +475,15 @@ export function validatePackageGroup(
}
}

export function validateVersionJsonExpression(node: AST.JSONExpression) {
export function validateVersionJsonExpression(
node: AST.JSONExpression,
context: TSESLint.RuleContext<MessageIds, Options>
) {
return (
node &&
node.type === 'JSONLiteral' &&
typeof node.value === 'string' &&
valid(node.value)
(valid(node.value) ||
context.options[0]?.allowedVersionStrings.includes(node.value))
);
}

0 comments on commit 7f4abd9

Please sign in to comment.