Skip to content

Commit d6d2717

Browse files
committed
clean up code
1 parent c42d5ca commit d6d2717

File tree

116 files changed

+1714
-1910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1714
-1910
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ jobs:
1919
- { os: macos-latest, target: darwin, platform: darwin-arm64}
2020
- { os: windows-latest, target: windows, platform: win32-x64 }
2121
steps:
22-
- uses: actions/checkout@v2
22+
- uses: nodejs/setup-node@v3
23+
with:
24+
node-version: '16'
25+
- uses: actions/checkout@v3
2326
with:
2427
ref: refs/heads/master
2528
- name: install gcc 11

.github/workflows/codestyle.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CodeStyle
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
clang-format:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
with:
14+
ref: ${{ github.event.pull_request.head.sha }}
15+
- name: Install ClangFormat
16+
run: sudo apt-get install -y clang-format
17+
- name: Run ClangFormat
18+
run: clang-format -style=file -output-replacements-xml $(find . -name '*.cpp' -or -name '*.h' -not -path "./3rd/*" -not -path "./Test/*" -not -path "./Test2/*") | grep -c '<replacement ' > /tmp/clang-format-result
19+
- name: Comment on pull request
20+
uses: actions/github-script@v4
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
const fs = require('fs');
25+
const result = fs.readFileSync('/tmp/clang-format-result', 'utf8');
26+
const comment = `ClangFormat check found ${result} formatting issues.`;
27+
github.issues.createComment({
28+
issue_number: context.issue.number,
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
body: comment
32+
});

.github/workflows/pr.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- master
7+
types: [opened, synchronize]
78

89
jobs:
910
build:
@@ -17,7 +18,10 @@ jobs:
1718
- { os: macos-latest, target: darwin, platform: darwin-arm64}
1819
- { os: windows-latest, target: windows, platform: win32-x64 }
1920
steps:
20-
- uses: actions/checkout@v2
21+
- uses: nodejs/setup-node@v3
22+
with:
23+
node-version: '16'
24+
- uses: actions/checkout@v3
2125
- name: install gcc 11
2226
if: startsWith(matrix.os, 'ubuntu')
2327
run: |
@@ -38,7 +42,7 @@ jobs:
3842
run: |
3943
mkdir build
4044
cd build
41-
cmake .. -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF
45+
cmake .. -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF -DCMAKE_BUILD_TYPE=Release
4246
cmake --build . --config Release
4347
ctest -V -C Release
4448
cmake --install . --config Release --prefix ${{ github.workspace }}/artifact/
@@ -48,16 +52,16 @@ jobs:
4852
mkdir build
4953
cd build
5054
if [[ "${{ matrix.platform }}" = darwin-arm64 ]]; then
51-
cmake .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF
55+
cmake .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF -DCMAKE_BUILD_TYPE=Release
5256
else
53-
cmake .. -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF
57+
cmake .. -DBUILD_GMOCK=OFF -DINSTALL_GTEST=OFF -DCMAKE_BUILD_TYPE=Release
5458
fi
5559
cmake --build . --config Release
5660
ctest -V -C Release
5761
cmake --install . --config Release --prefix ${{ github.workspace }}/artifact/
5862
5963
- name: Upload
60-
uses: actions/upload-artifact@v2
64+
uses: actions/upload-artifact@v3
6165
with:
6266
name: ${{ matrix.platform }}
6367
path: ${{ github.workspace }}/artifact/

CodeFormat/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ add_executable(CodeFormat)
77
add_dependencies(CodeFormat CodeFormatCore Util)
88

99
target_include_directories(CodeFormat PRIVATE
10-
src
10+
src
1111
)
1212

1313
target_sources(CodeFormat
14-
PRIVATE
15-
src/CodeFormat.cpp
16-
src/LuaFormat.cpp
14+
PRIVATE
15+
src/CodeFormat.cpp
16+
src/LuaFormat.cpp
1717
)
1818

1919
target_link_libraries(CodeFormat CodeFormatCore Util)
2020

21-
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
22-
target_link_libraries(CodeFormat -static-libstdc++ -static-libgcc)
23-
endif()
21+
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
22+
target_link_libraries(CodeFormat -static-libstdc++ -static-libgcc)
23+
endif ()
2424

2525
install(
26-
TARGETS CodeFormat
27-
LIBRARY DESTINATION lib
28-
RUNTIME DESTINATION bin
26+
TARGETS CodeFormat
27+
LIBRARY DESTINATION lib
28+
RUNTIME DESTINATION bin
2929
)

