-
Notifications
You must be signed in to change notification settings - Fork 0
/
coalaCheck.cpp
61 lines (50 loc) · 1.33 KB
/
coalaCheck.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>
#include <regex>
#include "json.hpp"
using json = nlohmann::json;
using namespace std;
json in;
json out;
string origin;
void init_results(string bear_name) {
origin = bear_name;
out["results"] = json::array({});
}
void add_result(string message, int line, int column, int severity) {
json result = {
{"origin", origin},
{"message", message},
{"affected_code", json::array({{
{"file", in["filename"]},
{"start", {
{"column", column},
{"file", in["filename"]},
{"line", line}
}},
{"end", {
{"column", column+6},
{"file", in["filename"]},
{"line", line}
}}
}})},
{"severity", severity}
};
out["results"] += result;
}
int main() {
cin >> in;
init_results("coalaCheckBear");
int i = 0;
for (auto it=in["file"].begin(); it !=in["file"].end(); it++) {
i++;
string line = *it;
size_t found = line.find("Coala");
while (found != string::npos) {
add_result("Did you mean 'coala'?", i, found, 2);
found = line.find("Coala", found+1);
}
}
cout << out;
return 0;
}