Skip to content

Commit

Permalink
Merge pull request #77 from embulk/checkstyle-9.3
Browse files Browse the repository at this point in the history
Checkstyle with checkstyle 9.3
  • Loading branch information
dmikurube authored Apr 17, 2024
2 parents 5616a11 + 62ed4d6 commit dd8c8dc
Show file tree
Hide file tree
Showing 20 changed files with 846 additions and 67 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,13 @@ task jruby9_2_9Test(type: Test, description: "Runs tests with JRuby 9.2.9.", gro
outputs.upToDateWhen { false }
}
}

checkstyle {
toolVersion = libs.versions.checkstyle.get()
configFile = file("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
configProperties = [
"org.checkstyle.google.suppressionfilter.config": file("${rootProject.projectDir}/config/checkstyle/checkstyle-suppressions.xml"),
]
ignoreFailures = false
maxWarnings = 0
}
11 changes: 11 additions & 0 deletions config/checkstyle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Checkstyle for the Embulk project
==================================

* google_check.xml: Downloaded from: https://github.com/checkstyle/checkstyle/blob/checkstyle-9.3/src/main/resources/google_checks.xml
* Commit: 5c1903792f8432243cc8ae5cd79a03a004d3c09c
* checkstyle.xml: Customized from google_check.xml.
* To enable suppressions through checkstyle-suppressions.xml.
* To enable suppressions with @SuppressWarnings.
* To indent with 4-column spaces.
* To limit columns to 180 characters.
* To reject unused imports.
14 changes: 14 additions & 0 deletions config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.2//EN"
"http://checkstyle.sourceforge.net/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress checks="JavadocMethod" files=".*"/>
<suppress checks="JavadocParagraph" files=".*"/>
<suppress checks="JavadocTagContinuationIndentation" files=".*"/>
<suppress checks="MissingJavadocType" files=".*"/>
<suppress checks="SingleLineJavadoc" files=".*"/>
<suppress checks="SummaryJavadoc" files=".*"/>
</suppressions>
368 changes: 368 additions & 0 deletions config/checkstyle/checkstyle.xml

Large diffs are not rendered by default.

364 changes: 364 additions & 0 deletions config/checkstyle/google_checks.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

junit5 = "5.9.2"

checkstyle = "9.3"

[libraries]

junit5-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit5" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private OffsetDateTime getOffsetAppliedDateTime(final TemporalAccessor original,
? original.get(ChronoField.MINUTE_OF_HOUR) : this.defaultMinuteOfHour;
int secondOfMinute = original.isSupported(ChronoField.SECOND_OF_MINUTE)
? original.get(ChronoField.SECOND_OF_MINUTE) : this.defaultSecondOfMinute;
int nanoOfSecond = original.isSupported(ChronoField.NANO_OF_SECOND)
final int nanoOfSecond = original.isSupported(ChronoField.NANO_OF_SECOND)
? original.get(ChronoField.NANO_OF_SECOND) : this.defaultNanoOfSecond;

int offset = zoneOffset.getTotalSeconds();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/embulk/util/rubytime/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private List<FormatToken> compileInitial() {
* @param beginningIndex index of the character next to {@code '%'} in {@code formatString}.
* @return {@code true} if recognized as a directive, {@code false} otherwise.
*/
@SuppressWarnings("checkstyle:LeftCurly")
private boolean compileDirective(final int beginningIndex) {
final FormatDirectiveOptions.Builder optionsBuilder = FormatDirectiveOptions.builder();

Expand Down Expand Up @@ -284,6 +285,8 @@ private boolean compileDirective(final int beginningIndex) {

case '0':
optionsBuilder.setPadding('0');
// fall-through

case '1':
case '2':
case '3':
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/embulk/util/rubytime/FormatDirective.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

package org.embulk.util.rubytime;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/org/embulk/util/rubytime/FormatterWithContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ String format(final Format format) {
return this.format(format, RubyDateTimeFormatter.ZoneNameStyle.NONE);
}

@SuppressWarnings("checkstyle:LeftCurly")
String format(final Format format, final RubyDateTimeFormatter.ZoneNameStyle zoneNameStyle) {
final StringBuilder builder = new StringBuilder();

Expand Down Expand Up @@ -371,6 +372,9 @@ String format(final Format format, final RubyDateTimeFormatter.ZoneNameStyle zon
// %+ is not supported in formatter. %+ is only for parser.
builder.append(token.getImmediate().orElse(""));
break;

default:
// Pass-through.
}
}
}
Expand Down Expand Up @@ -616,12 +620,16 @@ private void appendYearWithoutCentury(
* <li>MRI's {@code Time.zone} (the name of the time zone) cannot be set arbitrary.
* It is set almost only from {@code localtime(3)} from the computer's environment,
* such as the TZ environment variable.
* @see <a href="https://twitter.com/shyouhei/status/1245616200874209283">Tweet from @shyouhei (in Japanese)</a>
* @see <a href="https://twitter.com/nalsh/status/1245689453315670022">Tweet from @nalsh (in Japanese)</a>
* <ul>
* <li><a href="https://twitter.com/shyouhei/status/1245616200874209283">Tweet from @shyouhei (in Japanese)</a>
* <li><a href="https://twitter.com/nalsh/status/1245689453315670022">Tweet from @nalsh (in Japanese)</a>
* </ul>
* <li>MRI's {@code Time#strptime} never sets the name of the time zone from its input.
* The name of the time zone is set only from {@code Time.utc} or {@code Time.local}.
* @see <a href="https://docs.ruby-lang.org/en/2.7.0/Time.html#method-c-local">Time.local</a>
* @see <a href="https://docs.ruby-lang.org/en/2.7.0/Time.html#method-c-utc">Time.utc</a>
* <ul>
* <li><a href="https://docs.ruby-lang.org/en/2.7.0/Time.html#method-c-local">Time.local</a>
* <li><a href="https://docs.ruby-lang.org/en/2.7.0/Time.html#method-c-utc">Time.utc</a>
* </ul>
* <li>Embulk uses only {@link java.time.Instant} as its internal timestamp representation.
* </ol>
*
Expand Down Expand Up @@ -679,6 +687,7 @@ private void appendYearWithoutCentury(
*
* <p>On the other hand, Embulk's legacy {@code TimestampFormatter} has used {@code org.jruby.util.RubyDateFormat}
* directly. Unlike just {@code Time.strptime}, {@code RubyDateFormat} formats {@code "%Z"} into short names.
*
* @see <a href="https://github.com/jruby/jruby/blob/9.1.15.0/core/src/main/java/org/jruby/util/RubyDateFormat.java#L411-L419">RubyDateFormat#compilePattern</a>
* @see <a href="https://github.com/jruby/jruby/blob/9.1.15.0/core/src/main/java/org/jruby/util/RubyDateFormat.java#L622-L624">RubyDateFormat#format</a>
*
Expand Down Expand Up @@ -737,6 +746,8 @@ private void appendTimeZoneName(
builder.append("");
}
break;
default:
// Pass-through.
}
}

Expand Down Expand Up @@ -872,6 +883,7 @@ private void appendLongFormatted(
*
* @see <a href="https://github.com/ruby/ruby/blob/v2_6_3/strftime.c#L985-L1092">iso8601wknum</a>
*/
@SuppressWarnings("checkstyle:LeftCurly")
private static int calculateIso8601WeekNumber(final TemporalAccessor temporal) {
final int jan1DayOfWeek = calculateJan1DayOfWeek(temporal);

Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/embulk/util/rubytime/Parsed.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@

package org.embulk.util.rubytime;

import java.time.DateTimeException;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/embulk/util/rubytime/ParserWithContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package org.embulk.util.rubytime;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.time.Instant;
import java.time.Year;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

final class ParserWithContext {
ParserWithContext(final CharSequence text) {
Expand Down Expand Up @@ -717,7 +717,7 @@ private static int toInt(final char c) {
* @see <a href="https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v2_5_1/ext/date/date_strptime.c?view=markup#l571">ext/date/date_strptime.c</a>
*/
private static final Pattern ZONE_PARSE_REGEX =
Pattern.compile("\\A("
Pattern.compile("\\A("
+ "(?:gmt|utc?)?[-+]\\d+(?:[,.:]\\d+(?::\\d+)?)?"
+ "|(?-i:[[\\p{Alpha}].\\s]+)(?:standard|daylight)\\s+time\\b"
+ "|(?-i:[[\\p{Alpha}]]+)(?:\\s+dst)?\\b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public final class RubyDateTimeParsedElementsQuery<T> implements TemporalQuery<M
* }
* </pre>
*/
@SuppressWarnings("checkstyle:LineLength")
public static interface FractionalSecondConverter {
/**
* Converts fractional second, a pair of an integer part and a fraction part, into an arbitrary {@link java.lang.Object} to be stored in the result {@link java.util.Map} of {@link RubyDateTimeParsedElementsQuery}.
Expand Down Expand Up @@ -324,21 +325,21 @@ private Map<T, Object> build() {
private static final MillisecondToBigDecimalConverter MILLISECOND_TO_BIG_DECIMAL;
private static final StringAsIs STRING_AS_IS;

private final static class FractionalSecondToBigDecimalConverter implements FractionalSecondConverter {
private static final class FractionalSecondToBigDecimalConverter implements FractionalSecondConverter {
@Override
public Object convertFractionalSecond(final long integer, final int nano) {
return BigDecimal.valueOf(integer).add(BigDecimal.valueOf(nano, 9));
}
}

private final static class MillisecondToBigDecimalConverter implements MillisecondConverter {
private static final class MillisecondToBigDecimalConverter implements MillisecondConverter {
@Override
public Object convertMillisecond(final long millisecond) {
return BigDecimal.valueOf(millisecond, 3);
}
}

private final static class StringAsIs implements MapKeyConverter<String> {
private static final class StringAsIs implements MapKeyConverter<String> {
@Override
public String convertMapKey(final String mapKey) {
return mapKey;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/embulk/util/rubytime/RubyDateTimeZones.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* irb(main):008:0> Time.strptime("2017-12-31 12:34:56 PST", "%Y-%m-%d %H:%M:%S %z")
* => 2017-12-31 12:34:56 -0800}</pre>
*/
@SuppressWarnings("checkstyle:Indentation")
public final class RubyDateTimeZones {
private RubyDateTimeZones() {
// No instantiation.
Expand Down Expand Up @@ -142,6 +143,7 @@ static int mapZoneNameToOffsetInSecondsForTesting(final String zone) {
*
* @see <a href="https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v2_5_0/ext/date/date_parse.c?view=markup#l415">the latter part of date_zone_to_diff</a>
*/
@SuppressWarnings("checkstyle:IllegalTokenText")
private static String normalize(final String original) {
final int originalLength = original.length();
StringBuilder normalized = null;
Expand Down Expand Up @@ -550,6 +552,7 @@ private static int mapZoneNameToOffsetInSeconds(final String zone) {
case "WEST ASIA": return 18000;
case "WEST PACIFIC": return 36000;
case "YAKUTSK": return 32400;
default: // Pass-through.
}
return Integer.MIN_VALUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.embulk.util.rubytime;

import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
public interface RubyTemporalQueryResolver {
String getOriginalText();

String getZone();

String getLeftover();
}
64 changes: 34 additions & 30 deletions src/main/java/org/embulk/util/rubytime/RubyTimeZones.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* irb(main):008:0> Time.strptime("2017-12-31 12:34:56 PST", "%Y-%m-%d %H:%M:%S %z")
* => 2017-12-31 12:34:56 -0800}</pre>
*/
@SuppressWarnings("checkstyle:Indentation")
public final class RubyTimeZones {
private RubyTimeZones() {
// No instantiation.
Expand Down Expand Up @@ -105,19 +106,19 @@ private static boolean matchesOffsetRepresentation(final String zone) {
case 3: // +HH
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2));
case 5: // +HHMM
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4));
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4));
case 6: // +HH:MM
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5));
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5));
case 7: // +HHMMSS
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4)) &&
Character.isDigit(zone.charAt(5)) && Character.isDigit(zone.charAt(6));
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4))
&& Character.isDigit(zone.charAt(5)) && Character.isDigit(zone.charAt(6));
case 9: // +HH:MM:SS
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5)) &&
zone.charAt(6) == ':' && Character.isDigit(zone.charAt(7)) && Character.isDigit(zone.charAt(8));
return Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5))
&& zone.charAt(6) == ':' && Character.isDigit(zone.charAt(7)) && Character.isDigit(zone.charAt(8));
default:
return false;
}
Expand All @@ -131,37 +132,39 @@ private static int extractOffsetRepresentation(final String zone) {
}
return Integer.MIN_VALUE;
case 5: // +HHMM
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600 +
(Character.digit(zone.charAt(3), 10) * 10 + Character.digit(zone.charAt(4), 10)) * 60;
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600
+ (Character.digit(zone.charAt(3), 10) * 10 + Character.digit(zone.charAt(4), 10)) * 60;
}
return Integer.MIN_VALUE;
case 6: // +HH:MM
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600 +
(Character.digit(zone.charAt(4), 10) * 10 + Character.digit(zone.charAt(5), 10)) * 60;
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600
+ (Character.digit(zone.charAt(4), 10) * 10 + Character.digit(zone.charAt(5), 10)) * 60;
}
return Integer.MIN_VALUE;
case 7: // +HHMMSS
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4)) &&
Character.isDigit(zone.charAt(5)) && Character.isDigit(zone.charAt(6))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600 +
(Character.digit(zone.charAt(3), 10) * 10 + Character.digit(zone.charAt(4), 10)) * 60 +
(Character.digit(zone.charAt(5), 10) * 10 + Character.digit(zone.charAt(6), 10));
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& Character.isDigit(zone.charAt(3)) && Character.isDigit(zone.charAt(4))
&& Character.isDigit(zone.charAt(5)) && Character.isDigit(zone.charAt(6))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600
+ (Character.digit(zone.charAt(3), 10) * 10 + Character.digit(zone.charAt(4), 10)) * 60
+ (Character.digit(zone.charAt(5), 10) * 10 + Character.digit(zone.charAt(6), 10));
}
return Integer.MIN_VALUE;
case 9: // +HH:MM:SS
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2)) &&
zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5)) &&
zone.charAt(6) == ':' && Character.isDigit(zone.charAt(7)) && Character.isDigit(zone.charAt(8))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600 +
(Character.digit(zone.charAt(4), 10) * 10 + Character.digit(zone.charAt(5), 10)) * 60 +
(Character.digit(zone.charAt(7), 10) * 10 + Character.digit(zone.charAt(8), 10));
if (Character.isDigit(zone.charAt(1)) && Character.isDigit(zone.charAt(2))
&& zone.charAt(3) == ':' && Character.isDigit(zone.charAt(4)) && Character.isDigit(zone.charAt(5))
&& zone.charAt(6) == ':' && Character.isDigit(zone.charAt(7)) && Character.isDigit(zone.charAt(8))) {
return (Character.digit(zone.charAt(1), 10) * 10 + Character.digit(zone.charAt(2), 10)) * 3600
+ (Character.digit(zone.charAt(4), 10) * 10 + Character.digit(zone.charAt(5), 10)) * 60
+ (Character.digit(zone.charAt(7), 10) * 10 + Character.digit(zone.charAt(8), 10));
}
return Integer.MIN_VALUE;
default:
// Pass-through.
}
return Integer.MIN_VALUE;
}
Expand Down Expand Up @@ -230,6 +233,7 @@ private static ZoneOffset mapZoneNametoZoneOffset(final String name) {
case "W": return OFFSET_N_10;
case "X": return OFFSET_N_11;
case "Y": return OFFSET_N_12;
default: // Pass-through.
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@

package org.embulk.util.rubytime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.time.DateTimeException;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import org.junit.jupiter.api.Test;

/**
Expand Down
Loading

0 comments on commit dd8c8dc

Please sign in to comment.