From 90f310b525bf29cb7aa232449273de36af10ee94 Mon Sep 17 00:00:00 2001
From: Nikita Titov <nekit94-08@mail.ru>
Date: Fri, 5 Jun 2020 18:53:07 +0300
Subject: [PATCH] Revert "re-order includes (fixes #3132) (#3133)" (#3153)

This reverts commit 656d2676c2174781c91747ba158cb6d27f4cacbd.
---
 R-package/src/lightgbm_R.cpp                  | 14 +++++++-------
 include/LightGBM/application.h                |  6 +++---
 include/LightGBM/bin.h                        |  8 ++++----
 include/LightGBM/boosting.h                   |  6 +++---
 include/LightGBM/c_api.h                      |  4 ++--
 include/LightGBM/config.h                     | 10 +++++-----
 include/LightGBM/dataset.h                    | 14 +++++++-------
 include/LightGBM/dataset_loader.h             |  4 ++--
 include/LightGBM/feature_group.h              |  8 ++++----
 include/LightGBM/metric.h                     |  6 +++---
 include/LightGBM/network.h                    |  8 ++++----
 include/LightGBM/objective_function.h         |  6 +++---
 include/LightGBM/prediction_early_stop.h      |  4 ++--
 include/LightGBM/tree.h                       |  6 +++---
 include/LightGBM/tree_learner.h               |  6 +++---
 include/LightGBM/utils/array_args.h           |  6 +++---
 include/LightGBM/utils/common.h               |  6 +++---
 include/LightGBM/utils/openmp_wrapper.h       |  8 ++++----
 include/LightGBM/utils/pipeline_reader.h      |  6 +++---
 include/LightGBM/utils/text_reader.h          |  8 ++++----
 include/LightGBM/utils/threading.h            |  8 ++++----
 src/application/application.cpp               | 17 ++++++++---------
 src/application/predictor.hpp                 | 12 ++++++------
 src/boosting/dart.hpp                         |  4 ++--
 src/boosting/gbdt.cpp                         |  9 ++++-----
 src/boosting/gbdt.h                           | 19 ++++++++++---------
 src/boosting/gbdt_model_text.cpp              |  9 ++++-----
 src/boosting/gbdt_prediction.cpp              |  4 ++--
 src/boosting/goss.hpp                         |  8 ++++----
 src/boosting/prediction_early_stop.cpp        |  7 +++----
 src/boosting/rf.hpp                           |  6 +++---
 src/boosting/score_updater.hpp                |  6 +++---
 src/c_api.cpp                                 | 17 ++++++++---------
 src/io/bin.cpp                                | 11 +++++------
 src/io/config.cpp                             |  5 ++---
 src/io/dataset.cpp                            | 12 ++++++------
 src/io/dataset_loader.cpp                     |  5 ++---
 src/io/dense_bin.hpp                          |  8 +++++---
 src/io/file_io.cpp                            |  7 +++----
 src/io/json11.cpp                             |  7 +++----
 src/io/metadata.cpp                           |  5 ++---
 src/io/multi_val_dense_bin.hpp                |  6 +++---
 src/io/multi_val_sparse_bin.hpp               |  6 +++---
 src/io/parser.cpp                             |  3 +--
 src/io/parser.hpp                             |  8 ++++----
 src/io/sparse_bin.hpp                         |  8 ++++----
 src/io/tree.cpp                               |  9 ++++-----
 src/main.cpp                                  |  3 +--
 src/metric/binary_metric.hpp                  |  8 ++++----
 src/metric/dcg_calculator.cpp                 |  5 ++---
 src/metric/map_metric.hpp                     | 10 +++++-----
 src/metric/multiclass_metric.hpp              |  6 +++---
 src/metric/rank_metric.hpp                    |  8 ++++----
 src/metric/regression_metric.hpp              |  6 +++---
 src/metric/xentropy_metric.hpp                | 10 +++++-----
 src/network/linker_topo.cpp                   |  7 +++----
 src/network/linkers.h                         | 10 +++++-----
 src/network/linkers_socket.cpp                |  8 ++++----
 src/network/network.cpp                       |  7 +++----
 src/network/socket_wrapper.hpp                |  4 ++--
 src/objective/binary_objective.hpp            |  6 +++---
 src/objective/multiclass_objective.hpp        |  6 +++---
 src/objective/rank_objective.hpp              |  6 +++---
 src/objective/regression_objective.hpp        |  8 ++++----
 src/objective/xentropy_objective.hpp          |  8 ++++----
 src/treelearner/col_sampler.hpp               |  6 +++---
 .../cost_effective_gradient_boosting.hpp      |  4 ++--
 src/treelearner/data_partition.hpp            |  8 ++++----
 src/treelearner/feature_histogram.hpp         |  8 ++++----
 src/treelearner/gpu_tree_learner.cpp          |  4 ++--
 src/treelearner/gpu_tree_learner.h            | 12 ++++++------
 src/treelearner/leaf_splits.hpp               |  4 ++--
 src/treelearner/parallel_tree_learner.h       |  6 +++---
 src/treelearner/serial_tree_learner.cpp       | 10 +++++-----
 src/treelearner/serial_tree_learner.h         | 14 +++++++-------
 src/treelearner/split_info.hpp                |  4 ++--
 .../voting_parallel_tree_learner.cpp          |  3 +--
 77 files changed, 282 insertions(+), 297 deletions(-)

diff --git a/R-package/src/lightgbm_R.cpp b/R-package/src/lightgbm_R.cpp
index ec2dbb79dd2f..ad144be1d60c 100644
--- a/R-package/src/lightgbm_R.cpp
+++ b/R-package/src/lightgbm_R.cpp
@@ -5,13 +5,6 @@
 
 #include "lightgbm_R.h"
 
-#include <string>
-#include <cstdio>
-#include <cstring>
-#include <memory>
-#include <utility>
-#include <vector>
-
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/openmp_wrapper.h>
@@ -19,6 +12,13 @@
 
 #include <R_ext/Rdynload.h>
 
+#include <string>
+#include <cstdio>
+#include <cstring>
+#include <memory>
+#include <utility>
+#include <vector>
+
 #define COL_MAJOR (0)
 
 #define R_API_BEGIN() \
diff --git a/include/LightGBM/application.h b/include/LightGBM/application.h
index 53f9732edea6..911dedd7d94e 100644
--- a/include/LightGBM/application.h
+++ b/include/LightGBM/application.h
@@ -5,12 +5,12 @@
 #ifndef LIGHTGBM_APPLICATION_H_
 #define LIGHTGBM_APPLICATION_H_
 
-#include <memory>
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/meta.h>
 
+#include <memory>
+#include <vector>
+
 namespace LightGBM {
 
 class DatasetLoader;
diff --git a/include/LightGBM/bin.h b/include/LightGBM/bin.h
index fab69d9ba894..96ae6a8d641b 100644
--- a/include/LightGBM/bin.h
+++ b/include/LightGBM/bin.h
@@ -5,6 +5,10 @@
 #ifndef LIGHTGBM_BIN_H_
 #define LIGHTGBM_BIN_H_
 
+#include <LightGBM/meta.h>
+#include <LightGBM/utils/common.h>
+#include <LightGBM/utils/file_io.h>
+
 #include <limits>
 #include <string>
 #include <functional>
@@ -12,10 +16,6 @@
 #include <unordered_map>
 #include <vector>
 
-#include <LightGBM/meta.h>
-#include <LightGBM/utils/common.h>
-#include <LightGBM/utils/file_io.h>
-
 namespace LightGBM {
 
 enum BinType {
diff --git a/include/LightGBM/boosting.h b/include/LightGBM/boosting.h
index f456d7989771..31bb430f0aed 100644
--- a/include/LightGBM/boosting.h
+++ b/include/LightGBM/boosting.h
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_BOOSTING_H_
 #define LIGHTGBM_BOOSTING_H_
 
+#include <LightGBM/config.h>
+#include <LightGBM/meta.h>
+
 #include <string>
 #include <map>
 #include <unordered_map>
 #include <vector>
 
-#include <LightGBM/config.h>
-#include <LightGBM/meta.h>
-
 namespace LightGBM {
 
 /*! \brief forward declaration */
diff --git a/include/LightGBM/c_api.h b/include/LightGBM/c_api.h
index e1db94c22575..2b3727bf56ec 100644
--- a/include/LightGBM/c_api.h
+++ b/include/LightGBM/c_api.h
@@ -13,12 +13,12 @@
 #ifndef LIGHTGBM_C_API_H_
 #define LIGHTGBM_C_API_H_
 
+#include <LightGBM/export.h>
+
 #include <cstdint>
 #include <cstdio>
 #include <cstring>
 
-#include <LightGBM/export.h>
-
 
 typedef void* DatasetHandle;  /*!< \brief Handle of dataset. */
 typedef void* BoosterHandle;  /*!< \brief Handle of booster. */
diff --git a/include/LightGBM/config.h b/include/LightGBM/config.h
index 1fb18b2b5162..c1aed28e02ff 100644
--- a/include/LightGBM/config.h
+++ b/include/LightGBM/config.h
@@ -11,6 +11,11 @@
 #ifndef LIGHTGBM_CONFIG_H_
 #define LIGHTGBM_CONFIG_H_
 
+#include <LightGBM/export.h>
+#include <LightGBM/meta.h>
+#include <LightGBM/utils/common.h>
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <algorithm>
 #include <memory>
@@ -18,11 +23,6 @@
 #include <unordered_set>
 #include <vector>
 
-#include <LightGBM/export.h>
-#include <LightGBM/meta.h>
-#include <LightGBM/utils/common.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 /*! \brief Types of tasks */
diff --git a/include/LightGBM/dataset.h b/include/LightGBM/dataset.h
index bd0143daffd9..e4c5dc56511c 100644
--- a/include/LightGBM/dataset.h
+++ b/include/LightGBM/dataset.h
@@ -5,6 +5,13 @@
 #ifndef LIGHTGBM_DATASET_H_
 #define LIGHTGBM_DATASET_H_
 
+#include <LightGBM/config.h>
+#include <LightGBM/feature_group.h>
+#include <LightGBM/meta.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+#include <LightGBM/utils/random.h>
+#include <LightGBM/utils/text_reader.h>
+
 #include <string>
 #include <functional>
 #include <memory>
@@ -13,13 +20,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/config.h>
-#include <LightGBM/feature_group.h>
-#include <LightGBM/meta.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-#include <LightGBM/utils/random.h>
-#include <LightGBM/utils/text_reader.h>
-
 namespace LightGBM {
 
 /*! \brief forward declaration */
diff --git a/include/LightGBM/dataset_loader.h b/include/LightGBM/dataset_loader.h
index 88443d62472d..8d5b20b481fc 100644
--- a/include/LightGBM/dataset_loader.h
+++ b/include/LightGBM/dataset_loader.h
@@ -5,12 +5,12 @@
 #ifndef LIGHTGBM_DATASET_LOADER_H_
 #define LIGHTGBM_DATASET_LOADER_H_
 
+#include <LightGBM/dataset.h>
+
 #include <string>
 #include <unordered_set>
 #include <vector>
 
-#include <LightGBM/dataset.h>
-
 namespace LightGBM {
 
 class DatasetLoader {
diff --git a/include/LightGBM/feature_group.h b/include/LightGBM/feature_group.h
index c21ad33b6a4f..d949beec20e9 100644
--- a/include/LightGBM/feature_group.h
+++ b/include/LightGBM/feature_group.h
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_FEATURE_GROUP_H_
 #define LIGHTGBM_FEATURE_GROUP_H_
 
-#include <cstdio>
-#include <memory>
-#include <vector>
-
 #include <LightGBM/bin.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/random.h>
 
+#include <cstdio>
+#include <memory>
+#include <vector>
+
 namespace LightGBM {
 
 class Dataset;
diff --git a/include/LightGBM/metric.h b/include/LightGBM/metric.h
index 56fec3aad770..61d9fc99ea80 100644
--- a/include/LightGBM/metric.h
+++ b/include/LightGBM/metric.h
@@ -5,9 +5,6 @@
 #ifndef LIGHTGBM_METRIC_H_
 #define LIGHTGBM_METRIC_H_
 
-#include <string>
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/dataset.h>
 #include <LightGBM/meta.h>
@@ -15,6 +12,9 @@
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/common.h>
 
+#include <string>
+#include <vector>
+
 namespace LightGBM {
 
 /*!
diff --git a/include/LightGBM/network.h b/include/LightGBM/network.h
index 40373508eb5f..32c24fe69845 100644
--- a/include/LightGBM/network.h
+++ b/include/LightGBM/network.h
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_NETWORK_H_
 #define LIGHTGBM_NETWORK_H_
 
-#include <functional>
-#include <memory>
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/log.h>
 
+#include <functional>
+#include <memory>
+#include <vector>
+
 namespace LightGBM {
 
 /*! \brief forward declaration */
diff --git a/include/LightGBM/objective_function.h b/include/LightGBM/objective_function.h
index 76b3f7145efb..5ea838dece23 100644
--- a/include/LightGBM/objective_function.h
+++ b/include/LightGBM/objective_function.h
@@ -5,13 +5,13 @@
 #ifndef LIGHTGBM_OBJECTIVE_FUNCTION_H_
 #define LIGHTGBM_OBJECTIVE_FUNCTION_H_
 
-#include <string>
-#include <functional>
-
 #include <LightGBM/config.h>
 #include <LightGBM/dataset.h>
 #include <LightGBM/meta.h>
 
+#include <string>
+#include <functional>
+
 namespace LightGBM {
 /*!
 * \brief The interface of Objective Function.
diff --git a/include/LightGBM/prediction_early_stop.h b/include/LightGBM/prediction_early_stop.h
index 40db533325f9..1d3e510981f4 100644
--- a/include/LightGBM/prediction_early_stop.h
+++ b/include/LightGBM/prediction_early_stop.h
@@ -5,11 +5,11 @@
 #ifndef LIGHTGBM_PREDICTION_EARLY_STOP_H_
 #define LIGHTGBM_PREDICTION_EARLY_STOP_H_
 
+#include <LightGBM/export.h>
+
 #include <string>
 #include <functional>
 
-#include <LightGBM/export.h>
-
 namespace LightGBM {
 
 struct PredictionEarlyStopInstance {
diff --git a/include/LightGBM/tree.h b/include/LightGBM/tree.h
index f1ec755d9799..467ce0c652f8 100644
--- a/include/LightGBM/tree.h
+++ b/include/LightGBM/tree.h
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_TREE_H_
 #define LIGHTGBM_TREE_H_
 
+#include <LightGBM/dataset.h>
+#include <LightGBM/meta.h>
+
 #include <string>
 #include <map>
 #include <memory>
 #include <unordered_map>
 #include <vector>
 
-#include <LightGBM/dataset.h>
-#include <LightGBM/meta.h>
-
 namespace LightGBM {
 
 #define kCategoricalMask (1)
diff --git a/include/LightGBM/tree_learner.h b/include/LightGBM/tree_learner.h
index cdb3d2823b8a..6c549a5ed71c 100644
--- a/include/LightGBM/tree_learner.h
+++ b/include/LightGBM/tree_learner.h
@@ -5,13 +5,13 @@
 #ifndef LIGHTGBM_TREE_LEARNER_H_
 #define LIGHTGBM_TREE_LEARNER_H_
 
-#include <string>
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/json11.h>
 
+#include <string>
+#include <vector>
+
 namespace LightGBM {
 
 using json11::Json;
diff --git a/include/LightGBM/utils/array_args.h b/include/LightGBM/utils/array_args.h
index a071247fb285..0183ecc22ddb 100644
--- a/include/LightGBM/utils/array_args.h
+++ b/include/LightGBM/utils/array_args.h
@@ -5,13 +5,13 @@
 #ifndef LIGHTGBM_UTILS_ARRAY_AGRS_H_
 #define LIGHTGBM_UTILS_ARRAY_AGRS_H_
 
+#include <LightGBM/utils/openmp_wrapper.h>
+#include <LightGBM/utils/threading.h>
+
 #include <algorithm>
 #include <utility>
 #include <vector>
 
-#include <LightGBM/utils/openmp_wrapper.h>
-#include <LightGBM/utils/threading.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/include/LightGBM/utils/common.h b/include/LightGBM/utils/common.h
index ed1edeb3e859..8acf62d218e9 100644
--- a/include/LightGBM/utils/common.h
+++ b/include/LightGBM/utils/common.h
@@ -5,6 +5,9 @@
 #ifndef LIGHTGBM_UTILS_COMMON_FUN_H_
 #define LIGHTGBM_UTILS_COMMON_FUN_H_
 
+#include <LightGBM/utils/log.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+
 #include <limits>
 #include <string>
 #include <algorithm>
@@ -23,9 +26,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/utils/log.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-
 #if defined(_MSC_VER)
 #include <malloc.h>
 #elif MM_MALLOC
diff --git a/include/LightGBM/utils/openmp_wrapper.h b/include/LightGBM/utils/openmp_wrapper.h
index fdd4b3850fb9..075c991371c0 100644
--- a/include/LightGBM/utils/openmp_wrapper.h
+++ b/include/LightGBM/utils/openmp_wrapper.h
@@ -6,16 +6,16 @@
 #define LIGHTGBM_OPENMP_WRAPPER_H_
 #ifdef _OPENMP
 
+#include <LightGBM/utils/log.h>
+
+#include <omp.h>
+
 #include <exception>
 #include <memory>
 #include <mutex>
 #include <stdexcept>
 #include <vector>
 
-#include <omp.h>
-
-#include <LightGBM/utils/log.h>
-
 inline int OMP_NUM_THREADS() {
   int ret = 1;
 #pragma omp parallel
diff --git a/include/LightGBM/utils/pipeline_reader.h b/include/LightGBM/utils/pipeline_reader.h
index 4e07b8b36741..f02500c9751a 100644
--- a/include/LightGBM/utils/pipeline_reader.h
+++ b/include/LightGBM/utils/pipeline_reader.h
@@ -5,6 +5,9 @@
 #ifndef LIGHTGBM_UTILS_PIPELINE_READER_H_
 #define LIGHTGBM_UTILS_PIPELINE_READER_H_
 
+#include <LightGBM/utils/file_io.h>
+#include <LightGBM/utils/log.h>
+
 #include <algorithm>
 #include <cstdio>
 #include <functional>
@@ -13,9 +16,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/utils/file_io.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/include/LightGBM/utils/text_reader.h b/include/LightGBM/utils/text_reader.h
index 7aaf7f8153a8..638bb2683627 100644
--- a/include/LightGBM/utils/text_reader.h
+++ b/include/LightGBM/utils/text_reader.h
@@ -5,16 +5,16 @@
 #ifndef LIGHTGBM_UTILS_TEXT_READER_H_
 #define LIGHTGBM_UTILS_TEXT_READER_H_
 
+#include <LightGBM/utils/log.h>
+#include <LightGBM/utils/pipeline_reader.h>
+#include <LightGBM/utils/random.h>
+
 #include <string>
 #include <cstdio>
 #include <functional>
 #include <sstream>
 #include <vector>
 
-#include <LightGBM/utils/log.h>
-#include <LightGBM/utils/pipeline_reader.h>
-#include <LightGBM/utils/random.h>
-
 namespace LightGBM {
 
 const size_t kGbs = size_t(1024) * 1024 * 1024;
diff --git a/include/LightGBM/utils/threading.h b/include/LightGBM/utils/threading.h
index dcf4f7608afc..d293fc811eb1 100644
--- a/include/LightGBM/utils/threading.h
+++ b/include/LightGBM/utils/threading.h
@@ -6,14 +6,14 @@
 #ifndef LIGHTGBM_UTILS_THREADING_H_
 #define LIGHTGBM_UTILS_THREADING_H_
 
-#include <algorithm>
-#include <functional>
-#include <vector>
-
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <algorithm>
+#include <functional>
+#include <vector>
+
 namespace LightGBM {
 
 class Threading {
diff --git a/src/application/application.cpp b/src/application/application.cpp
index a46cf419c534..1b9eabf8a120 100644
--- a/src/application/application.cpp
+++ b/src/application/application.cpp
@@ -2,15 +2,6 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <string>
-#include <chrono>
-#include <cstdio>
-#include <ctime>
-#include <fstream>
-#include <sstream>
-#include <utility>
-
 #include <LightGBM/application.h>
 
 #include <LightGBM/boosting.h>
@@ -24,6 +15,14 @@
 #include <LightGBM/utils/openmp_wrapper.h>
 #include <LightGBM/utils/text_reader.h>
 
+#include <string>
+#include <chrono>
+#include <cstdio>
+#include <ctime>
+#include <fstream>
+#include <sstream>
+#include <utility>
+
 #include "predictor.hpp"
 
 #ifdef USE_CUDA
diff --git a/src/application/predictor.hpp b/src/application/predictor.hpp
index ab775d429133..1c56cfa5eb2c 100644
--- a/src/application/predictor.hpp
+++ b/src/application/predictor.hpp
@@ -5,6 +5,12 @@
 #ifndef LIGHTGBM_PREDICTOR_HPP_
 #define LIGHTGBM_PREDICTOR_HPP_
 
+#include <LightGBM/boosting.h>
+#include <LightGBM/dataset.h>
+#include <LightGBM/meta.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+#include <LightGBM/utils/text_reader.h>
+
 #include <string>
 #include <cstdio>
 #include <cstring>
@@ -15,12 +21,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/boosting.h>
-#include <LightGBM/dataset.h>
-#include <LightGBM/meta.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-#include <LightGBM/utils/text_reader.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/src/boosting/dart.hpp b/src/boosting/dart.hpp
index b9dca6a78f2f..e2481e797729 100644
--- a/src/boosting/dart.hpp
+++ b/src/boosting/dart.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_BOOSTING_DART_H_
 #define LIGHTGBM_BOOSTING_DART_H_
 
+#include <LightGBM/boosting.h>
+
 #include <string>
 #include <algorithm>
 #include <cstdio>
 #include <fstream>
 #include <vector>
 
-#include <LightGBM/boosting.h>
-
 #include "gbdt.h"
 #include "score_updater.hpp"
 
diff --git a/src/boosting/gbdt.cpp b/src/boosting/gbdt.cpp
index c7c82afd4e92..64baba793cd9 100644
--- a/src/boosting/gbdt.cpp
+++ b/src/boosting/gbdt.cpp
@@ -2,13 +2,8 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
 #include "gbdt.h"
 
-#include <chrono>
-#include <ctime>
-#include <sstream>
-
 #include <LightGBM/metric.h>
 #include <LightGBM/network.h>
 #include <LightGBM/objective_function.h>
@@ -16,6 +11,10 @@
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <chrono>
+#include <ctime>
+#include <sstream>
+
 namespace LightGBM {
 
 #ifdef USE_CUDA
diff --git a/src/boosting/gbdt.h b/src/boosting/gbdt.h
index ba281bcd48bd..93aafabd9150 100644
--- a/src/boosting/gbdt.h
+++ b/src/boosting/gbdt.h
@@ -5,6 +5,16 @@
 #ifndef LIGHTGBM_BOOSTING_GBDT_H_
 #define LIGHTGBM_BOOSTING_GBDT_H_
 
+#ifdef USE_CUDA
+#include <LightGBM/cuda/vector_cudahost.h> //LGBM_CUDA
+#endif
+
+#include <LightGBM/boosting.h>
+#include <LightGBM/objective_function.h>
+#include <LightGBM/prediction_early_stop.h>
+#include <LightGBM/utils/json11.h>
+#include <LightGBM/utils/threading.h>
+
 #include <string>
 #include <algorithm>
 #include <cstdio>
@@ -16,15 +26,6 @@
 #include <utility>
 #include <vector>
 
-#ifdef USE_CUDA
-#include <LightGBM/cuda/vector_cudahost.h> //LGBM_CUDA
-#endif
-#include <LightGBM/boosting.h>
-#include <LightGBM/objective_function.h>
-#include <LightGBM/prediction_early_stop.h>
-#include <LightGBM/utils/json11.h>
-#include <LightGBM/utils/threading.h>
-
 #include "score_updater.hpp"
 
 namespace LightGBM {
diff --git a/src/boosting/gbdt_model_text.cpp b/src/boosting/gbdt_model_text.cpp
index 9ac4b269ac1a..5ce26bca95ca 100644
--- a/src/boosting/gbdt_model_text.cpp
+++ b/src/boosting/gbdt_model_text.cpp
@@ -2,17 +2,16 @@
  * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <string>
-#include <sstream>
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/metric.h>
 #include <LightGBM/objective_function.h>
 #include <LightGBM/utils/array_args.h>
 #include <LightGBM/utils/common.h>
 
+#include <string>
+#include <sstream>
+#include <vector>
+
 #include "gbdt.h"
 
 namespace LightGBM {
diff --git a/src/boosting/gbdt_prediction.cpp b/src/boosting/gbdt_prediction.cpp
index e906bc0aaca1..b4711f7c01a6 100644
--- a/src/boosting/gbdt_prediction.cpp
+++ b/src/boosting/gbdt_prediction.cpp
@@ -2,12 +2,12 @@
  * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-#include "gbdt.h"
-
 #include <LightGBM/objective_function.h>
 #include <LightGBM/prediction_early_stop.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include "gbdt.h"
+
 namespace LightGBM {
 
 void GBDT::PredictRaw(const double* features, double* output, const PredictionEarlyStopInstance* early_stop) const {
diff --git a/src/boosting/goss.hpp b/src/boosting/goss.hpp
index d3a3c6a344c0..2af6dee14f64 100644
--- a/src/boosting/goss.hpp
+++ b/src/boosting/goss.hpp
@@ -5,6 +5,10 @@
 #ifndef LIGHTGBM_BOOSTING_GOSS_H_
 #define LIGHTGBM_BOOSTING_GOSS_H_
 
+#include <LightGBM/boosting.h>
+#include <LightGBM/utils/array_args.h>
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <algorithm>
 #include <chrono>
@@ -12,10 +16,6 @@
 #include <fstream>
 #include <vector>
 
-#include <LightGBM/boosting.h>
-#include <LightGBM/utils/array_args.h>
-#include <LightGBM/utils/log.h>
-
 #include "gbdt.h"
 #include "score_updater.hpp"
 
diff --git a/src/boosting/prediction_early_stop.cpp b/src/boosting/prediction_early_stop.cpp
index 7eda08f00d6a..7e21141f6852 100644
--- a/src/boosting/prediction_early_stop.cpp
+++ b/src/boosting/prediction_early_stop.cpp
@@ -2,16 +2,15 @@
  * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/prediction_early_stop.h>
+
+#include <LightGBM/utils/log.h>
 
 #include <limits>
 #include <algorithm>
 #include <cmath>
 #include <vector>
 
-#include <LightGBM/prediction_early_stop.h>
-
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 PredictionEarlyStopInstance CreateNone(const PredictionEarlyStopConfig&) {
diff --git a/src/boosting/rf.hpp b/src/boosting/rf.hpp
index c9c9718e89d1..6b72eebf0a4f 100644
--- a/src/boosting/rf.hpp
+++ b/src/boosting/rf.hpp
@@ -5,6 +5,9 @@
 #ifndef LIGHTGBM_BOOSTING_RF_H_
 #define LIGHTGBM_BOOSTING_RF_H_
 
+#include <LightGBM/boosting.h>
+#include <LightGBM/metric.h>
+
 #include <string>
 #include <cstdio>
 #include <fstream>
@@ -12,9 +15,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/boosting.h>
-#include <LightGBM/metric.h>
-
 #include "gbdt.h"
 #include "score_updater.hpp"
 
diff --git a/src/boosting/score_updater.hpp b/src/boosting/score_updater.hpp
index 231de245068c..7446691a4709 100644
--- a/src/boosting/score_updater.hpp
+++ b/src/boosting/score_updater.hpp
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_BOOSTING_SCORE_UPDATER_HPP_
 #define LIGHTGBM_BOOSTING_SCORE_UPDATER_HPP_
 
-#include <cstring>
-#include <vector>
-
 #include <LightGBM/dataset.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/tree.h>
 #include <LightGBM/tree_learner.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <cstring>
+#include <vector>
+
 namespace LightGBM {
 /*!
 * \brief Used to store and update score for data
diff --git a/src/c_api.cpp b/src/c_api.cpp
index 81c0724eec12..9e8069d7c864 100644
--- a/src/c_api.cpp
+++ b/src/c_api.cpp
@@ -2,15 +2,6 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <string>
-#include <cstdio>
-#include <functional>
-#include <memory>
-#include <mutex>
-#include <stdexcept>
-#include <vector>
-
 #include <LightGBM/c_api.h>
 
 #include <LightGBM/boosting.h>
@@ -31,6 +22,14 @@
 #include <LightGBM/cuda/vector_cudahost.h>
 #endif
 
+#include <string>
+#include <cstdio>
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <stdexcept>
+#include <vector>
+
 #include "application/predictor.hpp"
 
 namespace LightGBM {
diff --git a/src/io/bin.cpp b/src/io/bin.cpp
index 9ead232fda02..367edaa3f7b9 100644
--- a/src/io/bin.cpp
+++ b/src/io/bin.cpp
@@ -2,18 +2,17 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <algorithm>
-#include <cmath>
-#include <cstdint>
-#include <cstring>
-
 #include <LightGBM/bin.h>
 
 #include <LightGBM/utils/array_args.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/file_io.h>
 
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <cstring>
+
 #include "dense_bin.hpp"
 #include "multi_val_dense_bin.hpp"
 #include "multi_val_sparse_bin.hpp"
diff --git a/src/io/config.cpp b/src/io/config.cpp
index fd630dcdf037..c6a2dd6714bc 100644
--- a/src/io/config.cpp
+++ b/src/io/config.cpp
@@ -2,15 +2,14 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <limits>
-
 #include <LightGBM/config.h>
 
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/random.h>
 
+#include <limits>
+
 namespace LightGBM {
 
 void Config::KV2Map(std::unordered_map<std::string, std::string>* params, const char* kv) {
diff --git a/src/io/dataset.cpp b/src/io/dataset.cpp
index 1001a9432cee..b34757310cac 100644
--- a/src/io/dataset.cpp
+++ b/src/io/dataset.cpp
@@ -8,12 +8,6 @@
 #include <LightGBM/cuda/vector_cudahost.h>
 #endif
 
-#include <chrono>
-#include <cstdio>
-#include <limits>
-#include <sstream>
-#include <unordered_map>
-
 #include <LightGBM/dataset.h>
 
 #include <LightGBM/feature_group.h>
@@ -21,6 +15,12 @@
 #include <LightGBM/utils/openmp_wrapper.h>
 #include <LightGBM/utils/threading.h>
 
+#include <chrono>
+#include <cstdio>
+#include <limits>
+#include <sstream>
+#include <unordered_map>
+
 namespace LightGBM {
 
 const char* Dataset::binary_file_token =
diff --git a/src/io/dataset_loader.cpp b/src/io/dataset_loader.cpp
index 33ce1df7eb05..c0b2edf1a8c3 100644
--- a/src/io/dataset_loader.cpp
+++ b/src/io/dataset_loader.cpp
@@ -2,9 +2,6 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <fstream>
-
 #include <LightGBM/dataset_loader.h>
 
 #include <LightGBM/network.h>
@@ -13,6 +10,8 @@
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <fstream>
+
 namespace LightGBM {
 
 using json11::Json;
diff --git a/src/io/dense_bin.hpp b/src/io/dense_bin.hpp
index d7f839bffe39..8bba639121d3 100644
--- a/src/io/dense_bin.hpp
+++ b/src/io/dense_bin.hpp
@@ -6,9 +6,7 @@
 #ifndef LIGHTGBM_IO_DENSE_BIN_HPP_
 #define LIGHTGBM_IO_DENSE_BIN_HPP_
 
-#include <cstdint>
-#include <cstring>
-#include <vector>
+#include <LightGBM/bin.h>
 
 #ifdef USE_CUDA
 #include <LightGBM/cuda/vector_cudahost.h> // LGBM_CUDA
@@ -17,6 +15,10 @@
 #include <LightGBM/utils/openmp_wrapper.h> // LGBM_CUDA
 #include <LightGBM/bin.h>
 
+#include <cstdint>
+#include <cstring>
+#include <vector>
+
 namespace LightGBM {
 
 template <typename VAL_T, bool IS_4BIT>
diff --git a/src/io/file_io.cpp b/src/io/file_io.cpp
index 67a719de0a8e..a205964287e9 100644
--- a/src/io/file_io.cpp
+++ b/src/io/file_io.cpp
@@ -3,15 +3,14 @@
  * Licensed under the MIT License. See LICENSE file in the project root for
  * license information.
  */
+#include <LightGBM/utils/file_io.h>
+
+#include <LightGBM/utils/log.h>
 
 #include <algorithm>
 #include <sstream>
 #include <unordered_map>
 
-#include <LightGBM/utils/file_io.h>
-
-#include <LightGBM/utils/log.h>
-
 #ifdef USE_HDFS
 #include <hdfs.h>
 #endif
diff --git a/src/io/json11.cpp b/src/io/json11.cpp
index a3fec7724b50..db21c6aab544 100644
--- a/src/io/json11.cpp
+++ b/src/io/json11.cpp
@@ -18,16 +18,15 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include <LightGBM/utils/json11.h>
+
+#include <LightGBM/utils/log.h>
 
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
 #include <limits>
 
-#include <LightGBM/utils/json11.h>
-
-#include <LightGBM/utils/log.h>
-
 namespace json11 {
 
 static const int max_depth = 200;
diff --git a/src/io/metadata.cpp b/src/io/metadata.cpp
index 9b540045650b..ea0d5b08def8 100644
--- a/src/io/metadata.cpp
+++ b/src/io/metadata.cpp
@@ -2,13 +2,12 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/dataset.h>
+#include <LightGBM/utils/common.h>
 
 #include <string>
 #include <vector>
 
-#include <LightGBM/dataset.h>
-#include <LightGBM/utils/common.h>
-
 namespace LightGBM {
 
 Metadata::Metadata() {
diff --git a/src/io/multi_val_dense_bin.hpp b/src/io/multi_val_dense_bin.hpp
index d7c6599c381b..7645530d774b 100644
--- a/src/io/multi_val_dense_bin.hpp
+++ b/src/io/multi_val_dense_bin.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_IO_MULTI_VAL_DENSE_BIN_HPP_
 #define LIGHTGBM_IO_MULTI_VAL_DENSE_BIN_HPP_
 
+#include <LightGBM/bin.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+
 #include <algorithm>
 #include <cstdint>
 #include <cstring>
 #include <vector>
 
-#include <LightGBM/bin.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-
 namespace LightGBM {
 
 template <typename VAL_T>
diff --git a/src/io/multi_val_sparse_bin.hpp b/src/io/multi_val_sparse_bin.hpp
index 09c13420c660..ec3f64a11a02 100644
--- a/src/io/multi_val_sparse_bin.hpp
+++ b/src/io/multi_val_sparse_bin.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_IO_MULTI_VAL_SPARSE_BIN_HPP_
 #define LIGHTGBM_IO_MULTI_VAL_SPARSE_BIN_HPP_
 
+#include <LightGBM/bin.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+
 #include <algorithm>
 #include <cstdint>
 #include <cstring>
 #include <vector>
 
-#include <LightGBM/bin.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-
 namespace LightGBM {
 
 template <typename INDEX_T, typename VAL_T>
diff --git a/src/io/parser.cpp b/src/io/parser.cpp
index c30da4305f94..df14ea87a99d 100644
--- a/src/io/parser.cpp
+++ b/src/io/parser.cpp
@@ -2,6 +2,7 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include "parser.hpp"
 
 #include <string>
 #include <algorithm>
@@ -10,8 +11,6 @@
 #include <iostream>
 #include <memory>
 
-#include "parser.hpp"
-
 namespace LightGBM {
 
 void GetStatistic(const char* str, int* comma_cnt, int* tab_cnt, int* colon_cnt) {
diff --git a/src/io/parser.hpp b/src/io/parser.hpp
index 43764a68e754..1cfde0635a57 100644
--- a/src/io/parser.hpp
+++ b/src/io/parser.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_IO_PARSER_HPP_
 #define LIGHTGBM_IO_PARSER_HPP_
 
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
 #include <LightGBM/dataset.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
 namespace LightGBM {
 
 class CSVParser: public Parser {
diff --git a/src/io/sparse_bin.hpp b/src/io/sparse_bin.hpp
index 730ea161a2a6..c56cd6da99d5 100644
--- a/src/io/sparse_bin.hpp
+++ b/src/io/sparse_bin.hpp
@@ -6,6 +6,10 @@
 #ifndef LIGHTGBM_IO_SPARSE_BIN_HPP_
 #define LIGHTGBM_IO_SPARSE_BIN_HPP_
 
+#include <LightGBM/bin.h>
+#include <LightGBM/utils/log.h>
+#include <LightGBM/utils/openmp_wrapper.h>
+
 #include <algorithm>
 #include <cstdint>
 #include <cstring>
@@ -13,10 +17,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/bin.h>
-#include <LightGBM/utils/log.h>
-#include <LightGBM/utils/openmp_wrapper.h>
-
 namespace LightGBM {
 
 template <typename VAL_T>
diff --git a/src/io/tree.cpp b/src/io/tree.cpp
index 3c997055a745..be928b7e3124 100644
--- a/src/io/tree.cpp
+++ b/src/io/tree.cpp
@@ -2,17 +2,16 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <functional>
-#include <iomanip>
-#include <sstream>
-
 #include <LightGBM/tree.h>
 
 #include <LightGBM/dataset.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/threading.h>
 
+#include <functional>
+#include <iomanip>
+#include <sstream>
+
 namespace LightGBM {
 
 Tree::Tree(int max_leaves)
diff --git a/src/main.cpp b/src/main.cpp
index 0a8931ae4ff7..ef277ac0c1f5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,11 +2,10 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/application.h>
 
 #include <iostream>
 
-#include <LightGBM/application.h>
-
 #include "network/linkers.h"
 
 int main(int argc, char** argv) {
diff --git a/src/metric/binary_metric.hpp b/src/metric/binary_metric.hpp
index 5bde453cdbae..00a51d6cd24e 100644
--- a/src/metric/binary_metric.hpp
+++ b/src/metric/binary_metric.hpp
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_METRIC_BINARY_METRIC_HPP_
 #define LIGHTGBM_METRIC_BINARY_METRIC_HPP_
 
+#include <LightGBM/metric.h>
+#include <LightGBM/utils/common.h>
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <algorithm>
 #include <sstream>
 #include <vector>
 
-#include <LightGBM/metric.h>
-#include <LightGBM/utils/common.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/src/metric/dcg_calculator.cpp b/src/metric/dcg_calculator.cpp
index cd477612bdc2..58843d89f9e1 100644
--- a/src/metric/dcg_calculator.cpp
+++ b/src/metric/dcg_calculator.cpp
@@ -2,14 +2,13 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/metric.h>
+#include <LightGBM/utils/log.h>
 
 #include <algorithm>
 #include <cmath>
 #include <vector>
 
-#include <LightGBM/metric.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 /*! \brief Declaration for some static members */
diff --git a/src/metric/map_metric.hpp b/src/metric/map_metric.hpp
index b373a02b56f1..18539ee44ee0 100644
--- a/src/metric/map_metric.hpp
+++ b/src/metric/map_metric.hpp
@@ -5,16 +5,16 @@
 #ifndef LIGHTGBM_METRIC_MAP_METRIC_HPP_
 #define LIGHTGBM_METRIC_MAP_METRIC_HPP_
 
-#include <string>
-#include <algorithm>
-#include <sstream>
-#include <vector>
-
 #include <LightGBM/metric.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <string>
+#include <algorithm>
+#include <sstream>
+#include <vector>
+
 namespace LightGBM {
 
 class MapMetric:public Metric {
diff --git a/src/metric/multiclass_metric.hpp b/src/metric/multiclass_metric.hpp
index f60588cac3fc..59548cd3a794 100644
--- a/src/metric/multiclass_metric.hpp
+++ b/src/metric/multiclass_metric.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_METRIC_MULTICLASS_METRIC_HPP_
 #define LIGHTGBM_METRIC_MULTICLASS_METRIC_HPP_
 
+#include <LightGBM/metric.h>
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <cmath>
 #include <utility>
 #include <vector>
 
-#include <LightGBM/metric.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 /*!
 * \brief Metric for multiclass task.
diff --git a/src/metric/rank_metric.hpp b/src/metric/rank_metric.hpp
index d92275020090..3b3afb547eb9 100644
--- a/src/metric/rank_metric.hpp
+++ b/src/metric/rank_metric.hpp
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_METRIC_RANK_METRIC_HPP_
 #define LIGHTGBM_METRIC_RANK_METRIC_HPP_
 
-#include <string>
-#include <sstream>
-#include <vector>
-
 #include <LightGBM/metric.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 
+#include <string>
+#include <sstream>
+#include <vector>
+
 namespace LightGBM {
 
 class NDCGMetric:public Metric {
diff --git a/src/metric/regression_metric.hpp b/src/metric/regression_metric.hpp
index 3085bc941b34..4d1a36621424 100644
--- a/src/metric/regression_metric.hpp
+++ b/src/metric/regression_metric.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_METRIC_REGRESSION_METRIC_HPP_
 #define LIGHTGBM_METRIC_REGRESSION_METRIC_HPP_
 
+#include <LightGBM/metric.h>
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <algorithm>
 #include <cmath>
 #include <vector>
 
-#include <LightGBM/metric.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 /*!
 * \brief Metric for regression task.
diff --git a/src/metric/xentropy_metric.hpp b/src/metric/xentropy_metric.hpp
index 1b86e60e6406..bec611d28e54 100644
--- a/src/metric/xentropy_metric.hpp
+++ b/src/metric/xentropy_metric.hpp
@@ -5,16 +5,16 @@
 #ifndef LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
 #define LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
 
-#include <string>
-#include <algorithm>
-#include <sstream>
-#include <vector>
-
 #include <LightGBM/meta.h>
 #include <LightGBM/metric.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 
+#include <string>
+#include <algorithm>
+#include <sstream>
+#include <vector>
+
 /*
  * Implements three related metrics:
  *
diff --git a/src/network/linker_topo.cpp b/src/network/linker_topo.cpp
index 102fdc993cd2..1d7b2990f0e1 100644
--- a/src/network/linker_topo.cpp
+++ b/src/network/linker_topo.cpp
@@ -2,15 +2,14 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/network.h>
+#include <LightGBM/utils/common.h>
+#include <LightGBM/utils/log.h>
 
 #include <string>
 #include <unordered_map>
 #include <vector>
 
-#include <LightGBM/network.h>
-#include <LightGBM/utils/common.h>
-#include <LightGBM/utils/log.h>
-
 namespace LightGBM {
 
 
diff --git a/src/network/linkers.h b/src/network/linkers.h
index 5a91d40f73de..8ddbb902a152 100644
--- a/src/network/linkers.h
+++ b/src/network/linkers.h
@@ -5,6 +5,11 @@
 #ifndef LIGHTGBM_NETWORK_LINKERS_H_
 #define LIGHTGBM_NETWORK_LINKERS_H_
 
+#include <LightGBM/config.h>
+#include <LightGBM/meta.h>
+#include <LightGBM/network.h>
+#include <LightGBM/utils/common.h>
+
 #include <string>
 #include <algorithm>
 #include <chrono>
@@ -13,11 +18,6 @@
 #include <thread>
 #include <vector>
 
-#include <LightGBM/config.h>
-#include <LightGBM/meta.h>
-#include <LightGBM/network.h>
-#include <LightGBM/utils/common.h>
-
 #ifdef USE_SOCKET
 #include "socket_wrapper.hpp"
 #endif
diff --git a/src/network/linkers_socket.cpp b/src/network/linkers_socket.cpp
index 708e3ae9bad5..40c6de7aab66 100644
--- a/src/network/linkers_socket.cpp
+++ b/src/network/linkers_socket.cpp
@@ -4,6 +4,10 @@
  */
 #ifdef USE_SOCKET
 
+#include <LightGBM/config.h>
+#include <LightGBM/utils/common.h>
+#include <LightGBM/utils/text_reader.h>
+
 #include <string>
 #include <chrono>
 #include <cstring>
@@ -12,10 +16,6 @@
 #include <unordered_set>
 #include <vector>
 
-#include <LightGBM/config.h>
-#include <LightGBM/utils/common.h>
-#include <LightGBM/utils/text_reader.h>
-
 #include "linkers.h"
 
 namespace LightGBM {
diff --git a/src/network/network.cpp b/src/network/network.cpp
index cbc241d88c66..3976d72a6926 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -2,14 +2,13 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
-
-#include <cstdlib>
-#include <cstring>
-
 #include <LightGBM/network.h>
 
 #include <LightGBM/utils/common.h>
 
+#include <cstdlib>
+#include <cstring>
+
 #include "linkers.h"
 
 namespace LightGBM {
diff --git a/src/network/socket_wrapper.hpp b/src/network/socket_wrapper.hpp
index 87bd88f934ae..70f9586b99c5 100644
--- a/src/network/socket_wrapper.hpp
+++ b/src/network/socket_wrapper.hpp
@@ -6,13 +6,13 @@
 #define LIGHTGBM_NETWORK_SOCKET_WRAPPER_HPP_
 #ifdef USE_SOCKET
 
+#include <LightGBM/utils/log.h>
+
 #include <string>
 #include <cerrno>
 #include <cstdlib>
 #include <unordered_set>
 
-#include <LightGBM/utils/log.h>
-
 #if defined(_WIN32)
 
 #ifdef _MSC_VER
diff --git a/src/objective/binary_objective.hpp b/src/objective/binary_objective.hpp
index dff3a9c10979..4861bd1b83f8 100644
--- a/src/objective/binary_objective.hpp
+++ b/src/objective/binary_objective.hpp
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_OBJECTIVE_BINARY_OBJECTIVE_HPP_
 #define LIGHTGBM_OBJECTIVE_BINARY_OBJECTIVE_HPP_
 
+#include <LightGBM/network.h>
+#include <LightGBM/objective_function.h>
+
 #include <string>
 #include <algorithm>
 #include <cmath>
 #include <cstring>
 #include <vector>
 
-#include <LightGBM/network.h>
-#include <LightGBM/objective_function.h>
-
 namespace LightGBM {
 /*!
 * \brief Objective function for binary classification
diff --git a/src/objective/multiclass_objective.hpp b/src/objective/multiclass_objective.hpp
index da604baeb499..c133e1f75fdf 100644
--- a/src/objective/multiclass_objective.hpp
+++ b/src/objective/multiclass_objective.hpp
@@ -5,6 +5,9 @@
 #ifndef LIGHTGBM_OBJECTIVE_MULTICLASS_OBJECTIVE_HPP_
 #define LIGHTGBM_OBJECTIVE_MULTICLASS_OBJECTIVE_HPP_
 
+#include <LightGBM/network.h>
+#include <LightGBM/objective_function.h>
+
 #include <string>
 #include <algorithm>
 #include <cmath>
@@ -12,9 +15,6 @@
 #include <memory>
 #include <vector>
 
-#include <LightGBM/network.h>
-#include <LightGBM/objective_function.h>
-
 #include "binary_objective.hpp"
 
 namespace LightGBM {
diff --git a/src/objective/rank_objective.hpp b/src/objective/rank_objective.hpp
index 730d358f030d..1b20721e238b 100644
--- a/src/objective/rank_objective.hpp
+++ b/src/objective/rank_objective.hpp
@@ -6,6 +6,9 @@
 #ifndef LIGHTGBM_OBJECTIVE_RANK_OBJECTIVE_HPP_
 #define LIGHTGBM_OBJECTIVE_RANK_OBJECTIVE_HPP_
 
+#include <LightGBM/metric.h>
+#include <LightGBM/objective_function.h>
+
 #include <algorithm>
 #include <cmath>
 #include <cstdio>
@@ -14,9 +17,6 @@
 #include <string>
 #include <vector>
 
-#include <LightGBM/metric.h>
-#include <LightGBM/objective_function.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/src/objective/regression_objective.hpp b/src/objective/regression_objective.hpp
index fe391f2c15fe..53fa7020be55 100644
--- a/src/objective/regression_objective.hpp
+++ b/src/objective/regression_objective.hpp
@@ -5,14 +5,14 @@
 #ifndef LIGHTGBM_OBJECTIVE_REGRESSION_OBJECTIVE_HPP_
 #define LIGHTGBM_OBJECTIVE_REGRESSION_OBJECTIVE_HPP_
 
-#include <string>
-#include <algorithm>
-#include <vector>
-
 #include <LightGBM/meta.h>
 #include <LightGBM/objective_function.h>
 #include <LightGBM/utils/array_args.h>
 
+#include <string>
+#include <algorithm>
+#include <vector>
+
 namespace LightGBM {
 
 #define PercentileFun(T, data_reader, cnt_data, alpha)                    \
diff --git a/src/objective/xentropy_objective.hpp b/src/objective/xentropy_objective.hpp
index 3a145bd2cbb4..cad2b8faafd3 100644
--- a/src/objective/xentropy_objective.hpp
+++ b/src/objective/xentropy_objective.hpp
@@ -5,16 +5,16 @@
 #ifndef LIGHTGBM_OBJECTIVE_XENTROPY_OBJECTIVE_HPP_
 #define LIGHTGBM_OBJECTIVE_XENTROPY_OBJECTIVE_HPP_
 
+#include <LightGBM/meta.h>
+#include <LightGBM/objective_function.h>
+#include <LightGBM/utils/common.h>
+
 #include <string>
 #include <algorithm>
 #include <cmath>
 #include <cstring>
 #include <vector>
 
-#include <LightGBM/meta.h>
-#include <LightGBM/objective_function.h>
-#include <LightGBM/utils/common.h>
-
 /*
  * Implements gradients and hessians for the following point losses.
  * Target y is anything in interval [0, 1].
diff --git a/src/treelearner/col_sampler.hpp b/src/treelearner/col_sampler.hpp
index 8cc667c75afb..68a98d159271 100644
--- a/src/treelearner/col_sampler.hpp
+++ b/src/treelearner/col_sampler.hpp
@@ -6,15 +6,15 @@
 #ifndef LIGHTGBM_TREELEARNER_COL_SAMPLER_HPP_
 #define LIGHTGBM_TREELEARNER_COL_SAMPLER_HPP_
 
-#include <algorithm>
-#include <vector>
-
 #include <LightGBM/dataset.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 #include <LightGBM/utils/random.h>
 
+#include <algorithm>
+#include <vector>
+
 namespace LightGBM {
 class ColSampler {
  public:
diff --git a/src/treelearner/cost_effective_gradient_boosting.hpp b/src/treelearner/cost_effective_gradient_boosting.hpp
index fda2bffc8206..fad966e64877 100644
--- a/src/treelearner/cost_effective_gradient_boosting.hpp
+++ b/src/treelearner/cost_effective_gradient_boosting.hpp
@@ -5,13 +5,13 @@
 #ifndef LIGHTGBM_TREELEARNER_COST_EFFECTIVE_GRADIENT_BOOSTING_HPP_
 #define LIGHTGBM_TREELEARNER_COST_EFFECTIVE_GRADIENT_BOOSTING_HPP_
 
-#include <vector>
-
 #include <LightGBM/config.h>
 #include <LightGBM/dataset.h>
 #include <LightGBM/utils/common.h>
 #include <LightGBM/utils/log.h>
 
+#include <vector>
+
 #include "data_partition.hpp"
 #include "serial_tree_learner.h"
 #include "split_info.hpp"
diff --git a/src/treelearner/data_partition.hpp b/src/treelearner/data_partition.hpp
index bdae960c1d9f..01c5d2606e71 100644
--- a/src/treelearner/data_partition.hpp
+++ b/src/treelearner/data_partition.hpp
@@ -5,15 +5,15 @@
 #ifndef LIGHTGBM_TREELEARNER_DATA_PARTITION_HPP_
 #define LIGHTGBM_TREELEARNER_DATA_PARTITION_HPP_
 
-#include <algorithm>
-#include <cstring>
-#include <vector>
-
 #include <LightGBM/dataset.h>
 #include <LightGBM/meta.h>
 #include <LightGBM/utils/openmp_wrapper.h>
 #include <LightGBM/utils/threading.h>
 
+#include <algorithm>
+#include <cstring>
+#include <vector>
+
 namespace LightGBM {
 /*!
 * \brief DataPartition is used to store the the partition of data on tree.
diff --git a/src/treelearner/feature_histogram.hpp b/src/treelearner/feature_histogram.hpp
index 4dd5f29af0aa..8916ee48fd40 100644
--- a/src/treelearner/feature_histogram.hpp
+++ b/src/treelearner/feature_histogram.hpp
@@ -6,6 +6,10 @@
 #ifndef LIGHTGBM_TREELEARNER_FEATURE_HISTOGRAM_HPP_
 #define LIGHTGBM_TREELEARNER_FEATURE_HISTOGRAM_HPP_
 
+#include <LightGBM/bin.h>
+#include <LightGBM/dataset.h>
+#include <LightGBM/utils/array_args.h>
+
 #include <algorithm>
 #include <cmath>
 #include <cstring>
@@ -13,10 +17,6 @@
 #include <utility>
 #include <vector>
 
-#include <LightGBM/bin.h>
-#include <LightGBM/dataset.h>
-#include <LightGBM/utils/array_args.h>
-
 #include "monotone_constraints.hpp"
 #include "split_info.hpp"
 
diff --git a/src/treelearner/gpu_tree_learner.cpp b/src/treelearner/gpu_tree_learner.cpp
index 411e216b2148..400b6ab90bf2 100644
--- a/src/treelearner/gpu_tree_learner.cpp
+++ b/src/treelearner/gpu_tree_learner.cpp
@@ -6,12 +6,12 @@
 
 #include "gpu_tree_learner.h"
 
-#include <algorithm>
-
 #include <LightGBM/bin.h>
 #include <LightGBM/network.h>
 #include <LightGBM/utils/array_args.h>
 
+#include <algorithm>
+
 #include "../io/dense_bin.hpp"
 
 #define GPU_DEBUG 0
diff --git a/src/treelearner/gpu_tree_learner.h b/src/treelearner/gpu_tree_learner.h
index 19f696f48f5c..937474dd671d 100644
--- a/src/treelearner/gpu_tree_learner.h
+++ b/src/treelearner/gpu_tree_learner.h
@@ -5,6 +5,12 @@
 #ifndef LIGHTGBM_TREELEARNER_GPU_TREE_LEARNER_H_
 #define LIGHTGBM_TREELEARNER_GPU_TREE_LEARNER_H_
 
+#include <LightGBM/dataset.h>
+#include <LightGBM/feature_group.h>
+#include <LightGBM/tree.h>
+#include <LightGBM/utils/array_args.h>
+#include <LightGBM/utils/random.h>
+
 #include <string>
 #include <cmath>
 #include <cstdio>
@@ -12,12 +18,6 @@
 #include <random>
 #include <vector>
 
-#include <LightGBM/dataset.h>
-#include <LightGBM/feature_group.h>
-#include <LightGBM/tree.h>
-#include <LightGBM/utils/array_args.h>
-#include <LightGBM/utils/random.h>
-
 #include "data_partition.hpp"
 #include "feature_histogram.hpp"
 #include "leaf_splits.hpp"
diff --git a/src/treelearner/leaf_splits.hpp b/src/treelearner/leaf_splits.hpp
index 5c94846eb7b6..b0a753eafe1b 100644
--- a/src/treelearner/leaf_splits.hpp
+++ b/src/treelearner/leaf_splits.hpp
@@ -5,11 +5,11 @@
 #ifndef LIGHTGBM_TREELEARNER_LEAF_SPLITS_HPP_
 #define LIGHTGBM_TREELEARNER_LEAF_SPLITS_HPP_
 
+#include <LightGBM/meta.h>
+
 #include <limits>
 #include <vector>
 
-#include <LightGBM/meta.h>
-
 #include "data_partition.hpp"
 
 namespace LightGBM {
diff --git a/src/treelearner/parallel_tree_learner.h b/src/treelearner/parallel_tree_learner.h
index 59503499ea90..070b3105affc 100644
--- a/src/treelearner/parallel_tree_learner.h
+++ b/src/treelearner/parallel_tree_learner.h
@@ -5,13 +5,13 @@
 #ifndef LIGHTGBM_TREELEARNER_PARALLEL_TREE_LEARNER_H_
 #define LIGHTGBM_TREELEARNER_PARALLEL_TREE_LEARNER_H_
 
+#include <LightGBM/network.h>
+#include <LightGBM/utils/array_args.h>
+
 #include <cstring>
 #include <memory>
 #include <vector>
 
-#include <LightGBM/network.h>
-#include <LightGBM/utils/array_args.h>
-
 #include "gpu_tree_learner.h"
 #include "serial_tree_learner.h"
 #include "cuda_tree_learner.h"
diff --git a/src/treelearner/serial_tree_learner.cpp b/src/treelearner/serial_tree_learner.cpp
index 169d7935e40d..e548d07d1230 100644
--- a/src/treelearner/serial_tree_learner.cpp
+++ b/src/treelearner/serial_tree_learner.cpp
@@ -4,16 +4,16 @@
  */
 #include "serial_tree_learner.h"
 
-#include <algorithm>
-#include <queue>
-#include <unordered_map>
-#include <utility>
-
 #include <LightGBM/network.h>
 #include <LightGBM/objective_function.h>
 #include <LightGBM/utils/array_args.h>
 #include <LightGBM/utils/common.h>
 
+#include <algorithm>
+#include <queue>
+#include <unordered_map>
+#include <utility>
+
 #include "cost_effective_gradient_boosting.hpp"
 
 namespace LightGBM {
diff --git a/src/treelearner/serial_tree_learner.h b/src/treelearner/serial_tree_learner.h
index 16f160b55f56..eded538288cb 100644
--- a/src/treelearner/serial_tree_learner.h
+++ b/src/treelearner/serial_tree_learner.h
@@ -5,13 +5,6 @@
 #ifndef LIGHTGBM_TREELEARNER_SERIAL_TREE_LEARNER_H_
 #define LIGHTGBM_TREELEARNER_SERIAL_TREE_LEARNER_H_
 
-#include <string>
-#include <cmath>
-#include <cstdio>
-#include <memory>
-#include <random>
-#include <vector>
-
 #include <LightGBM/dataset.h>
 #include <LightGBM/tree.h>
 #include <LightGBM/tree_learner.h>
@@ -19,6 +12,13 @@
 #include <LightGBM/utils/json11.h>
 #include <LightGBM/utils/random.h>
 
+#include <string>
+#include <cmath>
+#include <cstdio>
+#include <memory>
+#include <random>
+#include <vector>
+
 #include "col_sampler.hpp"
 #include "data_partition.hpp"
 #include "feature_histogram.hpp"
diff --git a/src/treelearner/split_info.hpp b/src/treelearner/split_info.hpp
index 72dd3fa324cc..492434d5160f 100644
--- a/src/treelearner/split_info.hpp
+++ b/src/treelearner/split_info.hpp
@@ -5,6 +5,8 @@
 #ifndef LIGHTGBM_TREELEARNER_SPLIT_INFO_HPP_
 #define LIGHTGBM_TREELEARNER_SPLIT_INFO_HPP_
 
+#include <LightGBM/meta.h>
+
 #include <limits>
 #include <cmath>
 #include <cstdint>
@@ -12,8 +14,6 @@
 #include <functional>
 #include <vector>
 
-#include <LightGBM/meta.h>
-
 namespace LightGBM {
 
 /*!
diff --git a/src/treelearner/voting_parallel_tree_learner.cpp b/src/treelearner/voting_parallel_tree_learner.cpp
index b1d671eb2a52..9485d1f2fe5f 100644
--- a/src/treelearner/voting_parallel_tree_learner.cpp
+++ b/src/treelearner/voting_parallel_tree_learner.cpp
@@ -2,13 +2,12 @@
  * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
  * Licensed under the MIT License. See LICENSE file in the project root for license information.
  */
+#include <LightGBM/utils/common.h>
 
 #include <cstring>
 #include <tuple>
 #include <vector>
 
-#include <LightGBM/utils/common.h>
-
 #include "parallel_tree_learner.h"
 
 namespace LightGBM {