11#include " CodeService/Diagnostic/NameStyle/NameStyleChecker.h"
2- #include < algorithm>
3- #include " CodeService/Diagnostic/DiagnosticBuilder.h"
4- #include " Util/format.h"
52#include " CodeService/Config/LanguageTranslator.h"
3+ #include " CodeService/Diagnostic/DiagnosticBuilder.h"
64#include " CodeService/Diagnostic/NameStyle/NameStyleRuleMatcher.h"
75#include " LuaParser/Lexer/LuaTokenTypeDetail.h"
6+ #include " Util/format.h"
7+ #include < algorithm>
88
99std::set<std::string, std::less<>> NameStyleChecker::TableFieldSpecialName = {
1010 " __add" , " __sub" , " __mul" , " __div" , " __mod" , " __pow" ,
1111 " __unm" , " __idiv" , " __band" , " __bor" , " __bxor" , " __bnot" , " __shl" ,
1212 " __shr" , " __concat" , " __len" , " __eq" , " __lt" , " __index" , " __newindex" ,
13- " __call" , " __gc" , " __close" , " __mode" , " __name"
14- };
13+ " __call" , " __gc" , " __close" , " __mode" , " __name" };
1514
1615std::set<std::string, std::less<>> NameStyleChecker::GlobalSpecialName = {
17- " _G" , " _ENV"
18- };
16+ " _G" , " _ENV" };
1917
2018NameStyleChecker::NameStyleChecker () {
2119}
@@ -333,8 +331,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
333331 d.PushDiagnostic (DiagnosticType::NameStyle,
334332 n.GetTextRange (t),
335333 MakeDiagnosticInfo (" LocalVariableName" , n, t,
336- state.GetDiagnosticStyle ().local_name_style )
337- );
334+ state.GetDiagnosticStyle ().local_name_style ));
338335 }
339336 break ;
340337 }
@@ -343,8 +340,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
343340 d.PushDiagnostic (DiagnosticType::NameStyle,
344341 n.GetTextRange (t),
345342 MakeDiagnosticInfo (" ModuleName" , n, t,
346- state.GetDiagnosticStyle ().module_name_style )
347- );
343+ state.GetDiagnosticStyle ().module_name_style ));
348344 }
349345 break ;
350346 }
@@ -356,8 +352,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
356352 d.PushDiagnostic (DiagnosticType::NameStyle,
357353 n.GetTextRange (t),
358354 MakeDiagnosticInfo (" LocalFunctionName" , n, t,
359- state.GetDiagnosticStyle ().local_function_name_style )
360- );
355+ state.GetDiagnosticStyle ().local_function_name_style ));
361356 }
362357 break ;
363358 }
@@ -369,8 +364,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
369364 d.PushDiagnostic (DiagnosticType::NameStyle,
370365 n.GetTextRange (t),
371366 MakeDiagnosticInfo (" GlobalVariableDefineName" , n, t,
372- state.GetDiagnosticStyle ().global_variable_name_style )
373- );
367+ state.GetDiagnosticStyle ().global_variable_name_style ));
374368 }
375369 break ;
376370 }
@@ -379,8 +373,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
379373 d.PushDiagnostic (DiagnosticType::NameStyle,
380374 n.GetTextRange (t),
381375 MakeDiagnosticInfo (" ParamName" , n, t,
382- state.GetDiagnosticStyle ().function_param_name_style )
383- );
376+ state.GetDiagnosticStyle ().function_param_name_style ));
384377 }
385378 break ;
386379 }
@@ -389,8 +382,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
389382 d.PushDiagnostic (DiagnosticType::NameStyle,
390383 n.GetTextRange (t),
391384 MakeDiagnosticInfo (" ImportModuleName" , n, t,
392- state.GetDiagnosticStyle ().require_module_name_style )
393- );
385+ state.GetDiagnosticStyle ().require_module_name_style ));
394386 }
395387 break ;
396388 }
@@ -399,8 +391,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
399391 d.PushDiagnostic (DiagnosticType::NameStyle,
400392 n.GetTextRange (t),
401393 MakeDiagnosticInfo (" ClassVariableName" , n, t,
402- state.GetDiagnosticStyle ().class_name_style )
403- );
394+ state.GetDiagnosticStyle ().class_name_style ));
404395 }
405396 break ;
406397 }
@@ -413,8 +404,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
413404 d.PushDiagnostic (DiagnosticType::NameStyle,
414405 n.GetTextRange (t),
415406 MakeDiagnosticInfo (" FunctionDefineName" , n, t,
416- state.GetDiagnosticStyle ().function_name_style )
417- );
407+ state.GetDiagnosticStyle ().function_name_style ));
418408 }
419409 break ;
420410 }
@@ -427,8 +417,7 @@ void NameStyleChecker::Diagnostic(DiagnosticBuilder &d, const LuaSyntaxTree &t)
427417 d.PushDiagnostic (DiagnosticType::NameStyle,
428418 n.GetTextRange (t),
429419 MakeDiagnosticInfo (" TableFieldDefineName" , n, t,
430- state.GetDiagnosticStyle ().table_field_name_style )
431- );
420+ state.GetDiagnosticStyle ().table_field_name_style ));
432421 }
433422 break ;
434423 }
@@ -456,11 +445,11 @@ std::string NameStyleChecker::MakeDiagnosticInfo(std::string_view ruleName, LuaS
456445 break ;
457446 }
458447 case NameStyleType::Same: {
459- ruleMessage.append (util::format (" same('{}') " , rule. Param ));
448+ ruleMessage.append (util::format (" same" ));
460449 break ;
461450 }
462451 case NameStyleType::Pattern: {
463- ruleMessage.append (util::format (" pattern('{}') " , rule. Param ));
452+ ruleMessage.append (util::format (" pattern" ));
464453 break ;
465454 }
466455 case NameStyleType::UpperSnakeCase: {
0 commit comments