diff options
author | Derek Bailey <derekbailey@google.com> | 2020-06-26 11:16:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 11:16:02 -0700 |
commit | 60b6066febe67eb58d9444c8137b0e820729a088 (patch) | |
tree | 2ad3ef1fff2d1e733eeaa7ffe42f4a7b598cf0ce /src/idl_parser.cpp | |
parent | 35d45cac7a3895228402627f21e7d46ec85a7b95 (diff) | |
download | flatbuffers-60b6066febe67eb58d9444c8137b0e820729a088.tar.gz flatbuffers-60b6066febe67eb58d9444c8137b0e820729a088.tar.bz2 flatbuffers-60b6066febe67eb58d9444c8137b0e820729a088.zip |
Add warning to schema parser if field name is not snake_case. (#6005)
* Added code gen for evolution tests back in.
* General generate code and clang format
* Added code gen for evolution tests back in.
* General generate code and clang format
* reran generate_code.sh
* Added code gen for evolution tests back in.
* General generate code and clang format
* Added code gen for evolution tests back in.
* General generate code and clang format
* Enforce snake_case for schema field names
* Switched to basic for loop, Fixed warning message
Diffstat (limited to 'src/idl_parser.cpp')
-rw-r--r-- | src/idl_parser.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 897bf8e7..6faca7ac 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -82,6 +82,16 @@ static bool ValidateUTF8(const std::string &str) { return true; } +static bool IsLowerSnakeCase(const std::string &str) { + for (size_t i = 0; i < str.length(); i++) { + char c = str[i]; + if (!check_ascii_range(c, 'a', 'z') && !is_digit(c) && c != '_') { + return false; + } + } + return true; +} + // Convert an underscore_based_indentifier in to camelCase. // Also uppercases the first character if first is true. std::string MakeCamel(const std::string &in, bool first) { @@ -671,6 +681,10 @@ CheckedError Parser::ParseField(StructDef &struct_def) { if (LookupCreateStruct(name, false, false)) return Error("field name can not be the same as table/struct name"); + if (!IsLowerSnakeCase(name)) { + Warning("field names should be lowercase snake_case, got: " + name); + } + std::vector<std::string> dc = doc_comment_; EXPECT(kTokenIdentifier); EXPECT(':'); |