Skip to content

Add clang-tidy checks for Firestore #1078

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

Merged
merged 5 commits into from
Apr 12, 2018
Merged

Add clang-tidy checks for Firestore #1078

merged 5 commits into from
Apr 12, 2018

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented Apr 12, 2018

For now this is only really visible via CLion, when you disable the "use IDE configure" for the clang-tidy inspection.

I've run out of time trying to get CMake to also run these checks though this is something I also want to do.

wilhuff added 5 commits April 12, 2018 14:17
  * typedef -> using
  * const ref + rvalue ref -> pass by value
  * NULL -> nullptr
  * remove useless default initializations
  * remove useless const value-type parameter declarations (definitions
    can still use them)
  * use auto instead of repeating types in a cast
@@ -72,7 +72,7 @@ class Serializer {
// TODO(rsgowman): If we never support any output except to a vector, it may
// make sense to have Serializer own the vector and provide an accessor rather
// than asking the user to create it first.
static util::Status EncodeFieldValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

could you elaborate why remove static here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests instantiate the serializer and then access these static methods through the instance, which causes a warning under clang-tidy.

In the fullness of time the serializer will need to be stateful (for example, to encode a DocumentKey you need to know the current DatabaseId) so fixing those warnings by removing the static seemed like the better way.

@@ -47,7 +47,7 @@ class ComparatorHolder {
template <typename C>
class ComparatorHolder<C, true> : private C {
protected:
explicit ComparatorHolder(const C&) noexcept {
explicit ComparatorHolder(const C& /* comparator */) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put the parameter name outside of comment like
explicit ComparatorHolder(const C& comparator) noexcept {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That causes a different warning about an unused parameter. This way both the compiler and the linter are happy.

I could also do

explicit ComparatorHolder(const C& comparator) noexcept {
  (void)comparator;
}

But considered this to be inferior. I have no strong preference though.

Copy link
Contributor

@zxu123 zxu123 left a comment

Choose a reason for hiding this comment

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

SGTM, thank you for the explanation.

@wilhuff wilhuff merged commit 8876622 into master Apr 12, 2018
@wilhuff wilhuff deleted the wilhuff/clang-tidy branch April 12, 2018 21:54
minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
* Add a .clang-tidy configuration for Firestore C++

* Fix clang-tidy warnings

  * typedef -> using
  * const ref + rvalue ref -> pass by value
  * NULL -> nullptr
  * remove useless default initializations
  * remove useless const value-type parameter declarations (definitions
    can still use them)
  * use auto instead of repeating types in a cast

* Fix typos

* Address use of static method through instance warnings

* Address use after move warnings
@firebase firebase locked and limited conversation to collaborators Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants