Skip to content

Commit

Permalink
Switch back to Prettier for Svelte formatting
Browse files Browse the repository at this point in the history
Closes #3649
Closes #3713
  • Loading branch information
abdnh authored and dae committed Jan 13, 2025
1 parent 178a3fa commit 2c1a489
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
8 changes: 0 additions & 8 deletions .dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
},
"markdown": {},
"toml": {},
"prettier": {
"trailingComma": "all",
"printWidth": 88,
"tabWidth": 4,
"semi": true,
"htmlWhitespaceSensitivity": "ignore"
},
"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,svelte,scss}"],
"excludes": [
".vscode",
Expand All @@ -39,7 +32,6 @@
"https://plugins.dprint.dev/json-0.19.3.wasm",
"https://plugins.dprint.dev/markdown-0.17.6.wasm",
"https://plugins.dprint.dev/toml-0.6.2.wasm",
"https://plugins.dprint.dev/prettier-0.46.1.json@e5bd083088a8dfc6e5ce2d3c9bee81489b065bd5345ef55b59f5d96627928b7a",
"https://plugins.dprint.dev/disrupted/css-0.2.3.wasm"
]
}
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"trailingComma": "all",
"printWidth": 88,
"tabWidth": 4,
"semi": true,
"htmlWhitespaceSensitivity": "ignore",
"plugins": ["prettier-plugin-svelte"]
}
24 changes: 20 additions & 4 deletions build/configure/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ninja_gen::node::DPrint;
use ninja_gen::node::EsbuildScript;
use ninja_gen::node::Eslint;
use ninja_gen::node::GenTypescriptProto;
use ninja_gen::node::Prettier;
use ninja_gen::node::SqlFormat;
use ninja_gen::node::SvelteCheck;
use ninja_gen::node::SveltekitBuild;
Expand Down Expand Up @@ -64,6 +65,7 @@ fn setup_node(build: &mut Build) -> Result<()> {
"vite",
"vitest",
"protoc-gen-es",
"prettier",
],
hashmap! {
"jquery" => vec![
Expand Down Expand Up @@ -290,10 +292,10 @@ fn build_and_check_reviewer(build: &mut Build) -> Result<()> {
}

fn check_web(build: &mut Build) -> Result<()> {
let dprint_files = inputs![glob![
"**/*.{ts,mjs,js,md,json,toml,svelte,scss}",
"{target,ts/.svelte-kit,node_modules}/**"
]];
let fmt_excluded = "{target,ts/.svelte-kit,node_modules}/**";
let dprint_files = inputs![glob!["**/*.{ts,mjs,js,md,json,toml,scss}", fmt_excluded]];
let prettier_files = inputs![glob!["**/*.svelte", fmt_excluded]];

build.add_action(
"check:format:dprint",
DPrint {
Expand All @@ -308,6 +310,20 @@ fn check_web(build: &mut Build) -> Result<()> {
check_only: false,
},
)?;
build.add_action(
"check:format:prettier",
Prettier {
inputs: prettier_files.clone(),
check_only: true,
},
)?;
build.add_action(
"format:prettier",
Prettier {
inputs: prettier_files,
check_only: false,
},
)?;
build.add_action(
"check:vitest",
ViteTest {
Expand Down
24 changes: 24 additions & 0 deletions build/ninja_gen/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ impl BuildAction for DPrint {
}
}

pub struct Prettier {
pub inputs: BuildInput,
pub check_only: bool,
}

impl BuildAction for Prettier {
fn command(&self) -> &str {
"$prettier $mode $pattern"
}

fn files(&mut self, build: &mut impl build::FilesHandle) {
build.add_inputs("prettier", inputs![":node_modules:prettier"]);
build.add_inputs("", &self.inputs);
build.add_variable("pattern", r#""**/*.svelte""#);
let (file_ext, mode) = if self.check_only {
("fmt", "--check")
} else {
("check", "--write")
};
build.add_variable("mode", mode);
build.add_output_stamp(format!("tests/prettier.{file_ext}"));
}
}

pub struct SvelteCheck {
pub tsconfig: BuildInput,
pub inputs: BuildInput,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-svelte": "^2",
"license-checker-rseidelsohn": "=4.3.0",
"prettier": "^2.4.1",
"prettier-plugin-svelte": "^3.2.6",
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"sass": "<1.77",
"svelte": "^5.17.3",
"svelte-check": "^3.4.4",
Expand Down
36 changes: 10 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3637,15 +3637,15 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier-plugin-svelte@^3.2.6:
version "3.2.7"
resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-3.2.7.tgz#10db2d553b48c6ed412e2d00688f8d2eaa274f8a"
integrity sha512-/Dswx/ea0lV34If1eDcG3nulQ63YNr5KPDfMsjbdtpSWOxKKJ7nAc2qlVuYwEvCr4raIuredNoR7K4JCkmTGaQ==
prettier-plugin-svelte@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-3.3.2.tgz#f0c0b023a697f5cb43fb7257170e3d8762b547c6"
integrity sha512-kRPjH8wSj2iu+dO+XaUv4vD8qr5mdDmlak3IT/7AOgGIMRG86z/EHOLauFcClKEnOUf4A4nOA7sre5KrJD4Raw==

prettier@^2.4.1:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
prettier@^3.4.2:
version "3.4.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.2.tgz#a5ce1fb522a588bf2b78ca44c6e6fe5aa5a2b13f"
integrity sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==

psl@^1.1.33:
version "1.9.0"
Expand Down Expand Up @@ -4039,16 +4039,7 @@ std-env@^3.7.0:
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.7.0.tgz#c9f7386ced6ecf13360b6c6c55b8aaa4ef7481d2"
integrity sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -4094,14 +4085,7 @@ string.prototype.trimstart@^1.0.8:
define-properties "^1.2.1"
es-object-atoms "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down

0 comments on commit 2c1a489

Please sign in to comment.