Skip to content

Commit b8f9c06

Browse files
committed
refactor: rename error_list -> diag_code_list
* Change terminology from 'error' to 'diag'. * Add the word 'code' to clarify that the module deals with codes only. This disambiguates from buffering_diag_reporter, for example, which stores a list of reported diags.
1 parent 9da447e commit b8f9c06

File tree

10 files changed

+147
-146
lines changed

10 files changed

+147
-146
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ quick_lint_js_add_library(
5656
cli-location.cpp
5757
configuration-loader.cpp
5858
configuration.cpp
59+
diag-code-list.cpp
5960
diagnostic-formatter.cpp
6061
diagnostic.cpp
6162
document.cpp
6263
emacs-lisp-diag-reporter.cpp
6364
emacs-location.cpp
64-
error-list.cpp
6565
file-canonical.cpp
6666
file-handle.cpp
6767
file-path.cpp
@@ -107,14 +107,14 @@ quick_lint_js_add_library(
107107
quick-lint-js/consteval.h
108108
quick-lint-js/cpp.h
109109
quick-lint-js/crash.h
110+
quick-lint-js/diag-code-list.h
110111
quick-lint-js/diag-reporter.h
111112
quick-lint-js/diagnostic-formatter.h
112113
quick-lint-js/diagnostic-types.h
113114
quick-lint-js/diagnostic.h
114115
quick-lint-js/document.h
115116
quick-lint-js/emacs-lisp-diag-reporter.h
116117
quick-lint-js/emacs-location.h
117-
quick-lint-js/error-list.h
118118
quick-lint-js/event-loop.h
119119
quick-lint-js/expression.h
120120
quick-lint-js/feature.h

src/error-list.cpp renamed to src/diag-code-list.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <algorithm>
55
#include <cstddef>
66
#include <cstring>
7+
#include <quick-lint-js/diag-code-list.h>
78
#include <quick-lint-js/diagnostic-types.h>
89
#include <quick-lint-js/diagnostic.h>
9-
#include <quick-lint-js/error-list.h>
1010
#include <string>
1111
#include <string_view>
1212
#include <vector>
@@ -21,12 +21,13 @@ bool contains(const Container& container, const T& item) {
2121
}
2222
}
2323

24-
bool parsed_error_list::error_missing_predicate() const noexcept {
24+
bool parsed_diag_code_list::error_missing_predicate() const noexcept {
2525
return this->included_codes.empty() && this->excluded_codes.empty() &&
2626
this->included_categories.empty() && this->excluded_categories.empty();
2727
}
2828

29-
parsed_error_list parse_error_list(const char* const raw_error_list) {
29+
parsed_diag_code_list parse_diag_code_list(
30+
const char* const raw_diag_code_list) {
3031
static auto is_initial_category_character = [](char c) -> bool {
3132
return 'a' <= c && c <= 'z';
3233
};
@@ -37,51 +38,51 @@ parsed_error_list parse_error_list(const char* const raw_error_list) {
3738
return '0' <= c && c <= '9';
3839
};
3940

40-
parsed_error_list errors;
41+
parsed_diag_code_list errors;
4142
std::size_t i = 0;
4243
bool need_comma = false;
4344

4445
auto try_parse_category_or_code = [&](bool is_include) -> bool {
4546
auto parse_word = [&](auto& is_continue_character) -> std::string_view {
4647
std::size_t begin = i;
4748
i += 1; // Skip initial character. Assume it is valid.
48-
while (is_continue_character(raw_error_list[i])) {
49+
while (is_continue_character(raw_diag_code_list[i])) {
4950
i += 1;
5051
}
5152
std::size_t end = i;
52-
return std::string_view(&raw_error_list[begin], end - begin);
53+
return std::string_view(&raw_diag_code_list[begin], end - begin);
5354
};
5455

55-
if (raw_error_list[i] == 'E') {
56+
if (raw_diag_code_list[i] == 'E') {
5657
(is_include ? errors.included_codes : errors.excluded_codes)
5758
.emplace_back(parse_word(is_continue_code_character));
5859
return true;
59-
} else if (is_initial_category_character(raw_error_list[i])) {
60+
} else if (is_initial_category_character(raw_diag_code_list[i])) {
6061
(is_include ? errors.included_categories : errors.excluded_categories)
6162
.emplace_back(parse_word(is_continue_category_character));
6263
return true;
6364
} else {
64-
errors.unexpected.emplace_back(&raw_error_list[i], 1);
65+
errors.unexpected.emplace_back(&raw_diag_code_list[i], 1);
6566
return false;
6667
}
6768
};
6869

6970
for (;;) {
70-
i = i + std::strspn(&raw_error_list[i], " \t");
71-
if (raw_error_list[i] == '\0') {
71+
i = i + std::strspn(&raw_diag_code_list[i], " \t");
72+
if (raw_diag_code_list[i] == '\0') {
7273
break;
7374
}
74-
if (need_comma && raw_error_list[i] != ',') {
75-
errors.unexpected.emplace_back(&raw_error_list[i], 1);
75+
if (need_comma && raw_diag_code_list[i] != ',') {
76+
errors.unexpected.emplace_back(&raw_diag_code_list[i], 1);
7677
break;
7778
}
78-
i = i + std::strspn(&raw_error_list[i], " \t,");
79+
i = i + std::strspn(&raw_diag_code_list[i], " \t,");
7980
need_comma = true;
8081

81-
if (raw_error_list[i] == '\0') {
82+
if (raw_diag_code_list[i] == '\0') {
8283
break;
83-
} else if (raw_error_list[i] == '+' || raw_error_list[i] == '-') {
84-
bool is_include = raw_error_list[i] == '+';
84+
} else if (raw_diag_code_list[i] == '+' || raw_diag_code_list[i] == '-') {
85+
bool is_include = raw_diag_code_list[i] == '+';
8586
i += 1;
8687
if (!try_parse_category_or_code(/*is_include=*/is_include)) {
8788
break;
@@ -97,7 +98,7 @@ parsed_error_list parse_error_list(const char* const raw_error_list) {
9798
return errors;
9899
}
99100

100-
void compiled_error_list::add(const parsed_error_list& error_list) {
101+
void compiled_diag_code_list::add(const parsed_diag_code_list& diag_code_list) {
101102
auto add_code = [this](std::string_view code, auto& code_set) -> void {
102103
std::optional<diag_type> code_error_type = error_type_from_code_slow(code);
103104
if (code_error_type.has_value()) {
@@ -107,23 +108,23 @@ void compiled_error_list::add(const parsed_error_list& error_list) {
107108
}
108109
};
109110

110-
codes& c = this->parsed_error_lists_.emplace_back();
111-
for (std::string_view code : error_list.included_codes) {
111+
codes& c = this->parsed_diag_code_lists_.emplace_back();
112+
for (std::string_view code : diag_code_list.included_codes) {
112113
add_code(code, c.included_codes);
113114
}
114-
for (std::string_view code : error_list.excluded_codes) {
115+
for (std::string_view code : diag_code_list.excluded_codes) {
115116
add_code(code, c.excluded_codes);
116117
}
117-
c.included_categories = error_list.included_categories;
118-
c.excluded_categories = error_list.excluded_categories;
119-
c.override_defaults = error_list.override_defaults;
118+
c.included_categories = diag_code_list.included_categories;
119+
c.excluded_categories = diag_code_list.excluded_categories;
120+
c.override_defaults = diag_code_list.override_defaults;
120121

121-
if (error_list.error_missing_predicate()) {
122+
if (diag_code_list.error_missing_predicate()) {
122123
this->has_missing_predicate_error_ = true;
123124
}
124125
}
125126

126-
std::vector<std::string> compiled_error_list::parse_errors(
127+
std::vector<std::string> compiled_diag_code_list::parse_errors(
127128
std::string_view cli_option_name) const {
128129
std::vector<std::string> errors;
129130
if (this->has_missing_predicate_error_) {
@@ -133,7 +134,7 @@ std::vector<std::string> compiled_error_list::parse_errors(
133134
return errors;
134135
}
135136

136-
std::vector<std::string> compiled_error_list::parse_warnings() const {
137+
std::vector<std::string> compiled_diag_code_list::parse_warnings() const {
137138
std::vector<std::string> warnings;
138139
auto check_category = [&warnings](std::string_view category) {
139140
if (category != "all") {
@@ -142,7 +143,7 @@ std::vector<std::string> compiled_error_list::parse_warnings() const {
142143
}
143144
};
144145

145-
for (const codes& c : this->parsed_error_lists_) {
146+
for (const codes& c : this->parsed_diag_code_lists_) {
146147
for (std::string_view category : c.included_categories) {
147148
check_category(category);
148149
}
@@ -159,10 +160,10 @@ std::vector<std::string> compiled_error_list::parse_warnings() const {
159160
return warnings;
160161
}
161162

162-
bool compiled_error_list::is_present(diag_type type) const noexcept {
163+
bool compiled_diag_code_list::is_present(diag_type type) const noexcept {
163164
bool is_default = true; // For now, all codes are enabled by default.
164165
bool present = true;
165-
for (const codes& c : this->parsed_error_lists_) {
166+
for (const codes& c : this->parsed_diag_code_lists_) {
166167
std::size_t error_type_index = static_cast<std::size_t>(type);
167168
if (c.override_defaults || c.excluded_codes[error_type_index] ||
168169
(is_default && contains(c.excluded_categories, "all"))) {
@@ -176,8 +177,8 @@ bool compiled_error_list::is_present(diag_type type) const noexcept {
176177
return present;
177178
}
178179

179-
bool compiled_error_list::is_user_provided() const noexcept {
180-
return !parsed_error_lists_.empty();
180+
bool compiled_diag_code_list::is_user_provided() const noexcept {
181+
return !parsed_diag_code_lists_.empty();
181182
}
182183
}
183184

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <quick-lint-js/char8.h>
1212
#include <quick-lint-js/configuration-loader.h>
1313
#include <quick-lint-js/configuration.h>
14+
#include <quick-lint-js/diag-code-list.h>
1415
#include <quick-lint-js/emacs-lisp-diag-reporter.h>
1516
#include <quick-lint-js/emacs-location.h>
16-
#include <quick-lint-js/error-list.h>
1717
#include <quick-lint-js/event-loop.h>
1818
#include <quick-lint-js/file.h>
1919
#include <quick-lint-js/language.h>
@@ -74,7 +74,7 @@ bool get_escape_errors(option_when escape_errors) {
7474
class any_diag_reporter {
7575
public:
7676
static any_diag_reporter make(output_format format, option_when escape_errors,
77-
compiled_error_list *exit_fail_on) {
77+
compiled_diag_code_list *exit_fail_on) {
7878
switch (format) {
7979
case output_format::default_format:
8080
case output_format::gnu_like:

src/options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ options parse_options(int argc, char** argv) {
100100
next_vim_file_bufnr = bufnr;
101101
} else if (const char* arg_value =
102102
parser.match_option_with_value("--exit-fail-on"sv)) {
103-
o.exit_fail_on.add(parse_error_list(arg_value));
103+
o.exit_fail_on.add(parse_diag_code_list(arg_value));
104104
} else if (parser.match_flag_option("--help"sv, "--h"sv) ||
105105
parser.match_flag_shorthand('h')) {
106106
o.help = true;

src/quick-lint-js/error-list.h renamed to src/quick-lint-js/diag-code-list.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (C) 2020 Matthew "strager" Glazar
22
// See end of file for extended copyright information.
33

4-
#ifndef QUICK_LINT_JS_ERROR_LIST_H
5-
#define QUICK_LINT_JS_ERROR_LIST_H
4+
#ifndef QUICK_LINT_JS_DIAG_CODE_LIST_H
5+
#define QUICK_LINT_JS_DIAG_CODE_LIST_H
66

77
#include <array>
88
#include <bitset>
@@ -12,7 +12,7 @@
1212
#include <vector>
1313

1414
namespace quick_lint_js {
15-
struct parsed_error_list {
15+
struct parsed_diag_code_list {
1616
bool error_missing_predicate() const noexcept;
1717

1818
std::vector<std::string_view> included_codes;
@@ -23,11 +23,11 @@ struct parsed_error_list {
2323
bool override_defaults = false;
2424
};
2525

26-
parsed_error_list parse_error_list(const char* raw_error_list);
26+
parsed_diag_code_list parse_diag_code_list(const char* raw_diag_code_list);
2727

28-
class compiled_error_list {
28+
class compiled_diag_code_list {
2929
public:
30-
void add(const parsed_error_list&);
30+
void add(const parsed_diag_code_list&);
3131

3232
std::vector<std::string> parse_errors(std::string_view cli_option_name) const;
3333
std::vector<std::string> parse_warnings() const;
@@ -45,7 +45,7 @@ class compiled_error_list {
4545
bool override_defaults;
4646
};
4747

48-
std::vector<codes> parsed_error_lists_;
48+
std::vector<codes> parsed_diag_code_lists_;
4949

5050
// Collected errors and warnings:
5151
std::vector<std::string_view> unknown_codes_;

src/quick-lint-js/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define QUICK_LINT_JS_OPTIONS_H
66

77
#include <optional>
8-
#include <quick-lint-js/error-list.h>
8+
#include <quick-lint-js/diag-code-list.h>
99
#include <vector>
1010

1111
namespace quick_lint_js {
@@ -38,7 +38,7 @@ struct options {
3838
quick_lint_js::option_when diagnostic_hyperlinks =
3939
quick_lint_js::option_when::auto_;
4040
std::vector<file_to_lint> files_to_lint;
41-
compiled_error_list exit_fail_on;
41+
compiled_diag_code_list exit_fail_on;
4242

4343
std::vector<const char *> error_unrecognized_options;
4444
bool has_multiple_stdin = false;

src/quick-lint-js/reported-diag-statistics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#ifndef QUICK_LINT_JS_REPORTED_DIAG_STATISTICS_H
55
#define QUICK_LINT_JS_REPORTED_DIAG_STATISTICS_H
66

7+
#include <quick-lint-js/diag-code-list.h>
78
#include <quick-lint-js/diag-reporter.h>
89
#include <quick-lint-js/diagnostic-types.h>
9-
#include <quick-lint-js/error-list.h>
1010
#include <quick-lint-js/text-diag-reporter.h>
1111
#include <quick-lint-js/token.h>
1212
#include <quick-lint-js/vim-qflist-json-diag-reporter.h>
@@ -16,7 +16,7 @@ template <typename T>
1616
class reported_diag_statistics final : public diag_reporter {
1717
public:
1818
explicit reported_diag_statistics(T reporter,
19-
const compiled_error_list *predicate)
19+
const compiled_diag_code_list *predicate)
2020
: reporter_(reporter), predicate_(predicate) {}
2121

2222
T *get_reporter() { return &(this->reporter_); }
@@ -35,7 +35,7 @@ class reported_diag_statistics final : public diag_reporter {
3535
private:
3636
T reporter_;
3737

38-
const compiled_error_list *predicate_;
38+
const compiled_diag_code_list *predicate_;
3939
bool found_matching_error_ = false;
4040
};
4141
}

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ quick_lint_js_add_executable(
3838
test-configuration-loader.cpp
3939
test-configuration.cpp
4040
test-crash.cpp
41+
test-diag-code-list.cpp
4142
test-diagnostic-formatter.cpp
4243
test-diagnostic.cpp
4344
test-document.cpp
4445
test-emacs-lisp-diag-reporter.cpp
4546
test-emacs-location.cpp
46-
test-error-list.cpp
4747
test-error-matcher.cpp
4848
test-error.cpp
4949
test-event-loop.cpp

0 commit comments

Comments
 (0)