From 9c5c33f6a88cff5c3bf623cbde9e0730b67a3ffe Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Thu, 19 Oct 2023 16:21:17 -0400 Subject: [PATCH] refactor(cli): move get_language out of File_To_Lint get_language is a bit weird. There are two functions: a top-level function and a member function of File_To_Lint. Make both versions top-level functions. This makes it more obvious that the functions do the same thing, and will make it more natural to add some features to get_language later. --- src/quick-lint-js/cli/main.cpp | 2 +- src/quick-lint-js/cli/options.cpp | 4 ++-- src/quick-lint-js/cli/options.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/quick-lint-js/cli/main.cpp b/src/quick-lint-js/cli/main.cpp index 40433fde63..f4febfdc8d 100644 --- a/src/quick-lint-js/cli/main.cpp +++ b/src/quick-lint-js/cli/main.cpp @@ -301,7 +301,7 @@ void run(Options o) { source.error().print_and_exit(); } Linter_Options lint_options = - get_linter_options_from_language(file.get_language()); + get_linter_options_from_language(get_language(file)); lint_options.print_parser_visits = o.print_parser_visits; reporter->set_source(&*source, file); parse_and_lint(&*source, *reporter->get(), config->globals(), diff --git a/src/quick-lint-js/cli/options.cpp b/src/quick-lint-js/cli/options.cpp index 4aed5a6c8d..adecddb3bc 100644 --- a/src/quick-lint-js/cli/options.cpp +++ b/src/quick-lint-js/cli/options.cpp @@ -261,8 +261,8 @@ bool Options::dump_errors(Output_Stream& out) const { return have_errors; } -Resolved_Input_File_Language File_To_Lint::get_language() const { - return quick_lint_js::get_language(this->path, this->language); +Resolved_Input_File_Language get_language(const File_To_Lint& file) { + return get_language(file.path, file.language); } Resolved_Input_File_Language get_language(const char* file, diff --git a/src/quick-lint-js/cli/options.h b/src/quick-lint-js/cli/options.h index 968f42901b..cdb8fd4803 100644 --- a/src/quick-lint-js/cli/options.h +++ b/src/quick-lint-js/cli/options.h @@ -53,10 +53,9 @@ struct File_To_Lint { bool is_stdin = false; std::optional vim_bufnr; - - Resolved_Input_File_Language get_language() const; }; +Resolved_Input_File_Language get_language(const File_To_Lint &file); Resolved_Input_File_Language get_language(const char *file, Raw_Input_File_Language language);