Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): plugin-lint-checks should allow some strings as valid versions #10647

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts
Original file line number Diff line number Diff line change
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))
);
}