MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / CheckSingleFile

Method CheckSingleFile

CodeFormat/src/LuaCheck.cpp:54–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54bool LuaCheck::CheckSingleFile(const FormatContext &context, std::string_view path, std::string &&sourceText, LuaStyle style) {
55 auto file = std::make_shared<LuaSource>(std::move(sourceText));
56 LuaLexer luaLexer(file);
57 if (context.IsNonStandardLua()) {
58 luaLexer.SupportNonStandardSymbol();
59 }
60 if (context.IsCLikeCommentsSupport()) {
61 luaLexer.SupportCLikeComments();
62 }
63
64 luaLexer.Parse();
65
66 LuaParser p(file, std::move(luaLexer.GetTokens()));
67 p.Parse();
68
69 if (p.HasError()) {
70 auto &errors = p.GetErrors();
71 std::cout << util::format("Check {} ...\t{} error", path, errors.size()) << std::endl;
72 for (auto &error: errors) {
73 DiagnosticInspection(error.ErrorMessage, error.ErrorRange, *file, path);
74 }
75
76 return false;
77 }
78
79 LuaSyntaxTree t;
80 t.BuildTree(p);
81 auto diagnosticStyle = context.GetDiagnosticStyle();
82 DiagnosticBuilder diagnosticBuilder(style, diagnosticStyle);
83 diagnosticBuilder.CodeStyleCheck(t);
84 diagnosticBuilder.NameStyleCheck(t);
85
86 auto diagnostics = diagnosticBuilder.GetDiagnosticResults(t);
87 if (diagnostics.empty()) {
88 return true;
89 }
90
91 if (context.IsDumpJson()) {
92 std::cerr << util::format("Check {}\t{} warning", path, diagnostics.size()) << std::endl;
93
94 auto arr = nlohmann::json::array();
95 for (auto &d: diagnostics) {
96 auto obj = DiagnosticToJson(d.Message, d.Range, *file);
97 arr.push_back(obj);
98 }
99 std::cout << arr.dump() << std::endl;
100
101 return false;
102 } else {
103 std::cerr << util::format("Check {}\t{} warning", path, diagnostics.size()) << std::endl;
104
105 for (auto &d: diagnostics) {
106 DiagnosticInspection(d.Message, d.Range, *file, path);
107 }
108
109 return false;
110 }
111}

Callers

nothing calls this directly

Calls 15

DiagnosticInspectionFunction · 0.85
DiagnosticToJsonFunction · 0.85
IsNonStandardLuaMethod · 0.80
GetTokensMethod · 0.80
BuildTreeMethod · 0.80
CodeStyleCheckMethod · 0.80
GetDiagnosticResultsMethod · 0.80
IsDumpJsonMethod · 0.80
formatFunction · 0.50
arrayClass · 0.50

Tested by

no test coverage detected