mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-05 22:24:41 +00:00
Merge pull request #21946 from is-a-dev/wdhdev-patch-1
chore(ci): fix duplicate keys test
This commit is contained in:
+20
-10
@@ -36,20 +36,30 @@ const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath);
|
||||
|
||||
function findDuplicateKeys(jsonString) {
|
||||
const keyPattern = /"([^"]+)"(?=\s*:)/g;
|
||||
const keys = [];
|
||||
let match;
|
||||
const duplicateKeys = [];
|
||||
|
||||
while ((match = keyPattern.exec(jsonString)) !== null) {
|
||||
keys.push(match[1]);
|
||||
}
|
||||
const stack = [];
|
||||
|
||||
const keyCount = {};
|
||||
keys.forEach((key) => {
|
||||
keyCount[key] = (keyCount[key] || 0) + 1;
|
||||
const obj = JSON.parse(jsonString, (key, value) => {
|
||||
if (typeof key === "string") {
|
||||
const current = stack[stack.length - 1];
|
||||
if (current) {
|
||||
if (current[key]) {
|
||||
duplicateKeys.push(key);
|
||||
} else {
|
||||
current[key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof value === "object" && value !== null) {
|
||||
stack.push({});
|
||||
}
|
||||
|
||||
return value;
|
||||
});
|
||||
|
||||
return Object.keys(keyCount).filter((key) => keyCount[key] > 1);
|
||||
return [...new Set(duplicateKeys)];
|
||||
}
|
||||
|
||||
async function validateFields(t, obj, fields, file, prefix = "") {
|
||||
|
||||
Reference in New Issue
Block a user