Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ensure that BCD keys are only used once #1174

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ function convertMarkdown(markdown: string) {
return { text, html };
}

// Map from BCD keys/paths to web-features identifiers.
const bcdToFeatureId: Map<string, string> = new Map();

const features: { [key: string]: FeatureData } = {};
for (const [key, data] of yamlEntries('features')) {
// Draft features reserve an identifier but aren't complete yet. Skip them.
Expand Down Expand Up @@ -155,6 +158,19 @@ for (const [key, data] of yamlEntries('features')) {
}
}

// Check that no BCD key is used twice until the meaning is made clear in
// https://github.com/web-platform-dx/web-features/issues/1173.
if (data.compat_features) {
for (const bcdKey of data.compat_features) {
const otherKey = bcdToFeatureId.get(bcdKey);
if (otherKey) {
throw new Error(`BCD key ${bcdKey} is used in both ${otherKey} and ${key}, which creates ambiguity for some consumers. Please see https://github.com/web-platform-dx/web-features/issues/1173 and help us find a good solution to allow this.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like this message. 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm glad you like it :) It's a bit weird to throw and error and still say that we'd like to allow it...

} else {
bcdToFeatureId.set(bcdKey, key);
}
}
}

features[key] = scrub(data);
}

Expand Down
Loading