Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 3, 2025

Arguments to the jsii targets array that did not make sense in the target language were not being validated, leading to confusing compile-time errors.

Add validation for a bunch of these.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Arguments to the jsii `targets` array that did not make sense in the
target language were not being validated, leading to confusing
compile-time errors.

Add validation for a bunch of these.
@rix0rrr rix0rrr requested review from a team November 3, 2025 12:40
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit 08a499a Nov 3, 2025
83 checks passed
@aws-cdk-automation aws-cdk-automation deleted the huijbers/detect-go-misconfig branch November 3, 2025 14:01
aws-cdk-automation pushed a commit that referenced this pull request Nov 3, 2025
Arguments to the jsii `targets` array that did not make sense in the
target language were not being validated, leading to confusing
compile-time errors.

Add validation for a bunch of these.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

(cherry picked from commit 08a499a)
@aws-cdk-automation
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
maintenance/v5.8

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

github-merge-queue bot pushed a commit that referenced this pull request Nov 3, 2025
#2399)

# Backport

This will backport the following commits from `main` to
`maintenance/v5.8`:
- [fix: invalid jsii target parameters are not validated
(#2398)](#2398)

<!--- Backport version: 9.5.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

Co-authored-by: Rico Hermans <rix0rrr@gmail.com>
mrgrain added a commit that referenced this pull request Nov 11, 2025
Adds validation for target language package names in .jsiirc.json files
to ensure they contain only valid identifier characters. This extends the
validation added in #2398 for package.json to also cover submodule-specific
target configurations.

The validation checks:
- Go: packageName must be a valid identifier
- .NET: namespace parts must be valid identifiers
- Java: package parts must be valid identifiers  
- Python: module parts must be valid identifiers

Type guards ensure validation only runs when proper target structures exist,
maintaining backward compatibility with arbitrary target values used in tests.
mrgrain added a commit that referenced this pull request Nov 11, 2025
Adds validation for target language package names in .jsiirc.json files
to ensure they contain only valid identifier characters. This extends the
validation added in #2398 for package.json to also cover submodule-specific
target configurations.

The validation checks:
- Go: packageName must be a valid identifier
- .NET: namespace parts must be valid identifiers
- Java: package parts must be valid identifiers  
- Python: module parts must be valid identifiers

Type guards ensure validation only runs when proper target structures exist,
maintaining backward compatibility with arbitrary target values used in tests.
github-merge-queue bot pushed a commit that referenced this pull request Nov 12, 2025
Extends the target configuration validation from #2398 to also validate
`.jsiirc.json` files used for submodule-specific target configurations.

Additionally enhances validation to ensure target configurations are
well-formed objects with only valid keys for each language.

## Why

Submodules can have their own target configurations via `.jsiirc.json`
files (for directory-based submodules) or `.<filename>.jsiirc.json`
files (for file-based submodules). These configurations were not being
validated, allowing invalid configurations to slip through until code
generation time.

This PR ensures configuration errors are caught early during compilation
with clear error messages, rather than failing later during package
generation.

## Changes

* Exports `validateTargets` function from `project-info.ts` for reuse
* Calls `validateTargets` when loading `.jsiirc.json` files in
`assembler.ts`
* Adds comprehensive validation for target configuration structure
* Adds 21 new tests covering:
  - File-based `.jsiirc.json` validation (e.g., `.subfile.jsiirc.json`)
  - Namespace conflict detection across all target languages
  - Target configuration structure validation
  - Unknown language and key detection

## Validation Rules

### Identifier Validation

Target language package names must contain only valid identifier
characters:

* **Go**: `packageName` must be a valid identifier
* **.NET**: `namespace` parts (split by `.`) must be valid identifiers
* **Java**: `package` parts (split by `.`) must be valid identifiers
* **Python**: `module` parts (split by `.`) must be valid identifiers

An identifier is defined as matching the regex: `/^[\w_][\w\d_]*$/u`

### Structure Validation

* Target language entries must be objects (not strings or primitives)
* Only known target languages are allowed: `java`, `python`, `dotnet`,
`go`
* Only valid configuration keys are allowed for each language:
  - **Java**: `package`, `maven`, `versionSuffix`
  - **Python**: `module`, `distName`, `classifiers`
  - **.NET**: `namespace`, `packageId`, `iconUrl`, `versionSuffix`
  - **Go**: `moduleName`, `packageName`, `versionSuffix`

### Namespace Conflict Detection

Warns when multiple submodules emit to the same target language
namespace, which would cause conflicts during code generation.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0
license](https://www.apache.org/licenses/LICENSE-2.0).

---------

Signed-off-by: github-actions <github-actions@github.com>
Co-authored-by: github-actions <github-actions@github.com>
aws-cdk-automation pushed a commit that referenced this pull request Nov 12, 2025
Extends the target configuration validation from #2398 to also validate
`.jsiirc.json` files used for submodule-specific target configurations.

Additionally enhances validation to ensure target configurations are
well-formed objects with only valid keys for each language.

## Why

Submodules can have their own target configurations via `.jsiirc.json`
files (for directory-based submodules) or `.<filename>.jsiirc.json`
files (for file-based submodules). These configurations were not being
validated, allowing invalid configurations to slip through until code
generation time.

This PR ensures configuration errors are caught early during compilation
with clear error messages, rather than failing later during package
generation.

## Changes

* Exports `validateTargets` function from `project-info.ts` for reuse
* Calls `validateTargets` when loading `.jsiirc.json` files in
`assembler.ts`
* Adds comprehensive validation for target configuration structure
* Adds 21 new tests covering:
  - File-based `.jsiirc.json` validation (e.g., `.subfile.jsiirc.json`)
  - Namespace conflict detection across all target languages
  - Target configuration structure validation
  - Unknown language and key detection

## Validation Rules

### Identifier Validation

Target language package names must contain only valid identifier
characters:

* **Go**: `packageName` must be a valid identifier
* **.NET**: `namespace` parts (split by `.`) must be valid identifiers
* **Java**: `package` parts (split by `.`) must be valid identifiers
* **Python**: `module` parts (split by `.`) must be valid identifiers

An identifier is defined as matching the regex: `/^[\w_][\w\d_]*$/u`

### Structure Validation

* Target language entries must be objects (not strings or primitives)
* Only known target languages are allowed: `java`, `python`, `dotnet`,
`go`
* Only valid configuration keys are allowed for each language:
  - **Java**: `package`, `maven`, `versionSuffix`
  - **Python**: `module`, `distName`, `classifiers`
  - **.NET**: `namespace`, `packageId`, `iconUrl`, `versionSuffix`
  - **Go**: `moduleName`, `packageName`, `versionSuffix`

### Namespace Conflict Detection

Warns when multiple submodules emit to the same target language
namespace, which would cause conflicts during code generation.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0
license](https://www.apache.org/licenses/LICENSE-2.0).

---------

Signed-off-by: github-actions <github-actions@github.com>
Co-authored-by: github-actions <github-actions@github.com>
(cherry picked from commit 558c3ee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants