Skip to content

feat: add check for localization keys between package.json and package.nls.json#1222

Closed
joaomoreno wants to merge 1 commit intomainfrom
joao/jade-squirrel
Closed

feat: add check for localization keys between package.json and package.nls.json#1222
joaomoreno wants to merge 1 commit intomainfrom
joao/jade-squirrel

Conversation

@joaomoreno
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings October 2, 2025 13:15
@joaomoreno joaomoreno self-assigned this Oct 2, 2025
@joaomoreno joaomoreno enabled auto-merge October 2, 2025 13:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a validation tool to ensure localization consistency between package.json and package.nls.json files. The tool checks that all localization keys referenced in package.json (using the %key% pattern) have corresponding entries in the package.nls.json file.

  • Creates a TypeScript script that recursively scans package.json for localization key references
  • Validates that all referenced keys exist in package.nls.json
  • Integrates the validation check into CI/CD pipelines to catch localization issues early

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
script/checkPackageNls.ts New validation script that finds localization keys in package.json and verifies they exist in package.nls.json
package.json Adds npm script "check-package-nls" to run the validation tool
build/release.yml Integrates the localization check into the release build pipeline
build/pre-release.yml Integrates the localization check into the pre-release build pipeline
.github/workflows/pr.yml Adds the localization check to both PR validation jobs

/**
* Recursively finds all strings matching the pattern %key% in a JSON object
*/
function findLocalizationKeys(obj: any, keys: Set<string> = new Set()): Set<string> {
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type reduces type safety. Consider using a more specific type like unknown or a union type for better type checking.

Suggested change
function findLocalizationKeys(obj: any, keys: Set<string> = new Set()): Set<string> {
function findLocalizationKeys(obj: unknown, keys: Set<string> = new Set()): Set<string> {

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +45
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonContent);

// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for file read operations. If either file doesn't exist or can't be read, the script will crash with an unhelpful error message.

Suggested change
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonContent);
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
let packageJson;
try {
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
packageJson = JSON.parse(packageJsonContent);
} catch (err) {
console.error(`Failed to read or parse package.json: ${err.message}`);
process.exit(1);
}
// Read package.nls.json
let packageNls;
try {
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
packageNls = JSON.parse(packageNlsContent);
} catch (err) {
console.error(`Failed to read or parse package.nls.json: ${err.message}`);
process.exit(1);
}

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +44
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonContent);

// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for file read operations. If either file doesn't exist or can't be read, the script will crash with an unhelpful error message.

Suggested change
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonContent);
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
let packageJsonContent: string;
try {
packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
} catch (err: any) {
console.error(`❌ ERROR: Failed to read ${packageJsonPath}: ${err.message}`);
process.exit(1);
}
const packageJson = JSON.parse(packageJsonContent);
// Read package.nls.json
let packageNlsContent: string;
try {
packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
} catch (err: any) {
console.error(`❌ ERROR: Failed to read ${packageNlsPath}: ${err.message}`);
process.exit(1);
}

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +45
const packageJson = JSON.parse(packageJsonContent);

// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for JSON parsing. If either file contains invalid JSON, the script will crash with an unhelpful error message.

Suggested change
const packageJson = JSON.parse(packageJsonContent);
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
let packageJson;
try {
packageJson = JSON.parse(packageJsonContent);
} catch (err) {
console.error(`❌ ERROR: Failed to parse package.json as valid JSON.`);
console.error(err instanceof Error ? err.message : err);
process.exit(1);
}
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
let packageNls;
try {
packageNls = JSON.parse(packageNlsContent);
} catch (err) {
console.error(`❌ ERROR: Failed to parse package.nls.json as valid JSON.`);
console.error(err instanceof Error ? err.message : err);
process.exit(1);
}

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +45
const packageJson = JSON.parse(packageJsonContent);

// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for JSON parsing. If either file contains invalid JSON, the script will crash with an unhelpful error message.

Suggested change
const packageJson = JSON.parse(packageJsonContent);
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
const packageNls = JSON.parse(packageNlsContent);
let packageJson;
try {
packageJson = JSON.parse(packageJsonContent);
} catch (err) {
console.error(`❌ ERROR: Failed to parse ${packageJsonPath}:`, err.message);
process.exit(1);
}
// Read package.nls.json
const packageNlsContent = await fs.promises.readFile(packageNlsPath, 'utf-8');
let packageNls;
try {
packageNls = JSON.parse(packageNlsContent);
} catch (err) {
console.error(`❌ ERROR: Failed to parse ${packageNlsPath}:`, err.message);
process.exit(1);
}

Copilot uses AI. Check for mistakes.
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Oct 2, 2025
@joaomoreno joaomoreno closed this Oct 2, 2025
auto-merge was automatically disabled October 2, 2025 13:18

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant