diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index 26edbb839bb..a5a09ef4432 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -13,6 +13,8 @@ All changes included in 1.7: ## YAML validation - ([#11654](https://github.com/quarto-dev/quarto-cli/issues/11654)): Allow `page-inset` as value in `column` key for code cells. +- ([#12151](https://github.com/quarto-dev/quarto-cli/issues/12151)): Fix YAML validation in computations cell on Windows. +- ([#12151](https://github.com/quarto-dev/quarto-cli/pull/12151)): Basic YAML validation is now active in cell for document using Julia engine. ## Website projects @@ -72,6 +74,7 @@ All changes included in 1.7: - ([#11659](https://github.com/quarto-dev/quarto-cli/pull/11659)): Fix escaping bug where paths containing spaces or backslashes break server startup on Windows. - ([#12121](https://github.com/quarto-dev/quarto-cli/pull/12121)): Update QuartoNotebookRunner to 0.13.1. Support for evaluating Python cells via [PythonCall.jl](https://github.com/JuliaPy/PythonCall.jl) added. +- ([#12151](https://github.com/quarto-dev/quarto-cli/pull/12151)): Basic YAML validation is now active for document using Julia engine. ## Other Fixes and Improvements diff --git a/src/core/lib/yaml-schema/chunk-metadata.ts b/src/core/lib/yaml-schema/chunk-metadata.ts index c89b3058549..689e3bc65d3 100644 --- a/src/core/lib/yaml-schema/chunk-metadata.ts +++ b/src/core/lib/yaml-schema/chunk-metadata.ts @@ -132,6 +132,16 @@ const jupyterEngineSchema = defineCached( }, "engine-jupyter", ); +const juliaEnginesSchema = defineCached( + // deno-lint-ignore require-await + async () => { + return { + schema: makeEngineSchema("julia"), + errorHandlers: [], + }; + }, + "engine-julia", +); export async function getEngineOptionsSchema(): Promise< Record @@ -140,6 +150,7 @@ export async function getEngineOptionsSchema(): Promise< markdown: await markdownEngineSchema(), knitr: await knitrEngineSchema(), jupyter: await jupyterEngineSchema(), + julia: await juliaEnginesSchema(), }; return obj; diff --git a/src/core/schema/validate-document.ts b/src/core/schema/validate-document.ts index 84953156f15..42e2276ff9f 100644 --- a/src/core/schema/validate-document.ts +++ b/src/core/schema/validate-document.ts @@ -97,11 +97,11 @@ export async function validateDocumentFromSource( } else { firstContentCellIndex = 0; } - for (const cell of nb.cells.slice(firstContentCellIndex)) { if ( cell.cell_type === "markdown" || - cell.cell_type === "raw" + cell.cell_type === "raw" || + cell.cell_type?.language === "_directive" ) { // not a language chunk continue; @@ -110,21 +110,19 @@ export async function validateDocumentFromSource( const lang = cell.cell_type.language; try { - const fullCell = mappedString(cell.sourceVerbatim, [{ - start: lang.length + 6, - end: cell.sourceVerbatim.value.length - 3, - }]); - await partitionCellOptionsMapped( - lang, - fullCell, - true, - engine, - ); + if (cell.sourceWithYaml) { + await partitionCellOptionsMapped( + lang, + cell.sourceWithYaml, + true, + engine, + ); + } } catch (e) { if (e instanceof ValidationError) { error("Validation of YAML cell metadata failed."); for (const err of e.validationErrors) { - console.log(tidyverseFormatError(err.niceError)); + error(tidyverseFormatError(err.niceError), { colorize: false }); } result.push(...e.validationErrors); } else { diff --git a/tests/docs/yaml/fail-validation-julia-backticks.qmd b/tests/docs/yaml/fail-validation-julia-backticks.qmd new file mode 100644 index 00000000000..039e149b27e --- /dev/null +++ b/tests/docs/yaml/fail-validation-julia-backticks.qmd @@ -0,0 +1,11 @@ +--- +title: "YAML intelligence should fail with knitr engine" +engine: julia +--- + +This code cell has more than default 3 backticks + +````{julia} +#| echo: 123 +1 + 1 +```` diff --git a/tests/docs/yaml/fail-validation-julia.qmd b/tests/docs/yaml/fail-validation-julia.qmd new file mode 100644 index 00000000000..b379b2ffa90 --- /dev/null +++ b/tests/docs/yaml/fail-validation-julia.qmd @@ -0,0 +1,9 @@ +--- +title: "YAML intelligence should fail with knitr engine" +engine: julia +--- + +```{julia} +#| echo: 123 +1 + 1 +``` diff --git a/tests/docs/yaml/fail-validation-jupyter-backticks.qmd b/tests/docs/yaml/fail-validation-jupyter-backticks.qmd new file mode 100644 index 00000000000..9ca84d5cb75 --- /dev/null +++ b/tests/docs/yaml/fail-validation-jupyter-backticks.qmd @@ -0,0 +1,10 @@ +--- +title: "YAML intelligence should fail with knitr engine" +--- + +This code cell has more than default 3 backticks + +````{python} +#| echo: 123 +1 + 1 +```` \ No newline at end of file diff --git a/tests/docs/yaml/fail-validation-jupyter.qmd b/tests/docs/yaml/fail-validation-jupyter.qmd new file mode 100644 index 00000000000..917ba63fccf --- /dev/null +++ b/tests/docs/yaml/fail-validation-jupyter.qmd @@ -0,0 +1,8 @@ +--- +title: "YAML intelligence should fail with knitr engine" +--- + +```{python} +#| echo: 123 +1 + 1 +``` diff --git a/tests/docs/yaml/fail-validation-knitr-backticks.qmd b/tests/docs/yaml/fail-validation-knitr-backticks.qmd new file mode 100644 index 00000000000..81186fbfcec --- /dev/null +++ b/tests/docs/yaml/fail-validation-knitr-backticks.qmd @@ -0,0 +1,10 @@ +--- +title: "YAML intelligence should fail with knitr engine" +--- + +This code cell has more than default 3 backticks + +````{r} +#| echo: 123 +1 + 1 +```` \ No newline at end of file diff --git a/tests/docs/yaml/fail-validation-knitr.qmd b/tests/docs/yaml/fail-validation-knitr.qmd new file mode 100644 index 00000000000..50473685a4d --- /dev/null +++ b/tests/docs/yaml/fail-validation-knitr.qmd @@ -0,0 +1,8 @@ +--- +title: "YAML intelligence should fail with knitr engine" +--- + +```{r} +#| echo: 123 +1 + 1 +``` diff --git a/tests/smoke/yaml-intelligence/yaml-intelligence-code-cell-options.test.ts b/tests/smoke/yaml-intelligence/yaml-intelligence-code-cell-options.test.ts new file mode 100644 index 00000000000..c2dcea97dc3 --- /dev/null +++ b/tests/smoke/yaml-intelligence/yaml-intelligence-code-cell-options.test.ts @@ -0,0 +1,25 @@ +import { testQuartoCmd } from "../../test.ts"; +import { fileLoader } from "../../utils.ts"; +import { printsMessage } from "../../verify.ts"; + +const yamlDocs = fileLoader("yaml"); + +const testYamlValidationFails = (file: string) => { + testQuartoCmd( + "render", + [yamlDocs(file, "html").input, "--to", "html", "--quiet"], + [printsMessage("ERROR", /Validation of YAML cell metadata failed/)], + ); +}; + +const files = [ + "fail-validation-knitr.qmd", + "fail-validation-knitr-backticks.qmd", + "fail-validation-jupyter.qmd", + "fail-validation-jupyter-backticks.qmd", + "fail-validation-julia.qmd", + "fail-validation-julia-backticks.qmd", +]; + +files.forEach(testYamlValidationFails); +