googlesamples / assistant-sdk-cpp

Example of Google Assistant gRPC in C++
Apache License 2.0
96 stars 44 forks source link

Apply Google's linter #49

Closed mpoullet closed 6 years ago

mpoullet commented 6 years ago
mpoullet commented 6 years ago

I'd let you fix the remaining cpplint.py issues of the like

Include the directory when naming .h files  [build/include]

and

is an unapproved C++11 header.  [build/c++11]

because I'm not sure what to do about it.

Fleker commented 6 years ago

Yeah I ran into those issues in the past. I think the first is in general a bug that may require a PR.

The second is also an issue that can be remedied with the // NOLINT comment being placed on that line.

mpoullet commented 6 years ago

I've reworked this PR to address all the issues brought up by cpplint.

Command used:

Before PR:

./src/json_util_test.cc
./src/json_util_test.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/json_util_test.cc:39:  Add #include <utility> for move  [build/include_what_you_use] [4]
Done processing ./src/json_util_test.cc
Total errors found: 2
./src/scope_exit.h
./src/scope_exit.h:17:  #ifndef header guard has wrong style, please use: SRC_SCOPE_EXIT_H_  [build/header_guard] [5]
./src/scope_exit.h:31:  #endif line should be "#endif  // SRC_SCOPE_EXIT_H_"  [build/header_guard] [5]
./src/scope_exit.h:24:  Single-parameter constructors should be marked explicit.  [runtime/explicit] [5]
Done processing ./src/scope_exit.h
Total errors found: 3
./src/audio_input_alsa.cc
./src/audio_input_alsa.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/audio_input_alsa.cc:92:  Add #include <memory> for shared_ptr<>  [build/include_what_you_use] [4]
./src/audio_input_alsa.cc:93:  Add #include <vector> for vector<>  [build/include_what_you_use] [4]
Done processing ./src/audio_input_alsa.cc
Total errors found: 3
./src/assistant_config.h
./src/assistant_config.h:17:  #ifndef header guard has wrong style, please use: SRC_ASSISTANT_CONFIG_H_  [build/header_guard] [5]
./src/assistant_config.h:23:  #endif line should be "#endif  // SRC_ASSISTANT_CONFIG_H_"  [build/header_guard] [5]
Done processing ./src/assistant_config.h
Total errors found: 2
./src/audio_input_file.cc
./src/audio_input_file.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/audio_input_file.cc:39:  Using C-style cast.  Use reinterpret_cast<char*>(...) instead  [readability/casting] [4]
./src/audio_input_file.cc:33:  Add #include <memory> for shared_ptr<>  [build/include_what_you_use] [4]
./src/audio_input_file.cc:34:  Add #include <vector> for vector<>  [build/include_what_you_use] [4]
Done processing ./src/audio_input_file.cc
Total errors found: 4
./src/run_assistant_text.cc
./src/run_assistant_text.cc:21:  <chrono> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_text.cc:27:  <thread> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_text.cc:32:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_text.cc:33:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_text.cc:34:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_text.cc:35:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_text.cc:36:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_text.cc:52:  For a static/global string constant, use a C style string instead: "static const char kCredentialsTypeUserAccount[]".  [runtime/string] [4]
./src/run_assistant_text.cc:53:  For a static/global string constant, use a C style string instead: "static const char kLanguageCode[]".  [runtime/string] [4]
./src/run_assistant_text.cc:54:  For a static/global string constant, use a C style string instead: "static const char kDeviceModelId[]".  [runtime/string] [4]
./src/run_assistant_text.cc:55:  For a static/global string constant, use a C style string instead: "static const char kDeviceInstanceId[]".  [runtime/string] [4]
Done processing ./src/run_assistant_text.cc
Total errors found: 11
./src/run_assistant_audio.cc
./src/run_assistant_audio.cc:21:  <chrono> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_audio.cc:27:  <thread> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_audio.cc:34:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:35:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:41:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:42:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:43:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:44:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:45:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_audio.cc:61:  For a static/global string constant, use a C style string instead: "static const char kCredentialsTypeUserAccount[]".  [runtime/string] [4]
./src/run_assistant_audio.cc:62:  For a static/global string constant, use a C style string instead: "static const char kALSAAudioInput[]".  [runtime/string] [4]
./src/run_assistant_audio.cc:63:  For a static/global string constant, use a C style string instead: "static const char kLanguageCode[]".  [runtime/string] [4]
./src/run_assistant_audio.cc:64:  For a static/global string constant, use a C style string instead: "static const char kDeviceModelId[]".  [runtime/string] [4]
./src/run_assistant_audio.cc:65:  For a static/global string constant, use a C style string instead: "static const char kDeviceInstanceId[]".  [runtime/string] [4]
Done processing ./src/run_assistant_audio.cc
Total errors found: 14
./src/audio_input_alsa.h
./src/audio_input_alsa.h:0:  No #ifndef header guard found, suggested CPP variable is: SRC_AUDIO_INPUT_ALSA_H_  [build/header_guard] [5]
./src/audio_input_alsa.h:17:  Include the directory when naming .h files  [build/include] [4]
./src/audio_input_alsa.h:23:  "virtual" is redundant since function is already declared as "override"  [readability/inheritance] [4]
./src/audio_input_alsa.h:23:  Add #include <memory> for unique_ptr<>  [build/include_what_you_use] [4]
Done processing ./src/audio_input_alsa.h
Total errors found: 4
./src/base64_encode.cc
./src/base64_encode.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/base64_encode.cc:44:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
Done processing ./src/base64_encode.cc
Total errors found: 2
./src/audio_output_alsa.cc
./src/audio_output_alsa.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/audio_output_alsa.cc:136:  Add #include <memory> for shared_ptr<>  [build/include_what_you_use] [4]
Done processing ./src/audio_output_alsa.cc
Total errors found: 2
./src/audio_input.h
./src/audio_input.h:17:  #ifndef header guard has wrong style, please use: SRC_AUDIO_INPUT_H_  [build/header_guard] [5]
./src/audio_input.h:102:  #endif line should be "#endif  // SRC_AUDIO_INPUT_H_"  [build/header_guard] [5]
./src/audio_input.h:23:  <mutex> is an unapproved C++11 header.  [build/c++11] [5]
./src/audio_input.h:24:  <thread> is an unapproved C++11 header.  [build/c++11] [5]
./src/audio_input.h:57:  Add #include <utility> for move  [build/include_what_you_use] [4]
Done processing ./src/audio_input.h
Total errors found: 5
./src/base64_encode.h
./src/base64_encode.h:17:  #ifndef header guard has wrong style, please use: SRC_BASE64_ENCODE_H_  [build/header_guard] [5]
./src/base64_encode.h:24:  #endif line should be "#endif  // SRC_BASE64_ENCODE_H_"  [build/header_guard] [5]
Done processing ./src/base64_encode.h
Total errors found: 2
./src/run_assistant_file.cc
./src/run_assistant_file.cc:21:  <chrono> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_file.cc:27:  <thread> is an unapproved C++11 header.  [build/c++11] [5]
./src/run_assistant_file.cc:32:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_file.cc:33:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_file.cc:34:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_file.cc:35:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_file.cc:36:  Include the directory when naming .h files  [build/include] [4]
./src/run_assistant_file.cc:51:  For a static/global string constant, use a C style string instead: "static const char kCredentialsTypeUserAccount[]".  [runtime/string] [4]
./src/run_assistant_file.cc:52:  For a static/global string constant, use a C style string instead: "static const char kLanguageCode[]".  [runtime/string] [4]
./src/run_assistant_file.cc:53:  For a static/global string constant, use a C style string instead: "static const char kDeviceModelId[]".  [runtime/string] [4]
./src/run_assistant_file.cc:54:  For a static/global string constant, use a C style string instead: "static const char kDeviceInstanceId[]".  [runtime/string] [4]
./src/run_assistant_file.cc:299:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
Done processing ./src/run_assistant_file.cc
Total errors found: 12
./src/json_util.cc
./src/json_util.cc:17:  Include the directory when naming .h files  [build/include] [4]
./src/json_util.cc:18:  Include the directory when naming .h files  [build/include] [4]
./src/json_util.cc:21:  Found C system header after other header. Should be: json_util.h, c system, c++ system, other.  [build/include_order] [4]
./src/json_util.cc:24:  Found C++ system header after other header. Should be: json_util.h, c system, c++ system, other.  [build/include_order] [4]
./src/json_util.cc:25:  Found C++ system header after other header. Should be: json_util.h, c system, c++ system, other.  [build/include_order] [4]
Done processing ./src/json_util.cc
Total errors found: 5
./src/json_util.h
./src/json_util.h:17:  #ifndef header guard has wrong style, please use: SRC_JSON_UTIL_H_  [build/header_guard] [5]
./src/json_util.h:23:  #endif line should be "#endif  // SRC_JSON_UTIL_H_"  [build/header_guard] [5]
Done processing ./src/json_util.h
Total errors found: 2
./src/audio_output_alsa.h
./src/audio_output_alsa.h:0:  No #ifndef header guard found, suggested CPP variable is: SRC_AUDIO_OUTPUT_ALSA_H_  [build/header_guard] [5]
./src/audio_output_alsa.h:17:  <condition_variable> is an unapproved C++11 header.  [build/c++11] [5]
./src/audio_output_alsa.h:18:  <mutex> is an unapproved C++11 header.  [build/c++11] [5]
./src/audio_output_alsa.h:19:  <thread> is an unapproved C++11 header.  [build/c++11] [5]
./src/audio_output_alsa.h:37:  Add #include <memory> for unique_ptr<>  [build/include_what_you_use] [4]
Done processing ./src/audio_output_alsa.h
Total errors found: 5
./src/audio_input_file.h
./src/audio_input_file.h:0:  No #ifndef header guard found, suggested CPP variable is: SRC_AUDIO_INPUT_FILE_H_  [build/header_guard] [5]
./src/audio_input_file.h:17:  Include the directory when naming .h files  [build/include] [4]
./src/audio_input_file.h:21:  Single-parameter constructors should be marked explicit.  [runtime/explicit] [5]
./src/audio_input_file.h:24:  "virtual" is redundant since function is already declared as "override"  [readability/inheritance] [4]
./src/audio_input_file.h:24:  Add #include <memory> for unique_ptr<>  [build/include_what_you_use] [4]
./src/audio_input_file.h:27:  Add #include <string> for string  [build/include_what_you_use] [4]
Done processing ./src/audio_input_file.h
Total errors found: 

After PR:

./src/assistant/json_util_test.cc
./src/assistant/scope_exit.h
./src/assistant/audio_input_alsa.cc
./src/assistant/assistant_config.h
./src/assistant/audio_input_file.cc
./src/assistant/run_assistant_text.cc
./src/assistant/run_assistant_audio.cc
./src/assistant/audio_input_alsa.h
./src/assistant/base64_encode.cc
./src/assistant/audio_output_alsa.cc
./src/assistant/audio_input.h
./src/assistant/base64_encode.h
./src/assistant/run_assistant_file.cc
./src/assistant/json_util.cc
./src/assistant/json_util.h
./src/assistant/audio_output_alsa.h
./src/assistant/audio_input_file.h
Fleker commented 6 years ago

So moving the files from src to a deeper directory resolves lint issues?

Can you add a script to pull in and run the linter, like a lint.py?

mpoullet commented 6 years ago

Yes, moving the files to a deeper directory fixes the Include the directory when naming .h files [build/include] linter errors.

I've added a small script to the tests directory, is it ok?

Fleker commented 6 years ago

Thanks