Skip to content

Commit cdb794f

Browse files
authored
Merge pull request #12151 from quarto-dev/fix/windows/yaml-validation
2 parents e8eefd9 + 2b4c504 commit cdb794f

10 files changed

+106
-13
lines changed

news/changelog-1.7.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ All changes included in 1.7:
1313
## YAML validation
1414

1515
- ([#11654](https://github.com/quarto-dev/quarto-cli/issues/11654)): Allow `page-inset` as value in `column` key for code cells.
16+
- ([#12151](https://github.com/quarto-dev/quarto-cli/issues/12151)): Fix YAML validation in computations cell on Windows.
17+
- ([#12151](https://github.com/quarto-dev/quarto-cli/pull/12151)): Basic YAML validation is now active in cell for document using Julia engine.
1618

1719
## Website projects
1820

@@ -72,6 +74,7 @@ All changes included in 1.7:
7274

7375
- ([#11659](https://github.com/quarto-dev/quarto-cli/pull/11659)): Fix escaping bug where paths containing spaces or backslashes break server startup on Windows.
7476
- ([#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.
77+
- ([#12151](https://github.com/quarto-dev/quarto-cli/pull/12151)): Basic YAML validation is now active for document using Julia engine.
7578

7679
## Other Fixes and Improvements
7780

src/core/lib/yaml-schema/chunk-metadata.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ const jupyterEngineSchema = defineCached(
132132
},
133133
"engine-jupyter",
134134
);
135+
const juliaEnginesSchema = defineCached(
136+
// deno-lint-ignore require-await
137+
async () => {
138+
return {
139+
schema: makeEngineSchema("julia"),
140+
errorHandlers: [],
141+
};
142+
},
143+
"engine-julia",
144+
);
135145

136146
export async function getEngineOptionsSchema(): Promise<
137147
Record<string, ConcreteSchema>
@@ -140,6 +150,7 @@ export async function getEngineOptionsSchema(): Promise<
140150
markdown: await markdownEngineSchema(),
141151
knitr: await knitrEngineSchema(),
142152
jupyter: await jupyterEngineSchema(),
153+
julia: await juliaEnginesSchema(),
143154
};
144155

145156
return obj;

src/core/schema/validate-document.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ export async function validateDocumentFromSource(
9797
} else {
9898
firstContentCellIndex = 0;
9999
}
100-
101100
for (const cell of nb.cells.slice(firstContentCellIndex)) {
102101
if (
103102
cell.cell_type === "markdown" ||
104-
cell.cell_type === "raw"
103+
cell.cell_type === "raw" ||
104+
cell.cell_type?.language === "_directive"
105105
) {
106106
// not a language chunk
107107
continue;
@@ -110,21 +110,19 @@ export async function validateDocumentFromSource(
110110
const lang = cell.cell_type.language;
111111

112112
try {
113-
const fullCell = mappedString(cell.sourceVerbatim, [{
114-
start: lang.length + 6,
115-
end: cell.sourceVerbatim.value.length - 3,
116-
}]);
117-
await partitionCellOptionsMapped(
118-
lang,
119-
fullCell,
120-
true,
121-
engine,
122-
);
113+
if (cell.sourceWithYaml) {
114+
await partitionCellOptionsMapped(
115+
lang,
116+
cell.sourceWithYaml,
117+
true,
118+
engine,
119+
);
120+
}
123121
} catch (e) {
124122
if (e instanceof ValidationError) {
125123
error("Validation of YAML cell metadata failed.");
126124
for (const err of e.validationErrors) {
127-
console.log(tidyverseFormatError(err.niceError));
125+
error(tidyverseFormatError(err.niceError), { colorize: false });
128126
}
129127
result.push(...e.validationErrors);
130128
} else {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
engine: julia
4+
---
5+
6+
This code cell has more than default 3 backticks
7+
8+
````{julia}
9+
#| echo: 123
10+
1 + 1
11+
````
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
engine: julia
4+
---
5+
6+
```{julia}
7+
#| echo: 123
8+
1 + 1
9+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
---
4+
5+
This code cell has more than default 3 backticks
6+
7+
````{python}
8+
#| echo: 123
9+
1 + 1
10+
````
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
---
4+
5+
```{python}
6+
#| echo: 123
7+
1 + 1
8+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
---
4+
5+
This code cell has more than default 3 backticks
6+
7+
````{r}
8+
#| echo: 123
9+
1 + 1
10+
````
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "YAML intelligence should fail with knitr engine"
3+
---
4+
5+
```{r}
6+
#| echo: 123
7+
1 + 1
8+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { testQuartoCmd } from "../../test.ts";
2+
import { fileLoader } from "../../utils.ts";
3+
import { printsMessage } from "../../verify.ts";
4+
5+
const yamlDocs = fileLoader("yaml");
6+
7+
const testYamlValidationFails = (file: string) => {
8+
testQuartoCmd(
9+
"render",
10+
[yamlDocs(file, "html").input, "--to", "html", "--quiet"],
11+
[printsMessage("ERROR", /Validation of YAML cell metadata failed/)],
12+
);
13+
};
14+
15+
const files = [
16+
"fail-validation-knitr.qmd",
17+
"fail-validation-knitr-backticks.qmd",
18+
"fail-validation-jupyter.qmd",
19+
"fail-validation-jupyter-backticks.qmd",
20+
"fail-validation-julia.qmd",
21+
"fail-validation-julia-backticks.qmd",
22+
];
23+
24+
files.forEach(testYamlValidationFails);
25+

0 commit comments

Comments
 (0)