Skip to content

Commit 22e1bc9

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents b9401ce + abdea2d commit 22e1bc9

File tree

17 files changed

+426
-31
lines changed

17 files changed

+426
-31
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
include:
17-
- { os: ubuntu-20.04, target: linux, platform: linux-x64 }
17+
- { os: ubuntu-22.04, target: linux, platform: linux-x64 }
1818
- { os: ubuntu-22.04, target: linux, platform: linux-aarch64 }
1919
- { os: macos-latest, target: darwin, platform: darwin-x64 }
2020
- { os: macos-latest, target: darwin, platform: darwin-arm64 }

CodeFormatCore/include/CodeFormatCore/Config/LuaDiagnosticStyle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ class LuaDiagnosticStyle {
4848
std::vector<NameStyleRule> const_variable_name_style = {
4949
NameStyleRule(NameStyleType::SnakeCase),
5050
NameStyleRule(NameStyleType::UpperSnakeCase)};
51+
52+
std::vector<NameStyleRule> module_local_name_style = {NameStyleRule(NameStyleType::SnakeCase)};
5153
};

CodeFormatCore/include/CodeFormatCore/Config/LuaStyleEnum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ enum class CallArgParentheses : int {
1818
Remove,
1919
RemoveStringOnly,
2020
RemoveTableOnly,
21-
// 应该没人用
22-
//UnambiguousRemoveStringOnly
21+
Always
22+
2323
};
2424

2525
enum class ContinuousAlign {

CodeFormatCore/include/CodeFormatCore/Diagnostic/NameStyle/NameDefineType.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ enum class NameDefineType {
1010
ImportModuleName,
1111
ModuleDefineName,
1212
TableFieldDefineName,
13-
ConstVariableName
13+
ConstVariableName,
14+
ModuleLocalVariableName
1415
};
1516

1617
struct NameStyleInfo {

CodeFormatCore/include/CodeFormatCore/Format/Analyzer/FormatStrategy.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ enum class TokenStrategy {
2727
OriginRange,
2828
StmtEndSemicolon,
2929
NewLineBeforeToken,
30+
31+
WithParentheses,
32+
WithLeftParentheses,
33+
WithRightParentheses,
3034
SpaceAfterCommentDash
3135
};
3236

3337
enum class TokenAddStrategy {
3438
None,
3539
TableAddColon,
3640
TableAddComma,
37-
StmtEndSemicolon
41+
StmtEndSemicolon,
3842
};
3943

4044
enum class IndentStrategy {

CodeFormatCore/include/CodeFormatCore/Format/Analyzer/SpaceAnalyzer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SpaceAnalyzer : public FormatAnalyzer {
1010

1111
enum class SpacePriority : std::size_t {
1212
Normal = 0,
13-
CommentFirst,
13+
First,
1414
};
1515

1616
SpaceAnalyzer();

CodeFormatCore/src/Config/LuaDiagnosticStyle.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ void LuaDiagnosticStyle::ParseTree(InfoTree &tree) {
104104
{global_variable_name_style, "global_variable_name_style"},
105105
{module_name_style, "module_name_style" },
106106
{require_module_name_style, "require_module_name_style" },
107-
{class_name_style, "class_name_style" }
107+
{class_name_style, "class_name_style" },
108+
{const_variable_name_style, "const_variable_name_style" },
109+
{module_local_name_style, "module_local_name_style" }
108110
};
109111
for (auto &pair: name_styles) {
110112
if (auto n = root.GetValue(pair.second); !n.IsNull()) {
@@ -118,4 +120,18 @@ void LuaDiagnosticStyle::ParseTree(InfoTree &tree) {
118120
}
119121
}
120122
}
123+
// module_local_name_style should fallback on local_name_style if not defined
124+
if (root.GetValue("module_local_name_style").IsNull() && !root.GetValue("local_name_style").IsNull()) {
125+
auto moduleLocalNameStyle = std::find_if(name_styles.begin(), name_styles.end(), [&](const std::pair<std::vector<NameStyleRule> &, std::string> &pair) {
126+
return pair.second == "module_local_name_style";
127+
});
128+
auto localNameStyle = std::find_if(name_styles.begin(), name_styles.end(), [&](const std::pair<std::vector<NameStyleRule> &, std::string> &pair) {
129+
return pair.second == "local_name_style";
130+
});
131+
132+
// overwrite the namestyle of module_local_name_style with the namestyle of local_name_style
133+
if (moduleLocalNameStyle != name_styles.end() && localNameStyle != name_styles.end()) {
134+
moduleLocalNameStyle->first = localNameStyle->first;
135+
}
136+
}
121137
}

CodeFormatCore/src/Config/LuaStyle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ void LuaStyle::Parse(std::map<std::string, std::string, std::less<>> &configMap)
131131
call_arg_parentheses = CallArgParentheses::RemoveStringOnly;
132132
} else if (value == "remove_table_only") {
133133
call_arg_parentheses = CallArgParentheses::RemoveTableOnly;
134+
} else if (value == "always") {
135+
call_arg_parentheses = CallArgParentheses::Always;
134136
}
135137
}
136138

CodeFormatCore/src/Diagnostic/NameStyle/NameStyleChecker.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ void NameStyleChecker::CheckInBody(LuaSyntaxNode &n, const LuaSyntaxTree &t) {
152152
}
153153

154154
if (!matchConstRule) {
155+
// check for non-special, non-const variables that are in the outermost scope
156+
if (_scopeStack.size() == 1) {
157+
PushStyleCheck(NameDefineType::ModuleLocalVariableName, name);
158+
break;
159+
}
160+
155161
PushStyleCheck(NameDefineType::LocalVariableName, name);
156162
}
157163
}
@@ -459,6 +465,15 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
459465
}
460466
break;
461467
}
468+
case NameDefineType::ModuleLocalVariableName: {
469+
if (!matcher.Match(n, t, state.GetDiagnosticStyle().module_local_name_style)) {
470+
d.PushDiagnostic(DiagnosticType::NameStyle,
471+
n.GetTextRange(t),
472+
MakeDiagnosticInfo("ModuleLocalVariableName", n, t,
473+
state.GetDiagnosticStyle().module_local_name_style));
474+
}
475+
break;
476+
}
462477
}
463478
}
464479
}

CodeFormatCore/src/Format/Analyzer/LineBreakAnalyzer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ void LineBreakAnalyzer::ComplexAnalyze(FormatState &f, const LuaSyntaxTree &t) {
107107

108108
} else {
109109
switch (stmt.GetTokenKind(t)) {
110-
case TK_SHORT_COMMENT:
111110
case TK_LONG_COMMENT:
111+
{
112+
auto nextToken = stmt.GetNextToken(t).GetTokenKind(t);
113+
if (nextToken == TK_SHORT_COMMENT) {
114+
break;
115+
}
116+
// Fall through
117+
}
118+
case TK_SHORT_COMMENT:
112119
case TK_SHEBANG: {
113120
BreakAfter(stmt, t, style.line_space_after_comment);
114121
break;

0 commit comments

Comments
 (0)