diff --git a/src/app/components/Editor.tsx b/src/app/components/Editor.tsx index 812448e..f2f4425 100644 --- a/src/app/components/Editor.tsx +++ b/src/app/components/Editor.tsx @@ -29,6 +29,7 @@ import YAML from "yaml"; import { Col, Container, Row } from "design-react-kit"; import EditorContacts from "./EditorContacts"; import EditorContractors from "./EditorContractors"; +import linter from "../linter"; const resolver: Resolver = async (values) => { const res = await validator(JSON.stringify(values), "main"); @@ -241,7 +242,7 @@ export default function Editor() { /> setYamlModalVisibility(!isYamlModalVisible)} /> diff --git a/src/app/linter.ts b/src/app/linter.ts new file mode 100644 index 0000000..0ddd53c --- /dev/null +++ b/src/app/linter.ts @@ -0,0 +1,24 @@ +import { cloneDeep, isArray, isEmpty, isObjectLike, isUndefined } from "lodash"; +import PublicCode from "./contents/publiccode"; + +export default function linter(pc: PublicCode): PublicCode { + return removeEmpty(cloneDeep(pc)); +} + +function removeEmpty(obj: T): T { + if (typeof obj !== "object") return obj; + + const ret = obj; + + for (const key in ret) { + const val = removeEmpty(ret[key]); + if ( + ((isArray(val) || isObjectLike(val)) && isEmpty(val)) || + isUndefined(val) + ) { + delete ret[key]; + } + } + + return ret; +}