Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FabricMC/fabricmc.net
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Dec 23, 2024
2 parents 539e29a + c98a76e commit b2630c8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/src/lib/template/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ export function getJavaVersion(minecraftVersion: string): JavaVersion {
return JAVA_21;
}

const JAVA_PACKAGE_REGEX = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/;
const JAVA_PACKAGE_REGEX = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)*$/;
const JAVA_RESERVED_WORDS = `
abstract continue for new switch assert default goto package synchronized
boolean do if private this break double implements protected throw byte else
import public throws case enum instanceof return transient catch extends int
short try char final interface static void class finally long strictfp
volatile const float native super while _ true false null
`.trim().split(/\s+/);
const RESERVED_PACKAGE_PREFIXES = ["net.minecraft.", "com.mojang.", "net.fabricmc.", "java."];

export function computePackageNameErrors(packageName: string): string[] {
Expand All @@ -70,6 +77,11 @@ export function computePackageNameErrors(packageName: string): string[] {
errorList.push("Package name is not a valid Java package name!");
}

const reservedWordsFound = packageName.split('.').filter(c => JAVA_RESERVED_WORDS.includes(c));
if (reservedWordsFound.length != 0) {
errorList.push(`Package name contains illegal component: '${reservedWordsFound[0]}'`);
}

for (let prefix of RESERVED_PACKAGE_PREFIXES) {
if (packageName.toLowerCase().startsWith(prefix)) {
errorList.push(`Package name starts with '${prefix}', which is reserved!`);
Expand Down

0 comments on commit b2630c8

Please sign in to comment.