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
0 commit comments