From a8a4b54b90e6433cf4a25a88a4765243f831ebef Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 11:20:24 +0900 Subject: refactor(seld-json-lint): extract seld/json_lint into the shirabe-seld-json-lint crate Move `Seld\JsonLint` out of shirabe-external-packages and into its own crate, so the path is `shirabe_seld_json_lint::ParsingException` instead of `shirabe_external_packages::seld::json_lint::ParsingException`. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-external-packages/src/seld.rs | 2 - .../src/seld/json_lint.rs | 15 -------- .../src/seld/json_lint/parsing_exception.rs | 45 ---------------------- crates/shirabe-seld-json-lint/Cargo.toml | 11 ++++++ crates/shirabe-seld-json-lint/src/lib.rs | 15 ++++++++ .../src/parsing_exception.rs | 45 ++++++++++++++++++++++ crates/shirabe/Cargo.toml | 1 + crates/shirabe/src/console/application.rs | 2 +- crates/shirabe/src/installer.rs | 2 +- crates/shirabe/src/json/json_file.rs | 2 +- crates/shirabe/src/package/locker.rs | 2 +- crates/shirabe/tests/json/json_file_test.rs | 2 +- 12 files changed, 77 insertions(+), 67 deletions(-) delete mode 100644 crates/shirabe-external-packages/src/seld/json_lint.rs delete mode 100644 crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs create mode 100644 crates/shirabe-seld-json-lint/Cargo.toml create mode 100644 crates/shirabe-seld-json-lint/src/lib.rs create mode 100644 crates/shirabe-seld-json-lint/src/parsing_exception.rs (limited to 'crates') diff --git a/crates/shirabe-external-packages/src/seld.rs b/crates/shirabe-external-packages/src/seld.rs index b7c12c45..ffe32e07 100644 --- a/crates/shirabe-external-packages/src/seld.rs +++ b/crates/shirabe-external-packages/src/seld.rs @@ -1,5 +1,3 @@ -pub mod json_lint; pub mod signal; -pub use json_lint::*; pub use signal::*; diff --git a/crates/shirabe-external-packages/src/seld/json_lint.rs b/crates/shirabe-external-packages/src/seld/json_lint.rs deleted file mode 100644 index 2165c8f2..00000000 --- a/crates/shirabe-external-packages/src/seld/json_lint.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Partial port of seld/jsonlint. -//! -//! The parser, lexer, and duplicate-key exception (`JsonParser`, `Lexer`, -//! `DuplicateKeyException`) are intentionally not ported: JSON syntax validation now relies on -//! serde_json, and duplicate-key detection is done with a hand-written serde visitor, so -//! jsonlint's own parsing machinery is no longer needed. -//! -//! `ParsingException` is kept because it is the exception type thrown for invalid JSON and is -//! matched (via downcast) across the codebase as an error-kind signal; it also carries detail -//! such as the error line. Porting it keeps both the thrown exception class and the information -//! it carries unchanged. - -pub mod parsing_exception; - -pub use parsing_exception::*; diff --git a/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs b/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs deleted file mode 100644 index 9d3eaa57..00000000 --- a/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! ref: composer/vendor/seld/jsonlint/src/Seld/JsonLint/ParsingException.php - -#[derive(Debug, Clone, Default)] -pub struct ParsingExceptionLoc { - pub first_line: i64, - pub first_column: i64, - pub last_line: i64, - pub last_column: i64, -} - -#[derive(Debug, Clone)] -pub enum ParsingExceptionToken { - Name(String), - Symbol(i64), -} - -#[derive(Debug, Clone, Default)] -pub struct ParsingExceptionDetails { - pub text: Option, - pub token: Option, - pub line: Option, - pub loc: Option, - pub expected: Option>, -} - -#[derive(Debug)] -pub struct ParsingException { - inner: shirabe_php_shim::Exception, - pub(crate) details: Box, -} - -impl ParsingException { - pub fn new(message: String, details: ParsingExceptionDetails) -> Self { - Self { - inner: shirabe_php_shim::Exception::new(message), - details: Box::new(details), - } - } - - pub fn get_details(&self) -> &ParsingExceptionDetails { - &self.details - } -} - -shirabe_php_shim::impl_php_exception!(ParsingException, inner, r"Seld\JsonLint\ParsingException"); diff --git a/crates/shirabe-seld-json-lint/Cargo.toml b/crates/shirabe-seld-json-lint/Cargo.toml new file mode 100644 index 00000000..907e382c --- /dev/null +++ b/crates/shirabe-seld-json-lint/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "shirabe-seld-json-lint" +version.workspace = true +edition.workspace = true + +[dependencies] +shirabe-php-shim.workspace = true +anyhow.workspace = true + +[lints] +workspace = true diff --git a/crates/shirabe-seld-json-lint/src/lib.rs b/crates/shirabe-seld-json-lint/src/lib.rs new file mode 100644 index 00000000..2165c8f2 --- /dev/null +++ b/crates/shirabe-seld-json-lint/src/lib.rs @@ -0,0 +1,15 @@ +//! Partial port of seld/jsonlint. +//! +//! The parser, lexer, and duplicate-key exception (`JsonParser`, `Lexer`, +//! `DuplicateKeyException`) are intentionally not ported: JSON syntax validation now relies on +//! serde_json, and duplicate-key detection is done with a hand-written serde visitor, so +//! jsonlint's own parsing machinery is no longer needed. +//! +//! `ParsingException` is kept because it is the exception type thrown for invalid JSON and is +//! matched (via downcast) across the codebase as an error-kind signal; it also carries detail +//! such as the error line. Porting it keeps both the thrown exception class and the information +//! it carries unchanged. + +pub mod parsing_exception; + +pub use parsing_exception::*; diff --git a/crates/shirabe-seld-json-lint/src/parsing_exception.rs b/crates/shirabe-seld-json-lint/src/parsing_exception.rs new file mode 100644 index 00000000..9d3eaa57 --- /dev/null +++ b/crates/shirabe-seld-json-lint/src/parsing_exception.rs @@ -0,0 +1,45 @@ +//! ref: composer/vendor/seld/jsonlint/src/Seld/JsonLint/ParsingException.php + +#[derive(Debug, Clone, Default)] +pub struct ParsingExceptionLoc { + pub first_line: i64, + pub first_column: i64, + pub last_line: i64, + pub last_column: i64, +} + +#[derive(Debug, Clone)] +pub enum ParsingExceptionToken { + Name(String), + Symbol(i64), +} + +#[derive(Debug, Clone, Default)] +pub struct ParsingExceptionDetails { + pub text: Option, + pub token: Option, + pub line: Option, + pub loc: Option, + pub expected: Option>, +} + +#[derive(Debug)] +pub struct ParsingException { + inner: shirabe_php_shim::Exception, + pub(crate) details: Box, +} + +impl ParsingException { + pub fn new(message: String, details: ParsingExceptionDetails) -> Self { + Self { + inner: shirabe_php_shim::Exception::new(message), + details: Box::new(details), + } + } + + pub fn get_details(&self) -> &ParsingExceptionDetails { + &self.details + } +} + +shirabe_php_shim::impl_php_exception!(ParsingException, inner, r"Seld\JsonLint\ParsingException"); diff --git a/crates/shirabe/Cargo.toml b/crates/shirabe/Cargo.toml index 6623ba80..35aa4737 100644 --- a/crates/shirabe/Cargo.toml +++ b/crates/shirabe/Cargo.toml @@ -10,6 +10,7 @@ shirabe-metadata-minifier.workspace = true shirabe-pcre.workspace = true shirabe-php-rpc.workspace = true shirabe-php-shim.workspace = true +shirabe-seld-json-lint.workspace = true shirabe-semver.workspace = true shirabe-spdx-licenses.workspace = true shirabe-symfony-console.workspace = true diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 2e93c33d..f5c953da 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -55,7 +55,6 @@ use crate::util::Platform; use crate::util::Silencer; use indexmap::IndexMap; use shirabe_external_packages::composer::xdebug_handler::XdebugHandler; -use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ LogicException as ShimLogicException, PHP_VERSION, PHP_VERSION_ID, PhpMixed, RuntimeException, @@ -66,6 +65,7 @@ use shirabe_php_shim::{ php_uname, posix_getuid, random_bytes, realpath, restore_error_handler, round, str_contains, str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink, }; +use shirabe_seld_json_lint::ParsingException; use shirabe_symfony_console::application::Application as BaseApplication; use shirabe_symfony_console::command::Command as SymfonyCommand; use shirabe_symfony_console::command::help_command::HelpCommand; diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs index 22da3fff..4ff6af3d 100644 --- a/crates/shirabe/src/installer.rs +++ b/crates/shirabe/src/installer.rs @@ -34,11 +34,11 @@ pub use suggested_packages_reporter::*; use crate::io::io_interface; use indexmap::IndexMap; -use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_php_shim::{ PhpMixed, RuntimeException, array_map, array_unique, implode, intval, is_dir, is_numeric, strcmp, strpos, strtolower, touch, usort, }; +use shirabe_seld_json_lint::ParsingException; use shirabe_semver; use crate::advisory::AuditConfig; diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index f506a831..b08a7a97 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -9,7 +9,6 @@ use crate::util::Filesystem; use crate::util::HttpDownloader; use crate::util::Silencer; use indexmap::IndexMap; -use shirabe_external_packages::seld::json_lint::{ParsingException, ParsingExceptionDetails}; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ @@ -18,6 +17,7 @@ use shirabe_php_shim::{ file_put_contents, is_dir, is_file, json_decode, json_encode_ex, mkdir, php_regex, realpath, str_contains, str_ends_with, str_repeat, strlen, strpos, usleep, }; +use shirabe_seld_json_lint::{ParsingException, ParsingExceptionDetails}; #[derive(Debug, Clone)] pub struct JsonEncodeOptions { diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index 67b2d5b4..ccfb2ddf 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -24,7 +24,6 @@ use crate::repository::RootPackageRepository; use crate::util::Git as GitUtil; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ @@ -32,6 +31,7 @@ use shirabe_php_shim::{ array_map, array_merge, file_get_contents, filemtime, function_exists, hash, in_array_loose, is_int, ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort, }; +use shirabe_seld_json_lint::ParsingException; /// Reads/writes project lockfile (composer.lock). #[derive(Debug)] diff --git a/crates/shirabe/tests/json/json_file_test.rs b/crates/shirabe/tests/json/json_file_test.rs index a20e7234..27b43a05 100644 --- a/crates/shirabe/tests/json/json_file_test.rs +++ b/crates/shirabe/tests/json/json_file_test.rs @@ -2,9 +2,9 @@ use indexmap::IndexMap; use shirabe::json::{JsonEncodeOptions, JsonFile, JsonValidationException}; -use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_php_shim::Catch as _; use shirabe_php_shim::PhpMixed; +use shirabe_seld_json_lint::ParsingException; /// ref: JsonFileTest::expectParseException fn expect_parse_exception(text: &str, json: &str) { -- cgit v1.3.1-4-g156e