[A] Added clang-tidy support

This commit is contained in:
seleznevae 2019-01-01 21:43:21 +03:00
parent 926d32e069
commit 4943f941d4
9 changed files with 88 additions and 19 deletions

42
.clang-tidy Normal file
View File

@ -0,0 +1,42 @@
---
# Configure clang-tidy for this project.
# Disabled:
# -google-readability-namespace-comments the BIGTABLE_CLIENT_NS is a macro, and
# clang-tidy fails to match it against the initial value.
Checks: >-
bugprone-*,
#google-readability-*,
misc-*,
modernize-*,
#readability-identifier-naming,
#readability-*,
performance-*,
-google-readability-namespace-comments,
-readability-named-parameter
# Enable most warnings as errors.
WarningsAsErrors: >-
bugprone-*,
clang-*,
google-*,
misc-*,
modernize-*,
#readability-identifier-naming,
#readability-*,
performance-*
#CheckOptions:
# - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
# - { key: readability-identifier-naming.ClassCase, value: lower_case }
# - { key: readability-identifier-naming.StructCase, value: lower_case }
# - { key: readability-identifier-naming.TemplateParameterCase, value: lower_case }
# - { key: readability-identifier-naming.FunctionCase, value: lower_case }
# - { key: readability-identifier-naming.VariableCase, value: lower_case }
# - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
# - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
# - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
# - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
# - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE }
# - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
# - { key: readability-identifier-naming.MemberConstantCase, value: UPPER_CASE }

View File

@ -27,7 +27,13 @@ matrix:
os: linux os: linux
sudo: required # to prevent fail of executables build with clang and sanitizers sudo: required # to prevent fail of executables build with clang and sanitizers
compiler: clang compiler: clang
env: CC=clang env:
- CC=clang
- BASIC_LINUX_CLANG=yes
addons:
apt:
sources: ['llvm-toolchain-trusty-4.0']
packages: ['clang-tidy-4.0']
# Linux / GCC # Linux / GCC
- name: "Linux gcc-4.9" - name: "Linux gcc-4.9"
@ -142,6 +148,15 @@ script:
cppcheck --std=c++11 --enable=warning,style,performance,portability,information,missingInclude --error-exitcode=1 lib cppcheck --std=c++11 --enable=warning,style,performance,portability,information,missingInclude --error-exitcode=1 lib
fi fi
# clang-tidy run
- |
if [ "${BASIC_LINUX_CLANG}" = "yes" ]; then
# don't know how force warnings of clang-tidy to be errors
cp .clang-tidy lib
clang-tidy -dump-config lib/fort.c
fi
# doxygen run # doxygen run
- | - |
if [ "${BASIC_LINUX_GCC}" = "yes" ]; then if [ "${BASIC_LINUX_GCC}" = "yes" ]; then

View File

