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

Improve coding standard #1136

Merged
merged 3 commits into from
Jul 20, 2023
Merged

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jul 20, 2023

This adds a rule requiring arrow functions to our coding standard. In addition to that, I enabled a rule requiring single quotes where possible. Commits are split by rule for a better review experience.

The last commit entails no actual changes, this was left over from before we were specifying a PHP version in the config.

@alcaeus alcaeus requested review from jmikola and GromNaN July 20, 2023 09:56
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

LGTM.

&& $method->getFileName() === $class->getFileName(); // Exclude methods inherited from traits
},
fn (ReflectionMethod $method) => $method->getDeclaringClass() == $class // Exclude inherited methods
&& $method->getFileName() === $class->getFileName(),
Copy link
Member

Choose a reason for hiding this comment

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

You lost the 2nd comment

Suggested change
&& $method->getFileName() === $class->getFileName(),
&& $method->getFileName() === $class->getFileName(), // Exclude methods inherited from traits

Copy link
Member Author

Choose a reason for hiding this comment

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

Lesson learned: don't trust phpcbf to preserve your comments.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

One question but LGTM.

<property name="enableMixedTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableUnionTypeHint" value="false" />
</properties>
Copy link
Member

Choose a reason for hiding this comment

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

Why were these removed for parameters, properties, and return types? Is it irrelevant since we're forcing a lower php_version above?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is correct. When I added the config we didn't use php_version yet, so I added these as a safeguard against for when someone runs phpcs on a newer version (I typically run PHP 8.2 these days and only use an older version if necessary for specific testing). This came to bite me when phpcs didn't enforce native property types because the property was still set to false in this block.

With php_version this becomes irrelevant and the version set there takes precedence over the PHP version being used to run phpcs, so the auto-detection for those features works again and does not enable mixed types or union types until we update php_version to 80000.

@alcaeus alcaeus merged commit 9e1971c into mongodb:master Jul 20, 2023
@alcaeus alcaeus deleted the improve-coding-standard branch July 20, 2023 14:49
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.

3 participants