Skip to content

Commit 8fb4422

Browse files
committed
Move canonicalize_path fully into its own module
canonicalize_path has its own test .cpp and implementation .cpp, but its header bits are shared in file.h. Formally make a separate file-canonical module. This commit should not change behavior.
1 parent 49f11fb commit 8fb4422

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ quick_lint_js_add_library(
8484
quick-lint-js/error.h
8585
quick-lint-js/expression.h
8686
quick-lint-js/feature.h
87+
quick-lint-js/file-canonical.h
8788
quick-lint-js/file-handle.h
8889
quick-lint-js/file-path.h
8990
quick-lint-js/file.h

src/configuration-loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <quick-lint-js/assert.h>
55
#include <quick-lint-js/configuration-loader.h>
66
#include <quick-lint-js/configuration.h>
7+
#include <quick-lint-js/file-canonical.h>
78
#include <quick-lint-js/file-path.h>
89
#include <quick-lint-js/file.h>
910
#include <quick-lint-js/options.h>

src/file-canonical.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <cstring>
1111
#include <quick-lint-js/assert.h>
1212
#include <quick-lint-js/char8.h>
13+
#include <quick-lint-js/file-canonical.h>
14+
#include <quick-lint-js/file-handle.h>
1315
#include <quick-lint-js/file-path.h>
14-
#include <quick-lint-js/file.h>
1516
#include <quick-lint-js/have.h>
17+
#include <quick-lint-js/narrow-cast.h>
1618
#include <quick-lint-js/string-view.h>
1719
#include <quick-lint-js/utf-16.h>
1820
#include <string>

src/quick-lint-js/file-canonical.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2020 Matthew "strager" Glazar
2+
// See end of file for extended copyright information.
3+
4+
#ifndef QUICK_LINT_JS_FILE_CANONICAL_H
5+
#define QUICK_LINT_JS_FILE_CANONICAL_H
6+
7+
#include <string>
8+
9+
namespace quick_lint_js {
10+
class canonical_path_result {
11+
public:
12+
explicit canonical_path_result(std::string &&path);
13+
explicit canonical_path_result(const char *path);
14+
15+
std::string_view path() const &noexcept;
16+
std::string &&path() && noexcept;
17+
const char *c_str() const noexcept;
18+
19+
std::string &&error() && noexcept;
20+
21+
bool ok() const noexcept { return this->error_.empty(); }
22+
23+
static canonical_path_result failure(std::string &&error);
24+
25+
private:
26+
explicit canonical_path_result();
27+
28+
std::string path_;
29+
std::string error_;
30+
};
31+
32+
canonical_path_result canonicalize_path(const char *path);
33+
canonical_path_result canonicalize_path(const std::string &path);
34+
}
35+
36+
#endif
37+
38+
// quick-lint-js finds bugs in JavaScript programs.
39+
// Copyright (C) 2020 Matthew "strager" Glazar
40+
//
41+
// This file is part of quick-lint-js.
42+
//
43+
// quick-lint-js is free software: you can redistribute it and/or modify
44+
// it under the terms of the GNU General Public License as published by
45+
// the Free Software Foundation, either version 3 of the License, or
46+
// (at your option) any later version.
47+
//
48+
// quick-lint-js is distributed in the hope that it will be useful,
49+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
50+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+
// GNU General Public License for more details.
52+
//
53+
// You should have received a copy of the GNU General Public License
54+
// along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

src/quick-lint-js/file.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,6 @@ read_file_result read_stdin(void);
2929

3030
void write_file(const std::string &path, string8_view content);
3131
void write_file(const char *path, string8_view content);
32-
33-
class canonical_path_result {
34-
public:
35-
explicit canonical_path_result(std::string &&path);
36-
explicit canonical_path_result(const char *path);
37-
38-
std::string_view path() const &noexcept;
39-
std::string &&path() && noexcept;
40-
const char *c_str() const noexcept;
41-
42-
std::string &&error() && noexcept;
43-
44-
bool ok() const noexcept { return this->error_.empty(); }
45-
46-
static canonical_path_result failure(std::string &&error);
47-
48-
private:
49-
explicit canonical_path_result();
50-
51-
std::string path_;
52-
std::string error_;
53-
};
54-
55-
canonical_path_result canonicalize_path(const char *path);
56-
canonical_path_result canonicalize_path(const std::string &path);
5732
}
5833

5934
#endif

test/test-configuration-loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <gtest/gtest.h>
99
#include <quick-lint-js/configuration-loader.h>
1010
#include <quick-lint-js/configuration.h>
11+
#include <quick-lint-js/file-canonical.h>
1112
#include <quick-lint-js/file-matcher.h>
1213
#include <quick-lint-js/file.h>
1314
#include <quick-lint-js/options.h>

test/test-file-canonical.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <gtest/gtest.h>
1414
#include <optional>
1515
#include <quick-lint-js/char8.h>
16+
#include <quick-lint-js/file-canonical.h>
1617
#include <quick-lint-js/file-matcher.h>
17-
#include <quick-lint-js/file.h>
1818
#include <quick-lint-js/have.h>
1919
#include <quick-lint-js/string-view.h>
2020
#include <quick-lint-js/temporary-directory.h>

0 commit comments

Comments
 (0)