@ -74,8 +74,8 @@ SOFTWARE.
#define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1)) #define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1))
#define MAX(a,b) ((a) > (b) ? (a) : b) #define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : b) #define MIN(a,b) ((a) < (b) ? (a) : (b))
enum PolicyOnNull { enum PolicyOnNull {
@ -208,7 +208,7 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str);
#define CHECK_NOT_NEGATIVE(x) \ #define CHECK_NOT_NEGATIVE(x) \
do { if (x < 0) goto fort_fail; } while (0) do { if ((x) < 0) goto fort_fail; } while (0)
#endif /* FORT_IMPL_H */ #endif /* FORT_IMPL_H */
@ -253,13 +253,14 @@ void *vector_at(vector_t *, size_t index);
FT_INTERNAL FT_INTERNAL
fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos); fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos);
/*
#define FOR_EACH_(type, item, vector, index_name) \ #define FOR_EACH_(type, item, vector, index_name) \
size_t index_name = 0; \ size_t index_name = 0; \
for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name) for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name)
#define FOR_EACH(type, item, vector) \ #define FOR_EACH(type, item, vector) \
FOR_EACH_(type, item, vector, UNIQUE_NAME(i)) FOR_EACH_(type, item, vector, UNIQUE_NAME(i))
*/
#ifdef FT_TEST_BUILD #ifdef FT_TEST_BUILD
@ -392,7 +393,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz
#define PROP_IS_SET(ft_props, property) ((ft_props) & (property)) #define PROP_IS_SET(ft_props, property) ((ft_props) & (property))
#define PROP_SET(ft_props, property) ((ft_props) |=(property)) #define PROP_SET(ft_props, property) ((ft_props) |=(property))
#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)property)) #define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)(property)))
#define TEXT_STYLE_TAG_MAX_SIZE 64 #define TEXT_STYLE_TAG_MAX_SIZE 64
@ -3407,12 +3408,10 @@ size_t max_border_elem_strlen(struct fort_table_properties *properties)
result = MAX(result, strlen(properties->border_style.border_chars[i])); result = MAX(result, strlen(properties->border_style.border_chars[i]));
} }
i = 0;
for (i = 0; i < BorderItemPosSize; ++i) { for (i = 0; i < BorderItemPosSize; ++i) {
result = MAX(result, strlen(properties->border_style.header_border_chars[i])); result = MAX(result, strlen(properties->border_style.header_border_chars[i]));
} }
i = 0;
for (i = 0; i < SepratorItemPosSize; ++i) { for (i = 0; i < SepratorItemPosSize; ++i) {
result = MAX(result, strlen(properties->border_style.separator_chars[i])); result = MAX(result, strlen(properties->border_style.separator_chars[i]));
} }
@ -5312,6 +5311,7 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col
*cols = 0; *cols = 0;
if (table && table->rows) { if (table && table->rows) {
*rows = vector_size(table->rows); *rows = vector_size(table->rows);
/*
fort_row_t *row = NULL; fort_row_t *row = NULL;
FOR_EACH(fort_row_t *, row, table->rows) { FOR_EACH(fort_row_t *, row, table->rows) {
(void)i0; (void)i0;
@ -5319,6 +5319,13 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col
if (cols_in_row > *cols) if (cols_in_row > *cols)
*cols = cols_in_row; *cols = cols_in_row;
} }
*/
for (size_t row_index = 0; row_index < vector_size(table->rows); ++row_index) {
fort_row_t *row = *(fort_row_t**)vector_at(table->rows, row_index);
size_t cols_in_row = columns_in_row(row);
if (cols_in_row > *cols)
*cols = cols_in_row;
}
} }
return FT_SUCCESS; return FT_SUCCESS;
} }
@ -5380,7 +5387,6 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
} }
if (combined_cells_found) { if (combined_cells_found) {
col = 0;
for (col = 0; col < cols; ++col) { for (col = 0; col < cols; ++col) {
size_t row = 0; size_t row = 0;
for (row = 0; row < rows; ++row) { for (row = 0; row < rows; ++row) {

View File

@ -37,8 +37,8 @@
#define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1)) #define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1))
#define MAX(a,b) ((a) > (b) ? (a) : b) #define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : b) #define MIN(a,b) ((a) < (b) ? (a) : (b))
enum PolicyOnNull { enum PolicyOnNull {
@ -171,6 +171,6 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str);
#define CHECK_NOT_NEGATIVE(x) \ #define CHECK_NOT_NEGATIVE(x) \
do { if (x < 0) goto fort_fail; } while (0) do { if ((x) < 0) goto fort_fail; } while (0)
#endif /* FORT_IMPL_H */ #endif /* FORT_IMPL_H */

View File

@ -955,12 +955,10 @@ size_t max_border_elem_strlen(struct fort_table_properties *properties)
result = MAX(result, strlen(properties->border_style.border_chars[i])); result = MAX(result, strlen(properties->border_style.border_chars[i]));
} }
i = 0;
for (i = 0; i < BorderItemPosSize; ++i) { for (i = 0; i < BorderItemPosSize; ++i) {
result = MAX(result, strlen(properties->border_style.header_border_chars[i])); result = MAX(result, strlen(properties->border_style.header_border_chars[i]));
} }
i = 0;
for (i = 0; i < SepratorItemPosSize; ++i) { for (i = 0; i < SepratorItemPosSize; ++i) {
result = MAX(result, strlen(properties->border_style.separator_chars[i])); result = MAX(result, strlen(properties->border_style.separator_chars[i]));
} }

View File

@ -7,7 +7,7 @@
#define PROP_IS_SET(ft_props, property) ((ft_props) & (property)) #define PROP_IS_SET(ft_props, property) ((ft_props) & (property))
#define PROP_SET(ft_props, property) ((ft_props) |=(property)) #define PROP_SET(ft_props, property) ((ft_props) |=(property))
#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)property)) #define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)(property)))
#define TEXT_STYLE_TAG_MAX_SIZE 64 #define TEXT_STYLE_TAG_MAX_SIZE 64

View File

@ -612,7 +612,7 @@ fort_row_t *create_row_from_string(const char *str)
char_type *pos = NULL; char_type *pos = NULL;
char_type *base_pos = NULL; char_type *base_pos = NULL;
unsigned int number_of_separators = 0; size_t number_of_separators = 0;
fort_row_t *row = create_row(); fort_row_t *row = create_row();
if (row == NULL) if (row == NULL)
@ -701,7 +701,7 @@ fort_row_t *create_row_from_wstring(const wchar_t *str)
char_type *pos = NULL; char_type *pos = NULL;
char_type *base_pos = NULL; char_type *base_pos = NULL;
unsigned int number_of_separators = 0; size_t number_of_separators = 0;
fort_row_t *row = create_row(); fort_row_t *row = create_row();
if (row == NULL) if (row == NULL)

View File

@ -108,6 +108,7 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col
*cols = 0; *cols = 0;
if (table && table->rows) { if (table && table->rows) {
*rows = vector_size(table->rows); *rows = vector_size(table->rows);
/*
fort_row_t *row = NULL; fort_row_t *row = NULL;
FOR_EACH(fort_row_t *, row, table->rows) { FOR_EACH(fort_row_t *, row, table->rows) {
(void)i0; (void)i0;
@ -115,6 +116,13 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col
if (cols_in_row > *cols) if (cols_in_row > *cols)
*cols = cols_in_row; *cols = cols_in_row;
} }
*/
for (size_t row_index = 0; row_index < vector_size(table->rows); ++row_index) {
fort_row_t *row = *(fort_row_t**)vector_at(table->rows, row_index);
size_t cols_in_row = columns_in_row(row);
if (cols_in_row > *cols)
*cols = cols_in_row;
}
} }
return FT_SUCCESS; return FT_SUCCESS;
} }
@ -176,7 +184,6 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
} }
if (combined_cells_found) { if (combined_cells_found) {
col = 0;
for (col = 0; col < cols; ++col) { for (col = 0; col < cols; ++col) {
size_t row = 0; size_t row = 0;
for (row = 0; row < rows; ++row) { for (row = 0; row < rows; ++row) {

View File

@ -30,13 +30,14 @@ void *vector_at(vector_t *, size_t index);
FT_INTERNAL FT_INTERNAL
fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos); fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos);
/*
#define FOR_EACH_(type, item, vector, index_name) \ #define FOR_EACH_(type, item, vector, index_name) \
size_t index_name = 0; \ size_t index_name = 0; \
for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name) for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name)
#define FOR_EACH(type, item, vector) \ #define FOR_EACH(type, item, vector) \
FOR_EACH_(type, item, vector, UNIQUE_NAME(i)) FOR_EACH_(type, item, vector, UNIQUE_NAME(i))
*/
#ifdef FT_TEST_BUILD #ifdef FT_TEST_BUILD