Skip to content

Commit fe5742f

Browse files
committed
refactor(fe): make parse_and_lint accept a Configuration
Simplify parse_and_lint callers by moving the Configuration::globals() call into parse_and_lint. This refactor will allow parse_and_lint to use more data from the Configuration object in the future.
1 parent 22f60d6 commit fe5742f

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

plugin/vscode/quick-lint-js/vscode/qljs-document.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ class QLJS_Lintable_Document : public QLJS_Document_Base {
160160
VSCode_Diag_Reporter diag_reporter(vscode, env, &this->document_.locator(),
161161
this->uri());
162162
parse_and_lint(this->document_.string(), diag_reporter,
163-
this->config_->globals(),
164-
Linter_Options{.language = this->language_});
163+
Linter_Options{
164+
.language = this->language_,
165+
.configuration = this->config_,
166+
});
165167

166168
return std::move(diag_reporter).diagnostics();
167169
}

src/quick-lint-js/c-api.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ const QLJS_Web_Demo_Diagnostic* qljs_web_demo_lint(QLJS_Web_Demo_Document* p) {
9898
Configuration().load_from_json(&p->text_, &diags);
9999
p->diag_reporter_.report(diags);
100100
} else {
101-
parse_and_lint(&p->text_, p->diag_reporter_, p->config_.globals(),
102-
Linter_Options{.language = p->language_});
101+
parse_and_lint(
102+
&p->text_, p->diag_reporter_,
103+
Linter_Options{.language = p->language_, .configuration = &p->config_});
103104
}
104105
return p->diag_reporter_.get_diagnostics();
105106
}

src/quick-lint-js/cli/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ void run(Options o) {
301301
}
302302
Linter_Options lint_options = {
303303
.language = get_language(file, o),
304+
.configuration = config,
304305
.print_parser_visits = o.print_parser_visits,
305306
};
306307
reporter->set_source(&*source, file);
307-
parse_and_lint(&*source, *reporter->get(), config->globals(),
308-
lint_options);
308+
parse_and_lint(&*source, *reporter->get(), lint_options);
309309
}
310310
}
311311
reporter->finish();

src/quick-lint-js/fe/linter.cpp

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

4+
#include <quick-lint-js/configuration/configuration.h>
45
#include <quick-lint-js/container/padded-string.h>
56
#include <quick-lint-js/debug/debug-probe.h>
67
#include <quick-lint-js/fe/debug-parse-visitor.h>
@@ -15,7 +16,6 @@
1516

1617
namespace quick_lint_js {
1718
void parse_and_lint(Padded_String_View code, Diag_Reporter& reporter,
18-
const Global_Declared_Variable_Set& globals,
1919
Linter_Options options) {
2020
Parser_Options parser_options;
2121
switch (options.language) {
@@ -44,7 +44,7 @@ void parse_and_lint(Padded_String_View code, Diag_Reporter& reporter,
4444

4545
Parser p(code, &reporter, parser_options);
4646
Variable_Analyzer var_analyzer(
47-
&reporter, &globals,
47+
&reporter, &options.configuration->globals(),
4848
Variable_Analyzer_Options{
4949
.allow_deleting_typescript_variable = !parser_options.typescript,
5050
.eval_can_declare_variables = !parser_options.typescript,

src/quick-lint-js/fe/linter.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
#include <quick-lint-js/fe/language.h>
77

88
namespace quick_lint_js {
9+
class Configuration;
910
class Diag_Reporter;
10-
class Global_Declared_Variable_Set;
1111
class Padded_String_View;
1212

1313
// TODO(#465): Accept parser options from quick-lint-js.config or CLI options.
1414
struct Linter_Options {
1515
File_Language language;
1616

17+
Configuration* configuration;
18+
1719
// If true, print a human-readable representation of parser visits to stderr.
1820
bool print_parser_visits = false;
1921
};
2022

21-
void parse_and_lint(Padded_String_View code, Diag_Reporter&,
22-
const Global_Declared_Variable_Set&, Linter_Options);
23+
void parse_and_lint(Padded_String_View code, Diag_Reporter&, Linter_Options);
2324
}
2425

2526
// quick-lint-js finds bugs in JavaScript programs.

src/quick-lint-js/lsp/lsp-server.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,11 @@ void LSP_JavaScript_Linter::lint_and_get_diagnostics(
785785
Configuration& config, File_Language language, Padded_String_View code,
786786
Byte_Buffer& diagnostics_json) {
787787
LSP_Diag_Reporter diag_reporter(qljs_messages, diagnostics_json, code);
788-
parse_and_lint(code, diag_reporter, config.globals(),
789-
Linter_Options{.language = language});
788+
parse_and_lint(code, diag_reporter,
789+
Linter_Options{
790+
.language = language,
791+
.configuration = &config,
792+
});
790793
diag_reporter.finish();
791794
}
792795

tools/test-typescript/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <filesystem>
66
#include <quick-lint-js/cli/arg-parser.h>
77
#include <quick-lint-js/cli/text-diag-reporter.h>
8+
#include <quick-lint-js/configuration/configuration.h>
89
#include <quick-lint-js/container/concat.h>
910
#include <quick-lint-js/container/hash-set.h>
1011
#include <quick-lint-js/container/padded-string.h>
@@ -251,8 +252,9 @@ void process_test_case_file(Expected_Test_Results& expected_results,
251252
std::exit(1);
252253
}
253254

254-
Global_Declared_Variable_Set globals;
255-
globals.add_literally_everything();
255+
Configuration config;
256+
bool ok = config.add_global_group(u8"literally-anything"_sv);
257+
QLJS_ALWAYS_ASSERT(ok);
256258

257259
Memory_Output_Stream diags;
258260
Text_Diag_Reporter text_reporter(Translator(), &diags,
@@ -264,8 +266,11 @@ void process_test_case_file(Expected_Test_Results& expected_results,
264266
if (language.has_value()) {
265267
// TODO(strager): Indicate which unit we are looking at.
266268
text_reporter.set_source(&unit.data, path);
267-
parse_and_lint(&unit.data, text_reporter, globals,
268-
Linter_Options{.language = *language});
269+
parse_and_lint(&unit.data, text_reporter,
270+
Linter_Options{
271+
.language = *language,
272+
.configuration = &config,
273+
});
269274
}
270275
}
271276
diags.flush();

0 commit comments

Comments
 (0)