fix: null-safe package.json access in getRepoChecks

Review follow-up (CodeRabbit + cubic): switching to safeParseJson at line
389 means packageJson can be null on a missing/malformed package.json, but
the quality-ci-validations check dereferenced packageJson.scripts before the
optional chaining could help — throwing TypeError instead of degrading.
Guard the base object with packageJson?.scripts?.test at the access site,
matching the file's existing convention (e.g. line 220 uses packageJson?.name).

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
Chris Yau
2026-05-29 11:10:34 +08:00
committed by Affaan Mustafa
parent d82a37444a
commit 8dc02218db

View File

@@ -312,7 +312,7 @@ function getRepoChecks(rootDir) {
scopes: ['repo'],
path: 'package.json',
description: 'Test script runs validator chain before tests',
pass: typeof packageJson.scripts?.test === 'string' && packageJson.scripts.test.includes('validate-commands.js') && packageJson.scripts.test.includes('tests/run-all.js'),
pass: typeof packageJson?.scripts?.test === 'string' && packageJson?.scripts?.test.includes('validate-commands.js') && packageJson?.scripts?.test.includes('tests/run-all.js'),
fix: 'Update package.json test script to run validators plus tests/run-all.js.',
},
{