Skip to content

Commit b9b9466

Browse files
authored
fix(#449): fix empty string serialization in yaml (#452)
1 parent 5594f4c commit b9b9466

5 files changed

Lines changed: 512 additions & 30 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"github.vscode-pull-request-github",
3030
"github.vscode-github-actions",
3131
"golang.go",
32+
"firsttris.vscode-jest-runner",
3233
"waderyan.gitblame"
3334
]
3435
}

src/app/lib/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import linter from "../linter";
1+
import { useEffect, useState } from "react";
22
import YAML from "yaml";
33
import PublicCode from "../contents/publiccode";
4-
import { useEffect } from "react";
5-
import { useState } from "react";
4+
import linter from "../linter";
65

76
export function parseYaml(yaml: string): PublicCode | null {
87
return yaml ? (YAML.parse(yaml) as PublicCode) : null;
Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import {
22
clone,
33
cloneDeep,
4-
isArray,
5-
isEmpty,
64
isEqual,
7-
isObjectLike,
8-
isUndefined,
9-
mapValues,
5+
mapValues
106
} from "lodash";
11-
127
import PublicCode, {
138
Description,
149
Italy,
@@ -20,7 +15,8 @@ import PublicCode, {
2015
defaultItaly,
2116
defaultPiattaforme,
2217
defaultRiuso,
23-
} from "./contents/publiccode";
18+
} from "../contents/publiccode";
19+
import { removeEmpty } from "./remove-empty";
2420

2521
function sortDescription({
2622
genericName,
@@ -104,8 +100,8 @@ export default function linter({
104100
},
105101
dependsOn: dependsOn
106102
? mapValues(dependsOn, (v) =>
107-
v ? v.map((d) => sortAs(defaultDependency, d)) : undefined
108-
)
103+
v ? v.map((d) => sortAs(defaultDependency, d)) : undefined
104+
)
109105
: undefined,
110106
it:
111107
it === undefined || isEqual(removeEmpty(it), defaultItaly)
@@ -116,24 +112,6 @@ export default function linter({
116112
return removeEmpty(sortedPC);
117113
}
118114

119-
function removeEmpty<T>(obj: T): T {
120-
if (typeof obj !== "object") return obj;
121-
122-
const ret = obj;
123-
124-
for (const key in ret) {
125-
const val = removeEmpty(ret[key]);
126-
if (
127-
((isArray(val) || isObjectLike(val)) && isEmpty(val)) ||
128-
isUndefined(val)
129-
) {
130-
delete ret[key];
131-
}
132-
}
133-
134-
return ret;
135-
}
136-
137115
function lintItaly({
138116
countryExtensionVersion,
139117
conforme,

0 commit comments

Comments
 (0)