-
-
Notifications
You must be signed in to change notification settings - Fork 968
feat(markdown): add prettier tests for markdown formatter #9076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cda36e1
Implement TestFormatLanguage for Markdown
0108404
Add snapshots
6e74776
biome configuration for markdown
765bd14
Clean up
tidefield 51fddbe
[autofix.ci] apply automated fixes
autofix-ci[bot] a1e826b
Update crates/biome_markdown_formatter/src/context.rs
tidefield 7861a42
Fix compile errors after rebase
tidefield 7168fe7
Clippy fix
tidefield 0113456
Update crates/biome_configuration/src/markdown.rs
tidefield 22f0f37
Update crates/biome_configuration/src/markdown.rs
tidefield 03f5a02
Update crates/biome_configuration/src/lib.rs
tidefield a3dcc96
Compile error fix
tidefield f699143
Fix deadcode warning
tidefield 6bfb4b2
Clippy fix
tidefield 7a3929f
Remove unused code
tidefield df62e73
Unlist markdown configuration
tidefield 7f71eb4
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| use crate::bool::Bool; | ||
| use biome_deserialize_macros::{Deserializable, Merge}; | ||
| use biome_formatter::{IndentStyle, IndentWidth, LineWidth}; | ||
| use bpaf::Bpaf; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Options applied to Markdown files | ||
| #[derive( | ||
| Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, Bpaf, Deserializable, Merge, | ||
| )] | ||
| #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] | ||
| #[serde(rename_all = "camelCase", default, deny_unknown_fields)] | ||
| pub struct MarkdownConfiguration { | ||
| #[bpaf(external(markdown_formatter_configuration), optional)] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub formatter: Option<MarkdownFormatterConfiguration>, | ||
| } | ||
|
|
||
| pub type MarkdownFormatterEnabled = Bool<false>; // Keep it disabled by default while experimental. | ||
| pub type MarkdownLinterEnabled = Bool<true>; | ||
| pub type MarkdownAssistEnabled = Bool<true>; | ||
| pub type MarkdownParseInterpolation = Bool<false>; | ||
|
|
||
| /// Options that change how the Markdown formatter behaves | ||
| #[derive( | ||
| Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, Bpaf, Deserializable, Merge, | ||
| )] | ||
| #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] | ||
| #[serde(rename_all = "camelCase", default, deny_unknown_fields)] | ||
| pub struct MarkdownFormatterConfiguration { | ||
| /// Control the formatter for Markdown (and its super languages) files. | ||
| #[bpaf(long("markdown-formatter-enabled"), argument("true|false"), optional)] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub enabled: Option<MarkdownFormatterEnabled>, | ||
|
|
||
| /// The indent style applied to Markdown files. | ||
| #[bpaf( | ||
| long("markdown-formatter-indent-style"), | ||
| argument("tab|space"), | ||
| optional | ||
| )] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub indent_style: Option<IndentStyle>, | ||
|
|
||
| /// The size of the indentation applied to Markdown files. Defaults to 2. | ||
| #[bpaf(long("markdown-formatter-indent-width"), argument("NUMBER"), optional)] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub indent_width: Option<IndentWidth>, | ||
|
|
||
| /// What's the max width of a line applied to Markdown files. Defaults to 80. | ||
| #[bpaf(long("markdown-formatter-line-width"), argument("NUMBER"), optional)] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub line_width: Option<LineWidth>, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| use biome_formatter_test::TestFormatLanguage; | ||
| use biome_fs::BiomePath; | ||
| use biome_markdown_formatter::{MarkdownFormatLanguage, context::MarkdownFormatContext}; | ||
| use biome_markdown_parser::parse_markdown; | ||
| use biome_markdown_syntax::MarkdownLanguage; | ||
| use biome_parser::AnyParse; | ||
| use biome_service::{ | ||
| settings::{ServiceLanguage, Settings}, | ||
| workspace::DocumentFileSource, | ||
| }; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct MarkdownTestFormatLanguage {} | ||
|
|
||
| impl TestFormatLanguage for MarkdownTestFormatLanguage { | ||
| type ServiceLanguage = MarkdownLanguage; | ||
| type Context = MarkdownFormatContext; | ||
| type FormatLanguage = MarkdownFormatLanguage; | ||
|
|
||
| fn parse(&self, text: &str) -> AnyParse { | ||
| parse_markdown(text).into() | ||
| } | ||
|
|
||
| fn to_format_language( | ||
| &self, | ||
| settings: &Settings, | ||
| file_source: &DocumentFileSource, | ||
| ) -> Self::FormatLanguage { | ||
| let language_settings = &settings.languages.markdown.formatter; | ||
| let options = Self::ServiceLanguage::resolve_format_options( | ||
| &settings.formatter, | ||
| &settings.override_settings, | ||
| language_settings, | ||
| &BiomePath::new(""), | ||
| file_source, | ||
| ); | ||
| MarkdownFormatLanguage::new(options) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| use biome_formatter::{IndentStyle, IndentWidth}; | ||
| use biome_formatter_test::test_prettier_snapshot::{PrettierSnapshot, PrettierTestFile}; | ||
| use biome_markdown_formatter::{MarkdownFormatLanguage, context::MarkdownFormatOptions}; | ||
| use camino::Utf8Path; | ||
| use std::env; | ||
|
|
||
| mod language { | ||
| include!("language.rs"); | ||
| } | ||
|
|
||
| tests_macros::gen_tests! {"tests/specs/prettier/markdown/**/*.{md}", crate::test_snapshot, ""} | ||
|
|
||
| fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) { | ||
| countme::enable(true); | ||
|
|
||
| let root_path = Utf8Path::new(concat!( | ||
| env!("CARGO_MANIFEST_DIR"), | ||
| "/tests/specs/prettier/" | ||
| )); | ||
|
|
||
| let test_file = PrettierTestFile::new(input, root_path); | ||
| let options = MarkdownFormatOptions::default() | ||
| .with_indent_style(IndentStyle::Space) | ||
| .with_indent_width(IndentWidth::default()); | ||
| let language = language::MarkdownTestFormatLanguage::default(); | ||
| let snapshot = PrettierSnapshot::new(test_file, language, MarkdownFormatLanguage::new(options)); | ||
|
|
||
| snapshot.test() | ||
| } |
98 changes: 98 additions & 0 deletions
98
crates/biome_markdown_formatter/tests/specs/prettier/markdown/blockquote/code.md.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
| info: markdown/blockquote/code.md | ||
| --- | ||
| # Input | ||
|
|
||
| ```md | ||
| > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| >```json | ||
| >{ | ||
| > "extends": [ | ||
| > "unobtrusive", | ||
| > "unobtrusive/import", | ||
| > "unobtrusive/react", | ||
| > "unobtrusive/flowtype" | ||
| > ], | ||
| > "env": { | ||
| > "browser": true | ||
| > } | ||
| >} | ||
| >``` | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| # Prettier differences | ||
|
|
||
| ```diff | ||
| --- Prettier | ||
| +++ Biome | ||
| @@ -1,7 +1,6 @@ | ||
| > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| -> | ||
| -> ```json | ||
| -> { | ||
| +>```json | ||
| +>{ | ||
| > "extends": [ | ||
| > "unobtrusive", | ||
| > "unobtrusive/import", | ||
| @@ -11,5 +10,5 @@ | ||
| > "env": { | ||
| > "browser": true | ||
| > } | ||
| -> } | ||
| -> ``` | ||
| +>} | ||
| +>``` | ||
| ``` | ||
|
|
||
| # Output | ||
|
|
||
| ```md | ||
| > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| >```json | ||
| >{ | ||
| > "extends": [ | ||
| > "unobtrusive", | ||
| > "unobtrusive/import", | ||
| > "unobtrusive/react", | ||
| > "unobtrusive/flowtype" | ||
| > ], | ||
| > "env": { | ||
| > "browser": true | ||
| > } | ||
| >} | ||
| >``` | ||
| ``` | ||
|
|
||
| # Errors | ||
| ``` | ||
| code.md:2:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| × Unterminated fenced code block, expected closing triple backticks (```). | ||
|
|
||
| 1 │ > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| > 2 │ >```json | ||
| │ ^^^ | ||
| 3 │ >{ | ||
| 4 │ > "extends": [ | ||
|
|
||
| i code block started here | ||
|
|
||
| 1 │ > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| > 2 │ >```json | ||
| │ ^^^ | ||
| 3 │ >{ | ||
| 4 │ > "extends": [ | ||
|
|
||
| i Add closing triple backticks (```) at the start of a new line. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| # Lines exceeding max width of 80 characters | ||
| ``` | ||
| 1: > NOTE: To use `unobtrusive`, `unobtrusive/import`, `unobtrusive/react`, and `unobtrusive/flowtype` together, your eslint config would look like this: | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.