From c3c405f2f69cf6da889947a46a2444bcf70e1a25 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:56:32 +0000 Subject: [PATCH 1/2] fix(deps): update @biomejs packages (#4704) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .../@biomejs/backend-jsonrpc/package.json | 2 +- .../tailwindcss-config-analyzer/package.json | 2 +- pnpm-lock.yaml | 87 +++++++------------ 3 files changed, 32 insertions(+), 59 deletions(-) diff --git a/packages/@biomejs/backend-jsonrpc/package.json b/packages/@biomejs/backend-jsonrpc/package.json index aef1f232bde6..56035fffed1b 100644 --- a/packages/@biomejs/backend-jsonrpc/package.json +++ b/packages/@biomejs/backend-jsonrpc/package.json @@ -36,7 +36,7 @@ }, "license": "MIT OR Apache-2.0", "devDependencies": { - "@types/node": "20.17.9", + "@types/node": "20.17.10", "typescript": "5.7.2", "vite": "5.4.11", "vitest": "1.6.0" diff --git a/packages/tailwindcss-config-analyzer/package.json b/packages/tailwindcss-config-analyzer/package.json index c0b2cc35fc65..25ac75cdf4e5 100644 --- a/packages/tailwindcss-config-analyzer/package.json +++ b/packages/tailwindcss-config-analyzer/package.json @@ -7,7 +7,7 @@ "author": "Dani Guardiola", "type": "module", "dependencies": { - "tailwindcss": "^3.4.15" + "tailwindcss": "^3.4.16" }, "devDependencies": { "@types/bun": "1.1.14", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2d780b7a0dd..f4db618f8c0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,17 +57,17 @@ importers: version: 1.9.4 devDependencies: '@types/node': - specifier: 20.17.9 - version: 20.17.9 + specifier: 20.17.10 + version: 20.17.10 typescript: specifier: 5.7.2 version: 5.7.2 vite: specifier: 5.4.11 - version: 5.4.11(@types/node@20.17.9) + version: 5.4.11(@types/node@20.17.10) vitest: specifier: 1.6.0 - version: 1.6.0(@types/node@20.17.9)(happy-dom@15.11.7) + version: 1.6.0(@types/node@20.17.10)(happy-dom@15.11.7) packages/@biomejs/biome: optionalDependencies: @@ -128,10 +128,10 @@ importers: version: 5.7.2 vite: specifier: 5.4.11 - version: 5.4.11(@types/node@20.17.9) + version: 5.4.11(@types/node@20.17.10) vitest: specifier: 1.6.0 - version: 1.6.0(@types/node@20.17.9)(happy-dom@15.11.7) + version: 1.6.0(@types/node@20.17.10)(happy-dom@15.11.7) packages/@biomejs/wasm-bundler: {} @@ -148,8 +148,8 @@ importers: packages/tailwindcss-config-analyzer: dependencies: tailwindcss: - specifier: ^3.4.15 - version: 3.4.15 + specifier: ^3.4.16 + version: 3.4.16 devDependencies: '@types/bun': specifier: 1.1.14 @@ -601,8 +601,8 @@ packages: '@types/node@20.12.12': resolution: {integrity: sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw==} - '@types/node@20.17.9': - resolution: {integrity: sha512-0JOXkRyLanfGPE2QRCwgxhzlBAvaRdCNMcvbd7jFfpmD4eEXll7LRwy5ymJmyeZqk7Nh7eD2LeUyQ68BbndmXw==} + '@types/node@20.17.10': + resolution: {integrity: sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -783,10 +783,6 @@ packages: brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} - braces@3.0.2: - resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} - engines: {node: '>=8'} - braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -995,10 +991,6 @@ packages: resolution: {integrity: sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==} engines: {node: '>=16.0.0'} - fill-range@7.0.1: - resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} - engines: {node: '>=8'} - fill-range@7.1.1: resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} engines: {node: '>=8'} @@ -1161,12 +1153,8 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} - lilconfig@2.1.0: - resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==} - engines: {node: '>=10'} - - lilconfig@3.1.1: - resolution: {integrity: sha512-O18pf7nyvHTckunPWCV1XUNXU1piu01y2b7ATJ0ppkUkk8ocqVWBrYjJBCwHDjD/ZWcfyrA0P4gKhzWGi5EINQ==} + lilconfig@3.1.3: + resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} lines-and-columns@1.2.4: @@ -1319,9 +1307,6 @@ packages: picocolors@1.0.0: resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} - picocolors@1.1.0: - resolution: {integrity: sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==} - picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -1530,8 +1515,8 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} - tailwindcss@3.4.15: - resolution: {integrity: sha512-r4MeXnfBmSOuKUWmXe6h2CcyfzJCEk4F0pptO5jlnYSIViUkVmsawj80N5h2lO3gwcmSb4n3PuN+e+GC1Guylw==} + tailwindcss@3.4.16: + resolution: {integrity: sha512-TI4Cyx7gDiZ6r44ewaJmt0o6BrMCT5aK5e0rmJ/G9Xq3w7CX/5VXl/zIPEJZFUK5VEqwByyhqNPycPlvcK4ZNw==} engines: {node: '>=14.0.0'} hasBin: true @@ -2008,7 +1993,7 @@ snapshots: dependencies: undici-types: 5.26.5 - '@types/node@20.17.9': + '@types/node@20.17.10': dependencies: undici-types: 6.19.8 @@ -2016,7 +2001,7 @@ snapshots: '@types/ws@8.5.10': dependencies: - '@types/node': 20.17.9 + '@types/node': 20.17.10 '@typescript-eslint/eslint-plugin@8.17.0(@typescript-eslint/parser@8.3.0(eslint@9.16.0(jiti@1.21.6))(typescript@5.7.2))(eslint@9.16.0(jiti@1.21.6))(typescript@5.7.2)': dependencies: @@ -2217,10 +2202,6 @@ snapshots: dependencies: balanced-match: 1.0.2 - braces@3.0.2: - dependencies: - fill-range: 7.0.1 - braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -2264,7 +2245,7 @@ snapshots: chokidar@3.6.0: dependencies: anymatch: 3.1.3 - braces: 3.0.2 + braces: 3.0.3 glob-parent: 5.1.2 is-binary-path: 2.1.0 is-glob: 4.0.3 @@ -2481,10 +2462,6 @@ snapshots: dependencies: flat-cache: 4.0.1 - fill-range@7.0.1: - dependencies: - to-regex-range: 5.0.1 - fill-range@7.1.1: dependencies: to-regex-range: 5.0.1 @@ -2621,9 +2598,7 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 - lilconfig@2.1.0: {} - - lilconfig@3.1.1: {} + lilconfig@3.1.3: {} lines-and-columns@1.2.4: {} @@ -2765,8 +2740,6 @@ snapshots: picocolors@1.0.0: {} - picocolors@1.1.0: {} - picocolors@1.1.1: {} picomatch@2.3.1: {} @@ -2795,7 +2768,7 @@ snapshots: postcss-load-config@4.0.2(postcss@8.4.47): dependencies: - lilconfig: 3.1.1 + lilconfig: 3.1.3 yaml: 2.4.1 optionalDependencies: postcss: 8.4.47 @@ -2815,7 +2788,7 @@ snapshots: postcss@8.4.47: dependencies: nanoid: 3.3.7 - picocolors: 1.1.0 + picocolors: 1.1.1 source-map-js: 1.2.1 prelude-ls@1.2.1: {} @@ -2976,7 +2949,7 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} - tailwindcss@3.4.15: + tailwindcss@3.4.16: dependencies: '@alloc/quick-lru': 5.2.0 arg: 5.0.2 @@ -2987,7 +2960,7 @@ snapshots: glob-parent: 6.0.2 is-glob: 4.0.3 jiti: 1.21.6 - lilconfig: 2.1.0 + lilconfig: 3.1.3 micromatch: 4.0.8 normalize-path: 3.0.0 object-hash: 3.0.0 @@ -3056,13 +3029,13 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 - vite-node@1.6.0(@types/node@20.17.9): + vite-node@1.6.0(@types/node@20.17.10): dependencies: cac: 6.7.14 debug: 4.3.7 pathe: 1.1.2 picocolors: 1.0.0 - vite: 5.4.11(@types/node@20.17.9) + vite: 5.4.11(@types/node@20.17.10) transitivePeerDependencies: - '@types/node' - less @@ -3074,16 +3047,16 @@ snapshots: - supports-color - terser - vite@5.4.11(@types/node@20.17.9): + vite@5.4.11(@types/node@20.17.10): dependencies: esbuild: 0.21.5 postcss: 8.4.47 rollup: 4.23.0 optionalDependencies: - '@types/node': 20.17.9 + '@types/node': 20.17.10 fsevents: 2.3.3 - vitest@1.6.0(@types/node@20.17.9)(happy-dom@15.11.7): + vitest@1.6.0(@types/node@20.17.10)(happy-dom@15.11.7): dependencies: '@vitest/expect': 1.6.0 '@vitest/runner': 1.6.0 @@ -3102,11 +3075,11 @@ snapshots: strip-literal: 2.1.0 tinybench: 2.9.0 tinypool: 0.8.4 - vite: 5.4.11(@types/node@20.17.9) - vite-node: 1.6.0(@types/node@20.17.9) + vite: 5.4.11(@types/node@20.17.10) + vite-node: 1.6.0(@types/node@20.17.10) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 20.17.9 + '@types/node': 20.17.10 happy-dom: 15.11.7 transitivePeerDependencies: - less From c2dda66cc7533019bbd6c76960fcd68cd94cf1be Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 12 Dec 2024 14:19:52 -0500 Subject: [PATCH 2/2] feat(format/html): opt out of formatting for `pre`, `script` and `style` tags (#4729) --- .../biome_formatter/src/format_element/tag.rs | 2 + crates/biome_formatter/src/prelude.rs | 1 + crates/biome_formatter/src/verbatim.rs | 10 ++++ .../src/html/auxiliary/element.rs | 27 +++++++--- crates/biome_html_formatter/src/prelude.rs | 4 +- .../tests/specs/html/elements/pre.html | 13 +++++ .../tests/specs/html/elements/pre.html.snap | 52 +++++++++++++++++++ 7 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 crates/biome_html_formatter/tests/specs/html/elements/pre.html create mode 100644 crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap diff --git a/crates/biome_formatter/src/format_element/tag.rs b/crates/biome_formatter/src/format_element/tag.rs index ef4a1ca8a732..e07427347ce1 100644 --- a/crates/biome_formatter/src/format_element/tag.rs +++ b/crates/biome_formatter/src/format_element/tag.rs @@ -282,6 +282,8 @@ pub trait Label { pub enum VerbatimKind { Bogus, Suppressed, + /// This was intentionally skipped, not as a result of suppression. + Skipped, Verbatim { /// the length of the formatted node length: TextSize, diff --git a/crates/biome_formatter/src/prelude.rs b/crates/biome_formatter/src/prelude.rs index 78de2340d051..8513c0973f68 100644 --- a/crates/biome_formatter/src/prelude.rs +++ b/crates/biome_formatter/src/prelude.rs @@ -13,6 +13,7 @@ pub use crate::format_element::document::Document; pub use crate::format_element::tag::{LabelId, Tag, TagKind}; pub use crate::verbatim::{ format_bogus_node, format_or_verbatim, format_suppressed_node, format_verbatim_node, + format_verbatim_skipped, }; pub use crate::{ diff --git a/crates/biome_formatter/src/verbatim.rs b/crates/biome_formatter/src/verbatim.rs index 59429c924e15..47d308dd0367 100644 --- a/crates/biome_formatter/src/verbatim.rs +++ b/crates/biome_formatter/src/verbatim.rs @@ -24,6 +24,16 @@ pub fn format_verbatim_node(node: &SyntaxNode) -> FormatVerbatim } } +/// "Formats" a node according to its original formatting in the source text. It's functionally equal to +/// [`format_verbatim_node`], but it doesn't track the node as [VerbatimKind::Verbatim]. +pub fn format_verbatim_skipped(node: &SyntaxNode) -> FormatVerbatimNode { + FormatVerbatimNode { + node, + kind: VerbatimKind::Skipped, + format_comments: true, + } +} + #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub struct FormatVerbatimNode<'node, L: Language> { node: &'node SyntaxNode, diff --git a/crates/biome_html_formatter/src/html/auxiliary/element.rs b/crates/biome_html_formatter/src/html/auxiliary/element.rs index 6c468d16daea..f15cf06962c6 100644 --- a/crates/biome_html_formatter/src/html/auxiliary/element.rs +++ b/crates/biome_html_formatter/src/html/auxiliary/element.rs @@ -11,14 +11,25 @@ impl FormatNodeRule for FormatHtmlElement { closing_element, } = node.as_fields(); - write!( - f, - [ - opening_element.format(), - children.format(), - closing_element.format(), - ] - )?; + let tag_name = opening_element + .clone() + .and_then(|e| e.name()) + .map(|e| e.text()) + .unwrap_or_default(); + // `pre` tags are "preformatted", so we should not format the content inside them. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre + // We ignore the `script` and `style` tags as well, since embedded language parsing/formatting is not yet implemented. + let should_be_verbatim = ["script", "style", "pre"] + .iter() + .any(|tag| tag_name.eq_ignore_ascii_case(tag)); + + write!(f, [opening_element.format()])?; + if should_be_verbatim { + format_verbatim_skipped(children.syntax()).fmt(f)?; + write!(f, [hard_line_break()])?; + } else { + write!(f, [children.format()])?; + } + write!(f, [closing_element.format()])?; Ok(()) } diff --git a/crates/biome_html_formatter/src/prelude.rs b/crates/biome_html_formatter/src/prelude.rs index e5c3661049a9..b6cf7b5b1213 100644 --- a/crates/biome_html_formatter/src/prelude.rs +++ b/crates/biome_html_formatter/src/prelude.rs @@ -1,7 +1,7 @@ #[allow(unused_imports)] pub(crate) use crate::{ - format_verbatim_node, AsFormat, FormatNodeRule, FormatResult, FormatRule, FormattedIterExt, - HtmlFormatContext, HtmlFormatter, + format_verbatim_node, format_verbatim_skipped, AsFormat, FormatNodeRule, FormatResult, + FormatRule, FormattedIterExt, HtmlFormatContext, HtmlFormatter, }; pub(crate) use biome_formatter::prelude::*; #[allow(unused_imports)] diff --git a/crates/biome_html_formatter/tests/specs/html/elements/pre.html b/crates/biome_html_formatter/tests/specs/html/elements/pre.html new file mode 100644 index 000000000000..1d3423e9d132 --- /dev/null +++ b/crates/biome_html_formatter/tests/specs/html/elements/pre.html @@ -0,0 +1,13 @@ +
+	___                       ___           ___           ___
+	/\  \          ___        /\  \         /\__\         /\  \
+ /::\  \        /\  \      /::\  \       /::|  |       /::\  \
+/:/\:\  \       \:\  \    /:/\:\  \     /:|:|  |      /:/\:\  \
+/::\~\:\__\      /::\__\  /:/  \:\  \   /:/|:|__|__   /::\~\:\  \
+/:/\:\ \:|__|  __/:/\/__/ /:/__/ \:\__\ /:/ |::::\__\ /:/\:\ \:\__\
+\:\~\:\/:/  / /\/:/  /    \:\  \ /:/  / \/__/~~/:/  / \:\~\:\ \/__/
+\:\ \::/  /  \::/__/      \:\  /:/  /        /:/  /   \:\ \:\__\
+\:\/:/  /    \:\__\       \:\/:/  /        /:/  /     \:\ \/__/
+ \::/__/      \/__/        \::/  /        /:/  /       \:\__\
+	~~                        \/__/         \/__/         \/__/
+
diff --git a/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap b/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap new file mode 100644 index 000000000000..03b6e5a24b53 --- /dev/null +++ b/crates/biome_html_formatter/tests/specs/html/elements/pre.html.snap @@ -0,0 +1,52 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: elements/pre.html +--- +# Input + +```html +
+	___                       ___           ___           ___
+	/\  \          ___        /\  \         /\__\         /\  \
+ /::\  \        /\  \      /::\  \       /::|  |       /::\  \
+/:/\:\  \       \:\  \    /:/\:\  \     /:|:|  |      /:/\:\  \
+/::\~\:\__\      /::\__\  /:/  \:\  \   /:/|:|__|__   /::\~\:\  \
+/:/\:\ \:|__|  __/:/\/__/ /:/__/ \:\__\ /:/ |::::\__\ /:/\:\ \:\__\
+\:\~\:\/:/  / /\/:/  /    \:\  \ /:/  / \/__/~~/:/  / \:\~\:\ \/__/
+\:\ \::/  /  \::/__/      \:\  /:/  /        /:/  /   \:\ \:\__\
+\:\/:/  /    \:\__\       \:\/:/  /        /:/  /     \:\ \/__/
+ \::/__/      \/__/        \::/  /        /:/  /       \:\__\
+	~~                        \/__/         \/__/         \/__/
+
+ +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Attribute Position: Auto +----- + +```html +
___                       ___           ___           ___
+	/\  \          ___        /\  \         /\__\         /\  \
+ /::\  \        /\  \      /::\  \       /::|  |       /::\  \
+/:/\:\  \       \:\  \    /:/\:\  \     /:|:|  |      /:/\:\  \
+/::\~\:\__\      /::\__\  /:/  \:\  \   /:/|:|__|__   /::\~\:\  \
+/:/\:\ \:|__|  __/:/\/__/ /:/__/ \:\__\ /:/ |::::\__\ /:/\:\ \:\__\
+\:\~\:\/:/  / /\/:/  /    \:\  \ /:/  / \/__/~~/:/  / \:\~\:\ \/__/
+\:\ \::/  /  \::/__/      \:\  /:/  /        /:/  /   \:\ \:\__\
+\:\/:/  /    \:\__\       \:\/:/  /        /:/  /     \:\ \/__/
+ \::/__/      \/__/        \::/  /        /:/  /       \:\__\
+	~~                        \/__/         \/__/         \/__/
+
+```