mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 17:49:15 +02:00
Fix calls to string case api (#1620)
* Enable IntelliJ inspection for calls to `String.toLowerCase()` and `String.toUpperCase()` * Enable error prone check * Fix all issues
This commit is contained in:
+1
@@ -94,6 +94,7 @@
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="StringToUpperWithoutLocale" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
|
||||
<inspection_tool class="dd497f47-d38f-3fab-9ed7-eabe699620c8" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
|
||||
</profile>
|
||||
</component>
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import net.ltgt.gradle.errorprone.CheckSeverity
|
||||
import net.ltgt.gradle.errorprone.errorprone
|
||||
import net.ltgt.gradle.nullaway.nullaway
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
@@ -36,6 +37,7 @@ nullaway { onlyNullMarked = true }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.errorprone.disableAllChecks = true
|
||||
options.errorprone.check("StringCaseLocaleUsage", CheckSeverity.ERROR)
|
||||
options.errorprone.nullaway {
|
||||
error()
|
||||
onlyNullMarked = true
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -2541,7 +2542,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
int modifier = visitModifier(ctx);
|
||||
if ((modifier & validModifiers) == 0) {
|
||||
throw exceptionBuilder()
|
||||
.evalError(errorMessage, ctx.getValue().name().toLowerCase())
|
||||
.evalError(errorMessage, ctx.getValue().name().toLowerCase(Locale.ROOT))
|
||||
.withSourceSection(createSourceSection(ctx))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
@@ -115,7 +116,7 @@ public record PklEvaluatorSettings(
|
||||
(Map<String, String>) pSettings.get("env"),
|
||||
allowedModules,
|
||||
allowedResources,
|
||||
color == null ? null : Color.valueOf(color.toUpperCase()),
|
||||
color == null ? null : Color.valueOf(color.toUpperCase(Locale.ROOT)),
|
||||
(Boolean) pSettings.get("noCache"),
|
||||
moduleCacheDir,
|
||||
modulePath,
|
||||
@@ -124,7 +125,7 @@ public record PklEvaluatorSettings(
|
||||
Http.parse((Value) pSettings.get("http")),
|
||||
externalModuleReaders,
|
||||
externalResourceReaders,
|
||||
traceMode == null ? null : TraceMode.valueOf(traceMode.toUpperCase()));
|
||||
traceMode == null ? null : TraceMode.valueOf(traceMode.toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
public record Http(
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -737,7 +738,7 @@ public final class CommandSpecParser {
|
||||
if (each == null)
|
||||
each =
|
||||
(rawValue, workingDirUri) -> {
|
||||
var value = rawValue.toLowerCase();
|
||||
var value = rawValue.toLowerCase(Locale.ROOT);
|
||||
if (TRUE_VALUES.contains(value)) {
|
||||
return true;
|
||||
} else if (FALSE_VALUES.contains(value)) {
|
||||
|
||||
@@ -889,7 +889,7 @@ public final class IoUtils {
|
||||
}
|
||||
|
||||
private static boolean isReservedHeaderName(String headerName) {
|
||||
var normalizedHeader = headerName.toLowerCase();
|
||||
var normalizedHeader = headerName.toLowerCase(Locale.ROOT);
|
||||
for (var reservedHeader : reservedHeaderNames) {
|
||||
if (normalizedHeader.equals(reservedHeader)) {
|
||||
return true;
|
||||
@@ -899,7 +899,7 @@ public final class IoUtils {
|
||||
}
|
||||
|
||||
private static boolean hasReservedHeaderPrefix(String headerName) {
|
||||
var normalizedHeader = headerName.toLowerCase();
|
||||
var normalizedHeader = headerName.toLowerCase(Locale.ROOT);
|
||||
for (var prefix : reservedHeaderPrefixes) {
|
||||
if (normalizedHeader.startsWith(prefix)) {
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.pkl.gradle.test.extreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
import org.msgpack.core.MessagePack;
|
||||
import org.msgpack.value.Value;
|
||||
import org.msgpack.value.ValueFactory;
|
||||
@@ -77,7 +78,7 @@ public class Main {
|
||||
|
||||
var colonIndex = uri.indexOf(':');
|
||||
var schemeSpecific = colonIndex >= 0 ? uri.substring(colonIndex + 1) : uri;
|
||||
var contents = schemeSpecific.toUpperCase().getBytes(StandardCharsets.UTF_8);
|
||||
var contents = schemeSpecific.toUpperCase(Locale.ROOT).getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
packer.packArrayHeader(2);
|
||||
packer.packInt(READ_RESOURCE_RESPONSE);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.pkl.gradle;
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -453,7 +454,7 @@ public class PklPlugin implements Plugin<Project> {
|
||||
+ spec.getName()
|
||||
+ "'. Either apply a JVM plugin (e.g. 'java') or set the sourceSet property explicitly.");
|
||||
}
|
||||
if (sourceSet.getName().toLowerCase().contains("test")) {
|
||||
if (sourceSet.getName().toLowerCase(Locale.ROOT).contains("test")) {
|
||||
module.getTestSources().from(append(module.getTestSources().getFiles(), outputDir));
|
||||
} else {
|
||||
module.setSourceDirs(append(module.getSourceDirs(), outputDir));
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
import org.gradle.api.InvalidUserDataException;
|
||||
import org.gradle.api.file.FileSystemLocation;
|
||||
@@ -183,7 +184,7 @@ public final class PluginUtils {
|
||||
return TestReporter.getDefault();
|
||||
}
|
||||
try {
|
||||
return TestReporter.valueOf(inputStr.toUpperCase());
|
||||
return TestReporter.valueOf(inputStr.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException e) {
|
||||
var sb = new StringBuilder("Invalid test reporter: '");
|
||||
sb.append(inputStr).append("'. ");
|
||||
@@ -197,7 +198,7 @@ public final class PluginUtils {
|
||||
} else {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append('\'').append(value.toString().toLowerCase()).append('\'');
|
||||
sb.append('\'').append(value.toString().toLowerCase(Locale.ROOT)).append('\'');
|
||||
}
|
||||
sb.append(".");
|
||||
throw new InvalidUserDataException(sb.toString());
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.pkl.parser;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Token {
|
||||
ABSTRACT,
|
||||
AMENDS,
|
||||
@@ -233,6 +235,6 @@ public enum Token {
|
||||
if (this == UNDERSCORE) {
|
||||
return "_";
|
||||
}
|
||||
return name().toLowerCase();
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user