-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/quark-bot-discord/languages
- Loading branch information
Showing
4 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const directory = process.argv[2]; // Take directory as an input argument | ||
|
||
let foundErrors = false; | ||
|
||
try { | ||
const files = fs.readdirSync(directory); | ||
|
||
if (files.length === 0) { | ||
console.log("No JSON files found in the directory."); | ||
process.exit(0); | ||
} | ||
|
||
console.log(`Found ${files.length} files in the directory.`); | ||
|
||
files.forEach(file => { | ||
if (!file.endsWith('.json')) { | ||
console.log(`Skipping non-JSON file: ${file}`); | ||
return; | ||
} | ||
|
||
const filePath = path.join(directory, file); | ||
try { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const jsonData = JSON.parse(data); | ||
|
||
console.log(`Processing ${file}...`); | ||
|
||
function checkFields(obj, path = '') { | ||
Object.keys(obj).forEach(key => { | ||
const value = obj[key]; | ||
const currentPath = path ? `${path}.${key}` : key; | ||
|
||
if (typeof value === 'string') { | ||
if (path.endsWith('.description') && value.length > 100) { | ||
console.error(`${file}: Description exceeds 100 characters at '${currentPath}'`); | ||
foundErrors = true; | ||
} | ||
if (path.endsWith('.name') && value.includes(' ')) { | ||
console.error(`${file}: Name contains space at '${currentPath}'`); | ||
foundErrors = true; | ||
} | ||
} else if (typeof value === 'object' && value !== null) { | ||
checkFields(value, currentPath); | ||
} | ||
}); | ||
} | ||
|
||
checkFields(jsonData); | ||
|
||
} catch (err) { | ||
console.error(`Error processing ${file}:`, err); | ||
foundErrors = true; | ||
} | ||
}); | ||
} catch (err) { | ||
console.error("Error reading the directory:", err); | ||
process.exit(1); | ||
} | ||
|
||
if (foundErrors) { | ||
console.error("Validation errors found in the files. Please check the logs above."); | ||
process.exit(1); | ||
} else { | ||
console.log("All files validated successfully."); | ||
process.exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
directory=$1 | ||
|
||
valid=true | ||
|
||
for file in "$directory"/*.json; do | ||
echo "Validating $file" | ||
|
||
# Validate 'name' fields: No spaces allowed | ||
name_issues=$(jq -r 'recurse | objects | .name? | select(.) | with_entries(select(.value | test(" "))) | keys[] as $keys | $keys[] | "\($keys) at line \(input_line_number)"' "$file") | ||
if [ ! -z "$name_issues" ]; then | ||
echo "Validation failed in $file for 'name' field(s) with spaces:" | ||
echo "$name_issues" | ||
valid=false | ||
fi | ||
|
||
description_issues=$(jq -r 'recurse | objects | .description? | select(.) | to_entries[] | select(.value | type == "string" and length > 100) | "\(.key) at line \(input_line_number)"' "$file") | ||
if [ ! -z "$description_issues" ]; then | ||
echo "Validation failed in $file for 'description' field(s) exceeding 100 characters:" | ||
echo "$description_issues" | ||
valid=false | ||
fi | ||
|
||
if [ -z "$name_issues" ] && [ -z "$description_issues" ]; then | ||
echo "$file validated successfully." | ||
fi | ||
done | ||
|
||
if [ "$valid" = false ]; then | ||
echo "Validation errors found in some JSON files." | ||
exit 1 | ||
else | ||
echo "All JSON files validated successfully." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.