CodeFormat/src/LuaFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LuaFormat {
5050
void SetFormatRange(bool rangeLine, std::string_view rangeStr);
5151

5252
void SupportNonStandardLua();
53+
5354
private:
5455
std::optional<std::string> ReadFile(std::string_view path);
5556

@@ -58,7 +59,7 @@ class LuaFormat {
5859
void DiagnosticInspection(std::string_view message, TextRange range, std::shared_ptr<LuaSource> file,
5960
std::string_view path);
6061

61-
bool ReformatSingleFile(std::string_view inputPath, std::string_view outPath, std::string&& sourceText);
62+
bool ReformatSingleFile(std::string_view inputPath, std::string_view outPath, std::string &&sourceText);
6263

6364
bool ReformatWorkspace();
6465

CodeFormat/src/Types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
22

3-
#include <string_view>
4-
#include <memory>
53
#include "CodeFormatCore/Config/LuaEditorConfig.h"
4+
#include <memory>
5+
#include <string_view>
66

77

88
struct LuaConfig {
99
explicit LuaConfig(std::string_view workspace)
10-
: Workspace(workspace), Editorconfig(nullptr) {}
10+
: Workspace(workspace), Editorconfig(nullptr) {}
1111

1212
std::string Workspace;
1313
std::shared_ptr<LuaEditorConfig> Editorconfig;

CodeFormatCore/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ target_include_directories(CodeFormatCore
1111
include
1212
PRIVATE
1313
src
14-
)
14+
)
1515

1616
target_sources(CodeFormatCore
1717
PRIVATE
@@ -33,11 +33,12 @@ target_sources(CodeFormatCore
3333
src/Format/Analyzer/FormatDocAnalyze.cpp
3434
src/Format/Analyzer/AlignAnalyzer.cpp
3535
src/Format/Analyzer/TokenAnalyzer.cpp
36-
src/Format/Analyzer/SemicolonAnalyzer.cpp
36+
src/Format/Analyzer/SemicolonAnalyzer.cpp
3737
src/Format/Analyzer/FormatResolve.cpp
3838
src/Format/Analyzer/SyntaxNodeHelper.cpp
3939
# rangeFormat
4040
src/RangeFormat/RangeFormatBuilder.cpp
41+
# src/RangeFormat/MultiRangesFormatBuilder.cpp
4142
# typeFormat
4243
src/TypeFormat/LuaTypeFormat.cpp
4344
src/TypeFormat/LuaTypeFormatFeatures.cpp
@@ -51,7 +52,7 @@ target_sources(CodeFormatCore
5152
src/Diagnostic/Spell/Util.cpp
5253
# diagnostic/codestyle
5354
src/Diagnostic/CodeStyle/CodeStyleChecker.cpp
54-
)
55+
)
5556

5657
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5758
target_compile_options(CodeFormatCore PUBLIC /utf-8)
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
#pragma once
22

3-
#include <string>
43
#include <map>
4+
#include <string>
55

6-
class LanguageTranslator
7-
{
6+
class LanguageTranslator {
87
public:
9-
static LanguageTranslator& GetInstance();
8+
static LanguageTranslator &GetInstance();
109

11-
LanguageTranslator();
10+
LanguageTranslator();
1211

13-
std::string Get(const std::string& source);
12+
std::string Get(const std::string &source);
1413

15-
void SetLanguageMap(std::map<std::string, std::string>&& languageDictionary);
14+
void SetLanguageMap(std::map<std::string, std::string> &&languageDictionary);
1615

1716
private:
18-
std::map<std::string, std::string> _languageDictionary;
17+
std::map<std::string, std::string> _languageDictionary;
1918
};
2019

2120
/*
2221
* 语言本地化翻译实例,保持一种惯用法
2322
*/
2423
#define LText(text) LanguageTranslator::GetInstance().Get(text)
25-

CodeFormatCore/include/CodeFormatCore/Config/LuaDiagnosticStyle.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LuaDiagnosticStyle {
1111
public:
1212
LuaDiagnosticStyle() = default;
1313

14-
void ParseTree(InfoTree& tree);
14+
void ParseTree(InfoTree &tree);
1515

1616
bool code_style_check = true;
1717

@@ -31,12 +31,10 @@ class LuaDiagnosticStyle {
3131

3232
std::vector<NameStyleRule> global_variable_name_style = {
3333
NameStyleRule(NameStyleType::SnakeCase),
34-
NameStyleRule(NameStyleType::UpperSnakeCase)
35-
};
34+
NameStyleRule(NameStyleType::UpperSnakeCase)};
3635

3736
std::vector<NameStyleRule> module_name_style = {
38-
NameStyleRule(NameStyleType::SnakeCase)
39-
};
37+
NameStyleRule(NameStyleType::SnakeCase)};
4038

4139
std::vector<NameStyleRule> require_module_name_style = {
4240
NameStyleRule(NameStyleType::SnakeCase),
@@ -45,6 +43,5 @@ class LuaDiagnosticStyle {
4543

4644
std::vector<NameStyleRule> class_name_style = {
4745
NameStyleRule(NameStyleType::SnakeCase),
48-
NameStyleRule(NameStyleType::PascalCase)
49-
};
46+
NameStyleRule(NameStyleType::PascalCase)};
5047
};

CodeFormatCore/include/CodeFormatCore/Config/LuaEditorConfig.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
22

3+
#include "EditorconfigPattern.h"
4+
#include "LuaStyle.h"
35
#include <map>
4-
#include <string>
56
#include <memory>
6-
#include "LuaStyle.h"
7-
#include "EditorconfigPattern.h"
7+
#include <string>
88

99
class LuaEditorConfig {
1010
public:
@@ -27,7 +27,6 @@ class LuaEditorConfig {
2727
LuaStyle &Generate(std::string_view fileUri);
2828

2929
private:
30-
3130
std::string _source;
3231
std::vector<Section> _sections;
3332
std::map<std::string, LuaStyle, std::less<>> _styleMap;

0 commit comments

Comments
 (0)