Skip to content

Commit

Permalink
Merge pull request #131 from xdev-software/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AB-xdev authored Aug 12, 2024
2 parents 29dd3e2 + 5d4aada commit 920e20f
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 24 deletions.
155 changes: 155 additions & 0 deletions .config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Default"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

<description>
This ruleset checks the code for discouraged programming constructs.
</description>

<!-- Only rules that don't overlap with CheckStyle! -->

<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP"/>
<rule ref="category/java/bestpractices.xml/PreserveStackTrace"/>
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
<rule ref="category/java/bestpractices.xml/UseStandardCharsets"/>

<!-- Native code is platform dependent; Loading external native libs might pose a security threat -->
<rule ref="category/java/codestyle.xml/AvoidUsingNativeCode"/>
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches"/>
<rule ref="category/java/codestyle.xml/NoPackage"/>
<rule ref="category/java/codestyle.xml/PrematureDeclaration"/>

<rule ref="category/java/design.xml">
<!-- Sometimes abstract classes have just fields -->
<exclude name="AbstractClassWithoutAnyMethod"/>

<!-- Using RuntimeExceptions is ok -->
<exclude name="AvoidCatchingGenericException"/>
<exclude name="AvoidThrowingRawExceptionTypes"/>

<!-- Limit too low -->
<exclude name="AvoidDeeplyNestedIfStmts"/>

<!-- Limit too low -->
<exclude name="CouplingBetweenObjects"/>

<!-- Limit too low -->
<exclude name="CyclomaticComplexity"/>

<!-- Makes entity classes impossible -->
<exclude name="DataClass"/>

<!-- Used commonly particular in bigger methods with upstream throws -->
<exclude name="ExceptionAsFlowControl"/>

<!-- Limit too low -->
<exclude name="ExcessiveImports"/>

<!-- Handled by TooManyFields/TooManyMethods -->
<exclude name="ExcessivePublicCount"/>

<!-- Prohibits accessing members using multiple depths -->
<exclude name="LawOfDemeter"/>

<!-- No effect -->
<exclude name="LoosePackageCoupling"/>

<!-- Prohibits singleton pattern -->
<exclude name="MutableStaticState"/>

<!-- Checks LoC, already handled by Checkstyle -->
<exclude name="NcssCount"/>

<!-- Some override methods or Junit require this -->
<exclude name="SignatureDeclareThrowsException"/>

<!-- Reports FP for equals methods -->
<exclude name="SimplifyBooleanReturns"/>

<!-- Limit too low -->
<exclude name="TooManyFields"/>

<!-- Limit too low -->
<exclude name="TooManyMethods"/>

<!-- Limit too low -->
<exclude name="UseObjectForClearerAPI"/>

<!-- Handled by checkstyle -->
<exclude name="UseUtilityClass"/>
</rule>

<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts">
<properties>
<property name="problemDepth" value="4"/>
</properties>
</rule>
<rule ref="category/java/design.xml/CouplingBetweenObjects">
<properties>
<property name="threshold" value="100"/>
</properties>
</rule>
<rule ref="category/java/design.xml/CyclomaticComplexity">
<properties>
<property name="classReportLevel" value="150"/>
<property name="methodReportLevel" value="25"/>
<property name="cycloOptions" value=""/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveImports">
<properties>
<property name="minimum" value="200"/>
</properties>
</rule>
<rule ref="category/java/design.xml/TooManyFields">
<properties>
<property name="maxfields" value="50"/>
</properties>
</rule>
<rule ref="category/java/design.xml/TooManyMethods">
<properties>
<property name="maxmethods" value="100"/>
</properties>
</rule>

<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
<rule ref="category/java/errorprone.xml/ComparisonWithNaN"/>
<rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/>
<rule ref="category/java/errorprone.xml/DontImportSun"/>
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
<rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/>


<rule ref="category/java/multithreading.xml">
<!-- Just bloats code -->
<exclude name="AvoidSynchronizedAtMethodLevel"/>

<!-- NOPE -->
<exclude name="DoNotUseThreads"/>

<!-- Doesn't detect nested thread safe singleton pattern -->
<exclude name="NonThreadSafeSingleton"/>

<!-- Should relevant for fields that use multithreading which is rare -->
<exclude name="UseConcurrentHashMap"/>
</rule>

<rule ref="category/java/performance.xml">
<!-- This was fixed in Java 10 -->
<exclude name="AvoidFileStream"/>

<!-- Used everywhere and has neglectable performance impact -->
<exclude name="AvoidInstantiatingObjectsInLoops"/>

