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

chore: configure PMD #5155

Merged
merged 1 commit into from May 11, 2024
Merged

Conversation

vil02
Copy link
Member

@vil02 vil02 commented May 11, 2024

PMD is another static analysis tool, which can be used with Java. The pmd-exclude.properties file contains a list of rules, which currently have to be suppressed. Clearly, the long term goal, is to make this file empty. It was generated using such python script (I put it here, just to save it for the future):

# paste the relevant piece of the output of `mvn pmd:check` here
_INPUT = """
[INFO] PMD Failure: com.thealgorithms.bitmanipulation.SingleBitOperations:32 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:36 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:49 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:49 Rule:UselessParentheses Priority:4 Useless parentheses..
"""

def _get_class(in_str):
    class_name, _ = in_str.split(':')
    return class_name

def _get_rule(in_str):
    _, rule = in_str.split(':')
    return rule

def _proc_line(in_str):
    parts = in_str.split()
    class_name = _get_class(parts[3])
    rule = _get_rule(parts[4]);
    return class_name, rule

def _process_pmd_failures(input_data):
    res = {}
   
    for line in input_data.strip().split('\n'):
        class_name, rule = _proc_line(line)
        if class_name not in res:
            res[class_name] = set() 
        res[class_name].add(rule)
   
    return res

for class_name, rules in sorted(_process_pmd_failures(_INPUT).items()):
    rules_str = ",".join(sorted(rules))
    print(f'{class_name}={rules_str}')

This PR is similar to #5110 and #5122.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.26%. Comparing base (bbe4a02) to head (6a9758e).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5155   +/-   ##
=========================================
  Coverage     38.26%   38.26%           
  Complexity     2362     2362           
=========================================
  Files           516      516           
  Lines         15310    15310           
  Branches       2958     2958           
=========================================
  Hits           5858     5858           
  Misses         9165     9165           
  Partials        287      287           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vil02 vil02 marked this pull request as ready for review May 11, 2024 11:02
Copy link
Member

@BamaCharanChhandogi BamaCharanChhandogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,thanks

@BamaCharanChhandogi BamaCharanChhandogi merged commit cb401fe into TheAlgorithms:master May 11, 2024
4 checks passed
@vil02 vil02 deleted the configure_PMD branch May 11, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants