Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Linted #29

Merged
merged 13 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
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
33 changes: 22 additions & 11 deletions .github/linters/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/checks/misc/index.html -->
<module name="RegexpSingleline">
<!--<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
</module>-->

<!-- Checks for Headers -->
<!-- See https://checkstyle.org/checks/header/index.html -->
Expand All @@ -90,8 +90,9 @@

<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="250"/>
<property name="max" value="500"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
<property name="severity" value="warning"/>
</module>

<module name="TreeWalker">
Expand Down Expand Up @@ -123,7 +124,7 @@
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
<property name="severity" value="warning"/>
</module>

<!-- Checks for Size Violations. -->
Expand Down Expand Up @@ -151,7 +152,7 @@

<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/checks/blocks/index.html -->
<module name="AvoidNestedBlocks"/>
<!--<module name="AvoidNestedBlocks"/>-->
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
Expand All @@ -160,10 +161,12 @@
<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/checks/coding/index.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<!--<module name="EqualsHashCode"/>-->
<module name="HiddenField">
<property name="severity" value="warning"/>
</module>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<!--<module name="InnerAssignment"/>-->
<!--<module name="MagicNumber"/>-->
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
Expand All @@ -173,16 +176,18 @@
<!-- Checks for class design -->
<!-- See https://checkstyle.org/checks/design/index.html -->
<!--<module name="DesignForExtension"/>-->
<module name="FinalClass"/>
<module name="FinalClass">
<property name="severity" value="warning"/>
</module>
<!--<module name="HideUtilityClassConstructor"/>-->
<module name="InterfaceIsType"/>
<!--<module name="VisibilityModifier"/>-->

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/checks/misc/index.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment"/>
<!--<module name="FinalParameters"/>-->
<!--<module name="TodoComment"/>-->
<module name="UpperEll"/>

<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
Expand All @@ -192,6 +197,12 @@
<property name="optional" value="true"/>
</module>

<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>

</module>

</module>
5 changes: 4 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ jobs:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IGNORE_GITIGNORED_FILES: true
VALIDATE_JAVA_CHECKSTYLE: true
VALIDATE_GOOGLE_JAVA_FORMAT: false
VALIDATE_JSCPD: false
VALIDATE_MARKDOWN: false
JAVA_FILE_NAME: 'checkstyle.xml'
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ abstract class AbstractConfigMultiValue<E> extends AbstractConfigValue<E[]> {
private final IntFunction<E[]> m_arrayFactory;

@SuppressWarnings("unchecked")
protected AbstractConfigMultiValue(String key, Class<E> elementClass) {
protected AbstractConfigMultiValue(final String key, final Class<E> elementClass) {
super(key);
m_arrayFactory = (int length) -> (E[])Array.newInstance(elementClass, length);
m_arrayFactory = (int length) -> (E[]) Array.newInstance(elementClass, length);
}

@Override
protected final E[] parseJsonValue(Object configValue) {
protected final E[] parseJsonValue(final Object configValue) {
JSONArray jsonArray;
try {
jsonArray = (JSONArray)configValue;
jsonArray = (JSONArray) configValue;
} catch (ClassCastException ex) {
final E[] valueArray = m_arrayFactory.apply(1);
valueArray[0] = parseJsonElement(configValue);
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/com/team766/config/AbstractConfigValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ public abstract class AbstractConfigValue<E> implements SettableValueProvider<E>
private E m_cachedValue;
private boolean m_cachedHasValue;
private int m_cachedGeneration = -1;

private static ArrayList<AbstractConfigValue<?>> c_accessedValues = new ArrayList<AbstractConfigValue<?>>();

static Collection<AbstractConfigValue<?>> accessedValues() {
return Collections.unmodifiableCollection(c_accessedValues);
}

static void resetStatics() {
c_accessedValues.clear();
}
protected AbstractConfigValue(String key) {

protected AbstractConfigValue(final String key) {
m_key = key;
c_accessedValues.add(this);
// Querying for this config setting's key will add a placeholder entry
// in the config file if this setting does not already exist there.
ConfigFileReader.instance.getRawValue(m_key);
}

private void sync() {
if (ConfigFileReader.instance.getGeneration() != m_cachedGeneration) {
m_cachedGeneration = ConfigFileReader.instance.getGeneration();
Expand All @@ -42,7 +42,9 @@ private void sync() {
try {
m_cachedValue = parseJsonValue(rawValue);
} catch (Exception ex) {
Logger.get(Category.CONFIGURATION).logRaw(Severity.ERROR, "Failed to parse " + m_key + " from the config file: " + LoggerExceptionUtils.exceptionToString(ex));
Logger.get(Category.CONFIGURATION).logRaw(Severity.ERROR,
"Failed to parse " + m_key + " from the config file: "
+ LoggerExceptionUtils.exceptionToString(ex));
m_cachedValue = null;
m_cachedHasValue = false;
}
Expand All @@ -53,13 +55,13 @@ private void sync() {
public String getKey() {
return m_key;
}

@Override
public boolean hasValue() {
sync();
return m_cachedHasValue;
}

@Override
public E get() {
sync();
Expand All @@ -69,16 +71,16 @@ public E get() {
return m_cachedValue;
}

public void set(E value) {
public void set(final E value) {
ConfigFileReader.instance.setValue(m_key, value);
}

public void clear() {
ConfigFileReader.instance.setValue(m_key, null);
}

protected abstract E parseJsonValue(Object configValue);

@Override
public String toString() {
sync();
Expand Down
Loading
Loading