<!-- Handled by checkstyle -->
<exclude name="RedundantFieldInitializer"/>

<!-- Nowadays optimized by compiler; No code bloating needed -->
<exclude name="UseStringBufferForStringAppends"/>
</rule>

<rule ref="category/java/security.xml"/>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ jobs:
path: build/libs/intellij-plugin-save-actions-*.jar
if-no-files-found: error

code-style:
checkstyle:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }}

strategy:
matrix:
Expand All @@ -93,3 +94,34 @@ jobs:

- name: Run Checkstyle
run: ./gradlew checkstyleMain checkstyleTest -PcheckstyleEnabled=true

pmd:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }}

strategy:
matrix:
java: [17]
distribution: [temurin]

steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: ${{ matrix.distribution }}
java-version: ${{ matrix.java }}
cache: 'gradle'

- name: Run PMD
run: ./gradlew pmdMain pmdTest

- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: pmd-report
if-no-files-found: ignore
path: |
build/reports/pmd/*.html
4 changes: 4 additions & 0 deletions .github/workflows/update-from-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ jobs:
echo "Checking if update-branch-merged exists"
git fetch
if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then
echo "Branch still exists; Continuing..."
else
echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing"
exit 0
fi
Expand Down Expand Up @@ -274,6 +276,8 @@ jobs:
echo "Fetching..."
git fetch
if [[ $(git rev-parse origin/${{ env.UPDATE_BRANCH_MERGED }}) ]]; then
echo "Branch still exists; Continuing..."
else
echo "Branch origin/${{ env.UPDATE_BRANCH_MERGED }} is missing"
exit 0
fi
Expand Down
1 change: 1 addition & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.3
* Fix "run on multiple files" not working when the file is not a text file #129

## 1.2.2
* Workaround scaling problem on "New UI" [#26](https://github.com/xdev-software/intellij-plugin-template/issues/26)

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Latest version](https://img.shields.io/jetbrains/plugin/v/22113?logo=jetbrains)](https://plugins.jetbrains.com/plugin/22113)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/intellij-plugin-save-actions/checkBuild.yml?branch=develop)](https://github.com/xdev-software/intellij-plugin-save-actions/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/intellij-plugin-save-actions/check-build.yml?branch=develop)](https://github.com/xdev-software/intellij-plugin-save-actions/actions/workflows/check-build.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_intellij-plugin-save-actions&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_intellij-plugin-save-actions)
[![Feel free to leave a rating](https://img.shields.io/jetbrains/plugin/r/rating/22113?style=social&logo=jetbrains&label=Feel%20free%20to%20leave%20a%20rating)](https://plugins.jetbrains.com/plugin/22113/reviews)

Expand All @@ -17,9 +17,9 @@
Supports configurable, Eclipse like, save actions, including "optimize imports", "reformat code", "rearrange code", "compile file" and some quick fixes like "add / remove 'this' qualifier", etc. The plugin executes the configured actions when the file is synchronized (or saved) on disk.

Using the save actions plugin makes your code cleaner and more uniform across your code base by enforcing your code style and code rules every time you save. The settings file (see [files location](#files-location)) can be shared in your development team so that every developer has the same configuration.
Using the save actions plugin makes your code cleaner and more uniform across your code base by enforcing your code style and code rules every time you save. The settings file (see [files location](./USAGE.md#files-location)) can be shared in your development team so that every developer has the same configuration.

The code style applied by the save actions plugin is the one configured your settings at "File > Settings > Editor > Code Style". For some languages, custom formatter (Dartfmt, Prettier, etc.) may also be triggered by the save actions plugin. See the [Editor Actions](#editor-actions) configuration for more information.
The code style applied by the save actions plugin is the one configured your settings at "File > Settings > Editor > Code Style". For some languages, custom formatter (Dartfmt, Prettier, etc.) may also be triggered by the save actions plugin. See the [Editor Actions](./USAGE.md#editor-actions) configuration for more information.

## Features

Expand All @@ -33,8 +33,8 @@ The code style applied by the save actions plugin is the one configured your set
- Include / exclude files with regex support
- Works on any file type (Java, Python, XML, etc.)
- Launch any editor action using "quick lists"
- Uses a settings file per project you can commit (see [Files location](#files-location))
- Available keymaps and actions for activation (see [Keymap and actions](#keymap-and-actions))
- Uses a settings file per project you can commit (see [Files location](./USAGE.md#files-location))
- Available keymaps and actions for activation (see [Keymap and actions](./USAGE.md#keymap-and-actions))

<img src="./assets/intellij-save-actions-plugin-settings-page.png" alt="Save actions plugin settings page" height=500 />

Expand All @@ -44,8 +44,8 @@ Works in JetBrains IDE with Java support, like Intellij IDEA and AndroidStudio.

- Compile project after save (if compiling is available)
- Reload debugger after save (if compiling is available)
- Eclipse configuration file `.epf` support (see [Eclipse support](#eclipse-support))
- Automatically fix Java inspections (see [Java quick fixes](#java-fixes))
- Eclipse configuration file `.epf` support (see [Eclipse support](./USAGE.md#eclipse-support))
- Automatically fix Java inspections (see [Java quick fixes](./USAGE.md#java-fixes))

<img src="./assets/intellij-save-actions-plugin-settings-page-java.png" alt="Save actions plugin settings page for Java" height=600 />

Expand Down
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ plugins {
id 'java'
id 'idea'
id 'checkstyle'
id 'org.jetbrains.intellij' version '1.17.3'
id 'org.sonarqube' version '5.0.0.4638'
id 'pmd'
id 'org.jetbrains.intellij' version '1.17.4'
id 'org.sonarqube' version '5.1.0.4882'
}

ext {
Expand Down Expand Up @@ -41,10 +42,10 @@ configurations.checkstyle {
// Add dependencies to test, junit5 api (annotations) and engine (runtime)
dependencies {
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
testImplementation platform('org.junit:junit-bom:5.10.2'),
testImplementation platform('org.junit:junit-bom:5.10.3'),
'org.junit.jupiter:junit-jupiter',
'org.junit.jupiter:junit-jupiter-engine',
'org.assertj:assertj-core:3.26.0'
'org.assertj:assertj-core:3.26.3'
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because("Only needed to run tests in a version of IntelliJ IDEA that bundles older versions")
}
Expand Down Expand Up @@ -78,6 +79,11 @@ checkstyle {
toolVersion = checkstyleVersion
}

pmd {
consoleOutput = true
ruleSetFiles = files(".config/pmd/ruleset.xml")
}

tasks.withType(Checkstyle).configureEach {
enabled = project.hasProperty("checkstyleEnabled");
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/software/xdev/saveactions/core/component/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private boolean isPsiFileEligible(final Project project, final PsiFile psiFile)
return psiFile != null
&& this.isProjectValid(project)
&& this.isPsiFileValid(psiFile)
&& this.hasPsiFileText(psiFile)
&& this.isPsiFileFresh(psiFile)
&& this.isPsiFileInProject(project, psiFile)
&& this.isPsiFileNoError(project, psiFile)
Expand Down Expand Up @@ -189,6 +190,16 @@ private boolean isPsiFileValid(final PsiFile psiFile)
return valid;
}

private boolean hasPsiFileText(final PsiFile psiFile)
{
final boolean valid = psiFile.getTextRange() != null;
if(!valid)
{
LOGGER.info(String.format("File %s has no text.", psiFile));
}
return valid;
}

boolean isIncludedAndNotExcluded(final String path)
{
return this.isIncluded(path) && !this.isExcluded(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @see com.intellij.codeInspection.visibility.AccessCanBeTightenedInspection
*/
@SuppressWarnings({"java:S6201", "java:S3776", "java:S125", "java:S3398", "java:S2637", "java:S120", "java:S6541", "java:S135"})
@SuppressWarnings({"java:S6201", "java:S3776", "java:S125", "java:S3398", "java:S2637", "java:S120", "java:S6541", "java:S135", "PMD"})
public class CustomAccessCanBeTightenedInspection extends AbstractBaseJavaLocalInspectionTool {
private static final Logger LOG = Logger.getInstance(CustomAccessCanBeTightenedInspection.class);
private final VisibilityInspection myVisibilityInspection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void visitReferenceExpression(@NotNull final PsiReferenceExpression expre
this.registerError(expression, expression);
}

@SuppressWarnings("PMD.NPathComplexity")
private boolean isUnqualifiedStaticAccess(final PsiReferenceExpression expression)
{
if(CustomUnqualifiedStaticUsageInspection.this.m_ignoreStaticAccessFromStaticContext)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/software/xdev/saveactions/ui/BuildPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private boolean hasId(final String id)

private String getId()
{
return this.quickList.hashCode() + "";
return String.valueOf(this.quickList.hashCode());
}

@Override
Expand Down
Loading

0 comments on commit 920e20f

Please sign in to comment.