Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Mar 24, 2025

Proposed changes

Jira ticket: CLOUDP-272000

Adds xgen-IPA-112-boolean-field-names-avoid-is-prefix rule

47 violations are found to be exempted in the MMS code

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review March 24, 2025 10:08
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner March 24, 2025 10:08
Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM

Comment on lines 17 to 25
if (property.type === 'boolean') {
if (IS_PREFIX_REGEX.test(input)) {
const suggestedName = input.charAt(2).toLowerCase() + input.slice(3);
const errorMessage = `Boolean field "${input}" should not use the "is" prefix. Use "${suggestedName}" instead.`;
return collectAndReturnViolation(path, RULE_NAME, errorMessage);
}
}

collectAdoption(path, RULE_NAME);
Copy link
Collaborator

@lovisaberggren lovisaberggren Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (property.type === 'boolean') {
if (IS_PREFIX_REGEX.test(input)) {
const suggestedName = input.charAt(2).toLowerCase() + input.slice(3);
const errorMessage = `Boolean field "${input}" should not use the "is" prefix. Use "${suggestedName}" instead.`;
return collectAndReturnViolation(path, RULE_NAME, errorMessage);
}
}
collectAdoption(path, RULE_NAME);
if (property.type !== 'boolean') {
return;
}
if (IS_PREFIX_REGEX.test(input)) {
const suggestedName = input.charAt(2).toLowerCase() + input.slice(3);
const errorMessage = `Boolean field "${input}" should not use the "is" prefix. Use "${suggestedName}" instead.`;
return collectAndReturnViolation(path, RULE_NAME, errorMessage);
}
collectAdoption(path, RULE_NAME);

Right now it would collect adoption for all properties that aren't booleans

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, nice catch!

Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yelizhenden-mdb yelizhenden-mdb merged commit 9884dbe into main Mar 24, 2025
8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-272000 branch March 24, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants