Skip to content

Commit

Permalink
Merge branch 'quick-lint:master' into rename_import_alias_namespace_a…
Browse files Browse the repository at this point in the history
…lias_add_new_diag_namespace_alias
  • Loading branch information
UnfairBots authored Feb 27, 2024
2 parents 9e773ad + 6ecf408 commit 963b20d
Show file tree
Hide file tree
Showing 31 changed files with 1,570 additions and 188 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/build-and-test-plugin-vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,40 @@ jobs:
cmake --build build-tools --config Debug --target quick-lint-js-build-tools
- name: C++ configure
shell: "python3 {0}"
run: |
env | grep '^CMAKE\|^QUICK_LINT_JS' | sort
cmake ${CMAKE_C_COMPILER:+-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}"} ${CMAKE_CXX_COMPILER:+-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}"} -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=NO -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" -DQUICK_LINT_JS_ENABLE_VSCODE=YES -DCMAKE_POSITION_INDEPENDENT_CODE=YES -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=YES ${{ fromJSON('["", "-DQUICK_LINT_JS_USE_BUILD_TOOLS=${PWD}/build-tools"]')[matrix.os.cross_compiling] }} ${CMAKE_EXTRA_FLAGS} -S . -B build
shell: bash
import os
import shlex
import subprocess
def var(name):
return os.environ.get(name, '')
command = [
"cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_TESTING=NO",
"-DQUICK_LINT_JS_ENABLE_VSCODE=YES",
"-DCMAKE_POSITION_INDEPENDENT_CODE=YES",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=YES",
"-S", ".", "-B", "build",
f"-DCMAKE_C_FLAGS={var('CMAKE_C_FLAGS')}",
f"-DCMAKE_CXX_FLAGS={var('CMAKE_CXX_FLAGS')}",
f"-DCMAKE_EXE_LINKER_FLAGS={var('CMAKE_EXE_LINKER_FLAGS')}",
f"-DCMAKE_SHARED_LINKER_FLAGS={var('CMAKE_SHARED_LINKER_FLAGS')}",
]
c_compiler = var('CMAKE_C_COMPILER')
if c_compiler: command.append(f"-DCMAKE_C_COMPILER={c_compiler}")
cxx_compiler = var('CMAKE_CXX_COMPILER')
if cxx_compiler: command.append(f"-DCMAKE_CXX_COMPILER={cxx_compiler}")
if "${{ matrix.os.cross_compiling }}":
command.append(f"-DQUICK_LINT_JS_USE_BUILD_TOOLS={os.getcwd()}/build-tools")
command.extend(var('CMAKE_EXTRA_FLAGS').split())
print(" ".join(shlex.quote(arg) for arg in command), flush=True)
result = subprocess.run(command)
exit(result.returncode)
- name: C++ build
run: cmake --build build --config Release --target quick-lint-js-vscode-node quick-lint-js-vscode-node-licenses
- name: C++ install
Expand Down
34 changes: 31 additions & 3 deletions .github/workflows/build-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,38 @@ jobs:
cmake --build build-tools --config Debug --target quick-lint-js-build-tools
- name: configure
shell: "python3 {0}"
run: |
env | grep '^CMAKE\|^QUICK_LINT_JS' | sort
cmake ${CMAKE_C_COMPILER:+-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}"} ${CMAKE_CXX_COMPILER:+-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}"} -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=${{ matrix.toolchain.test }} -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=YES -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS}" ${{ fromJSON('["", "-DQUICK_LINT_JS_USE_BUILD_TOOLS=${PWD}/build-tools"]')[matrix.toolchain.cross_compiling] }} ${CMAKE_EXTRA_FLAGS} -S . -B build
shell: bash
import os
import shlex
import subprocess
def var(name):
return os.environ.get(name, '')
command = [
"cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_TESTING=${{ matrix.toolchain.test }}",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=YES",
"-S", ".", "-B", "build",
f"-DCMAKE_C_FLAGS={var('CMAKE_C_FLAGS')}",
f"-DCMAKE_CXX_FLAGS={var('CMAKE_CXX_FLAGS')}",
f"-DCMAKE_EXE_LINKER_FLAGS={var('CMAKE_EXE_LINKER_FLAGS')}",
f"-DCMAKE_SHARED_LINKER_FLAGS={var('CMAKE_SHARED_LINKER_FLAGS')}",
]
c_compiler = var('CMAKE_C_COMPILER')
if c_compiler: command.append(f"-DCMAKE_C_COMPILER={c_compiler}")
cxx_compiler = var('CMAKE_CXX_COMPILER')
if cxx_compiler: command.append(f"-DCMAKE_CXX_COMPILER={cxx_compiler}")
if "${{ matrix.toolchain.cross_compiling }}":
command.append(f"-DQUICK_LINT_JS_USE_BUILD_TOOLS={os.getcwd()}/build-tools")
command.extend(var('CMAKE_EXTRA_FLAGS').split())
print(" ".join(shlex.quote(arg) for arg in command), flush=True)
result = subprocess.run(command)
exit(result.returncode)
- name: build
run: cmake --build build --config Release
- name: test
Expand Down
2 changes: 1 addition & 1 deletion dist/arch/PKGBUILD-dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pkgrel=1
pkgdesc="Find bugs in JavaScript programs"
arch=(aarch64 arm armv6h armv7h i686 pentium4 x86_64)
url="https://quick-lint-js.com/"
license=(Apache GPL3)
license=(Apache-2.0 GPL-3.0-or-later)
depends=(gcc-libs glibc hicolor-icon-theme)
makedepends=(cmake gcc git ninja)
checkdepends=(icu)
Expand Down
2 changes: 1 addition & 1 deletion dist/arch/PKGBUILD-git
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pkgrel=1
pkgdesc="Find bugs in JavaScript programs"
arch=(aarch64 arm armv6h armv7h i686 pentium4 x86_64)
url="https://quick-lint-js.com/"
license=(Apache GPL3)
license=(Apache-2.0 GPL-3.0-or-later)
depends=(gcc-libs glibc hicolor-icon-theme)
makedepends=(cmake gcc git ninja)
checkdepends=(icu)
Expand Down
2 changes: 1 addition & 1 deletion dist/arch/PKGBUILD-release
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pkgrel=1
pkgdesc="Find bugs in JavaScript programs"
arch=(aarch64 arm armv6h armv7h i686 pentium4 x86_64)
url="https://quick-lint-js.com/"
license=(Apache GPL3)
license=(Apache-2.0 GPL-3.0-or-later)
depends=(gcc-libs glibc hicolor-icon-theme)
makedepends=(cmake gcc ninja)
checkdepends=(icu)
Expand Down
13 changes: 12 additions & 1 deletion dist/arch/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ cd "$(dirname "${0}")"
errors="$(mktemp)"
trap 'rm -f "${errors}"' EXIT

# HACK(strager): Disable the symlink check. The debug package
# references files in the main package
# (usr/lib/debug/.build-id/7d/de35aceb40462c945841b0d88b87fdfab87ea5
# points to ../../../../bin/quick-lint-js), but because namcap lints
# each package separately, namcap doesn't see the file from the main
# package when linting the debug package.
#
# HACK(strager): Disable the emptydir check. The debug package,
# created automatically with OPTIONS=(debug strip), has an empty
# directory (usr/src/debug/quick-lint-js-dev/quick-lint-js/build).
#
# HACK(strager): Disable the unusedsodepends check. With -Wl,--gc-sections, the
# check fails on libm. Even with -Wl,--as-needed, the linker keeps the NEEDED
# entry, so I don't know how to work around the libm dependency.
namcap --exclude=unusedsodepends PKGBUILD-dev PKGBUILD-git PKGBUILD-release ./quick-lint-js-*.pkg.tar.zst |& tee "${errors}"
namcap --exclude=emptydir,symlink,unusedsodepends PKGBUILD-dev PKGBUILD-git PKGBUILD-release ./quick-lint-js-*.pkg.tar.zst |& tee "${errors}"
if [ -s "${errors}" ]; then
printf 'error: namcap reported an error\n' >&2
exit 1
Expand Down
10 changes: 10 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Semantic Versioning.

* TypeScript: `(): RT<T>=>null` (with no spaces in `>=>`) now parses correctly.
(Fixed by [vegerot][].)
* Fixed [E0718][] falsely diagnosing valid code. ([#1192][], [#1199][])
* quick-lint-js no longer crashes in the presence of symbolic links and
directory junctions on Windows. ([#1182][])
* Fixed a read buffer overflow (possibly leading to a crash) when checking
whether short identifiers containing Unicode escape sequences are keywords.
(x86 and x86_64 only.) ([#1191][])

## 3.1.0 (2024-01-10)

Expand Down Expand Up @@ -1416,7 +1422,11 @@ Beta release.
[#1168]: https://github.com/quick-lint/quick-lint-js/pull/1168
[#1171]: https://github.com/quick-lint/quick-lint-js/issues/1171
[#1180]: https://github.com/quick-lint/quick-lint-js/issues/1180
[#1182]: https://github.com/quick-lint/quick-lint-js/issues/1182
[#1191]: https://github.com/quick-lint/quick-lint-js/issues/1191
[#1192]: https://github.com/quick-lint/quick-lint-js/issues/1192
[#1194]: https://github.com/quick-lint/quick-lint-js/issues/1194
[#1199]: https://github.com/quick-lint/quick-lint-js/issues/1199

[E0001]: https://quick-lint-js.com/errors/E0001/
[E0003]: https://quick-lint-js.com/errors/E0003/
Expand Down
2 changes: 1 addition & 1 deletion plugin/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"test": "node test/run-vscode-tests.js"
},
"devDependencies": {
"@vscode/test-electron": "2.3.0",
"@vscode/test-electron": "2.3.9",
"colors": "1.4.0",
"prettier": "2.8.4",
"vsce": "2.15.0"
Expand Down
19 changes: 13 additions & 6 deletions plugin/vscode/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==

"@vscode/[email protected].0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@vscode/test-electron/-/test-electron-2.3.0.tgz#de0ba2f5d36546a83cd481b458cbdbb7cc0f7049"
integrity sha512-fwzA9RtazH1GT/sckYlbxu6t5e4VaMXwCVtyLv4UAG0hP6NTfnMaaG25XCfWqlVwFhBMcQXHBCy5dmz2eLUnkw==
"@vscode/[email protected].9":
version "2.3.9"
resolved "https://registry.yarnpkg.com/@vscode/test-electron/-/test-electron-2.3.9.tgz#f61181392634b408411e4302aef6e1cd2dd41474"
integrity sha512-z3eiChaCQXMqBnk2aHHSEkobmC2VRalFQN0ApOAtydL172zXGxTwGrRtviT5HnUB+Q+G3vtEYFtuQkYqBzYgMA==
dependencies:
http-proxy-agent "^4.0.1"
https-proxy-agent "^5.0.0"
jszip "^3.10.1"
semver "^7.3.8"
semver "^7.5.2"

agent-base@6:
version "6.0.2"
Expand Down Expand Up @@ -676,13 +676,20 @@ semver@^5.1.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^7.3.5, semver@^7.3.8:
semver@^7.3.5:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
dependencies:
lru-cache "^6.0.0"

semver@^7.5.2:
version "7.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
dependencies:
lru-cache "^6.0.0"

setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ quick_lint_js_add_library(
quick-lint-js/fe/language-debug.cpp
quick-lint-js/fe/lex-debug.cpp
quick-lint-js/i18n/po-parser-debug.cpp
quick-lint-js/io/file-path-debug.cpp
quick-lint-js/lsp/lsp-location-debug.cpp
quick-lint-js/port/char8-debug.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Change_Detecting_Filesystem_Win32::~Change_Detecting_Filesystem_Win32() {

Result<Canonical_Path_Result, Canonicalize_Path_IO_Error>
Change_Detecting_Filesystem_Win32::canonicalize_path(const std::string& path) {
return quick_lint_js::canonicalize_path(path);
return quick_lint_js::canonicalize_path(path, this);
}

Result<Padded_String, Read_File_IO_Error>
Expand All @@ -122,6 +122,39 @@ Change_Detecting_Filesystem_Win32::read_file(const Canonical_Path& path) {
return *std::move(r);
}

void Change_Detecting_Filesystem_Win32::on_canonicalize_child_of_directory(
const char*) {
// We don't use char paths on Windows.
QLJS_UNIMPLEMENTED();
}

void Change_Detecting_Filesystem_Win32::on_canonicalize_child_of_directory(
const wchar_t* path) {
// TODO(strager): Only watch parents of symlinks and of the target file. For
// example:
//
// Given a symlink C:\foo\bar.txt pointing to D:\baz\qix.txt,
// and assuming read_file("C:\\foo\\bar.txt"), then we should create oplocks
// for only the following directories:
//
// C:\foo
// D:\baz
//
// But today, we create oplocks for C:\, C:\foo, D:\, and D:\baz. This is
// inefficient.
bool ok = this->watch_directory(path);
if (!ok) {
std::optional<std::string> narrow_path = wstring_to_mbstring(path);
if (!narrow_path.has_value()) {
QLJS_UNIMPLEMENTED();
}
this->watch_errors_.emplace_back(Watch_IO_Error{
.path = narrow_path->c_str(),
.io_error = Windows_File_IO_Error{::GetLastError()},
});
}
}

bool Change_Detecting_Filesystem_Win32::handle_event(
::OVERLAPPED* overlapped, ::DWORD number_of_bytes_transferred,
::DWORD error) {
Expand Down Expand Up @@ -179,9 +212,13 @@ bool Change_Detecting_Filesystem_Win32::watch_directory(
if (!wpath.has_value()) {
QLJS_UNIMPLEMENTED();
}
return this->watch_directory(wpath->c_str());
}

bool Change_Detecting_Filesystem_Win32::watch_directory(
const wchar_t* directory) {
Windows_Handle_File directory_handle(::CreateFileW(
wpath->c_str(), /*dwDesiredAccess=*/GENERIC_READ,
directory, /*dwDesiredAccess=*/GENERIC_READ,
/*dwShareMode=*/FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
/*lpSecurityAttributes=*/nullptr,
/*dwCreationDisposition=*/OPEN_EXISTING,
Expand Down Expand Up @@ -215,9 +252,9 @@ bool Change_Detecting_Filesystem_Win32::watch_directory(
}

QLJS_DEBUG_LOG(
"note: Directory handle %#llx: %s: Directory identity changed\n",
"note: Directory handle %#llx: %ls: Directory identity changed\n",
reinterpret_cast<unsigned long long>(old_dir->directory_handle.get()),
directory.c_str());
directory);
this->cancel_watch(std::move(watched_directory_it->second));
watched_directory_it->second = std::move(new_dir);
}
Expand Down Expand Up @@ -249,6 +286,10 @@ bool Change_Detecting_Filesystem_Win32::watch_directory(
DWORD error = ::GetLastError();
if (error == ERROR_IO_PENDING) {
// run_io_thread will handle the oplock breaking.
QLJS_DEBUG_LOG(
"note: Watching directory with handle %#llx: %ls\n",
reinterpret_cast<unsigned long long>(dir->directory_handle.get()),
directory);
} else {
// FIXME(strager): Should we close the directory handle?
return false;
Expand Down Expand Up @@ -297,7 +338,7 @@ void Change_Detecting_Filesystem_Win32::handle_oplock_broke_event(
//
// https://docs.microsoft.com/en-us/windows/win32/api/winioctl/ni-winioctl-fsctl_request_oplock
QLJS_DEBUG_LOG(
"note: Directory handle %#llx: %s: Oplock broke\n",
"note: Directory handle %#llx: %ls: Oplock broke\n",
reinterpret_cast<unsigned long long>(dir->directory_handle.get()),
directory_it->first.c_str());
QLJS_ASSERT(number_of_bytes_transferred == sizeof(dir->oplock_response));
Expand Down
9 changes: 7 additions & 2 deletions src/quick-lint-js/configuration/change-detecting-filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ extern ::DWORD mock_win32_force_directory_file_id_error;
extern ::DWORD mock_win32_force_directory_ioctl_error;

// Not thread-safe.
class Change_Detecting_Filesystem_Win32 : public Configuration_Filesystem {
class Change_Detecting_Filesystem_Win32 : public Configuration_Filesystem,
Canonicalize_Observer {
public:
explicit Change_Detecting_Filesystem_Win32(
Windows_Handle_File_Ref io_completion_port, ::ULONG_PTR completion_key);
Expand All @@ -164,6 +165,9 @@ class Change_Detecting_Filesystem_Win32 : public Configuration_Filesystem {
Result<Padded_String, Read_File_IO_Error> read_file(
const Canonical_Path&) override;

void on_canonicalize_child_of_directory(const char*) override;
void on_canonicalize_child_of_directory(const wchar_t*) override;

Windows_Handle_File_Ref io_completion_port() const {
return this->io_completion_port_;
}
Expand Down Expand Up @@ -200,6 +204,7 @@ class Change_Detecting_Filesystem_Win32 : public Configuration_Filesystem {

// Calls SetLastError and returns false on failure.
bool watch_directory(const Canonical_Path&);
bool watch_directory(const wchar_t* path);

void cancel_watch(std::unique_ptr<Watched_Directory>&&);

Expand All @@ -210,7 +215,7 @@ class Change_Detecting_Filesystem_Win32 : public Configuration_Filesystem {
Windows_Handle_File_Ref io_completion_port_;
::ULONG_PTR completion_key_;

Hash_Map<Canonical_Path, std::unique_ptr<Watched_Directory>>
Hash_Map<std::wstring, std::unique_ptr<Watched_Directory>>
watched_directories_;
std::vector<std::unique_ptr<Watched_Directory>>
cancelling_watched_directories_;
Expand Down
9 changes: 9 additions & 0 deletions src/quick-lint-js/container/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ template <>
struct Hasher<String8> : Hasher<String8_View> {};
#endif

template <>
struct Hasher<std::wstring_view> {
std::size_t operator()(std::wstring_view s) const {
return std::hash<std::wstring_view>()(s);
}
};
template <>
struct Hasher<std::wstring> : Hasher<std::wstring_view> {};

template <class T1, class T2>
struct Hasher<std::pair<T1, T2>> {
template <class U1, class U2>
Expand Down
9 changes: 8 additions & 1 deletion src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <quick-lint-js/diag/buffering-diag-reporter.h>
#include <quick-lint-js/diag/diag-list.h>
#include <quick-lint-js/diag/diagnostic-types.h>
#include <quick-lint-js/fe/keyword-lexer.h>
#include <quick-lint-js/fe/lex.h>
#include <quick-lint-js/fe/token.h>
#include <quick-lint-js/port/bit.h>
Expand Down Expand Up @@ -1832,9 +1833,15 @@ Lexer::Parsed_Identifier Lexer::parse_identifier_slow(
}
}

String8_View normalized_view = normalized.release_to_string_view();

// Add padding bytes required by Keyword_Lexer. This should not be considered
// part of the returned string.
normalized.resize(normalized.size() + Keyword_Lexer::padding_size);

return Parsed_Identifier{
.after = input,
.normalized = normalized.release_to_string_view(),
.normalized = normalized_view,
.escape_sequences = escape_sequences,
};
}
Expand Down
Loading

0 comments on commit 963b20d

Please sign in to comment.