Skip to main content

A check50 extension that wraps around the static code analyser checkstye(.org)

Project description

check50_checkstyle

This is an extension for the CS50 automarker check50 that allows to run the static code analyser checkstyle and interpret the resulting XML report as check50 Failures.

Checkstyle let's you complain about style issues, particularly in Java code, beyond what style50 (astyle) can do. For instance you can flag if identifiers don't adhere to Java's camelCase code conventions, or javadocs are missing.

For convenience, this package ships with the stand-alone CLI of checkstyle (checkstyle-8.35-all.jar), which is why it is so large.

Example Usage

You need to import this module into your problem set (__init.py__):

import check50_checkstyle

and declare #- check50-checkstyle it as a dependency in your .cs50.yml file:

check50:
  dependencies:
    - check50-checkstyle

Checkstyle needs an XML style definition file to run. The jar file contains two such definitions, following the sun or google style guides but both are rather "picky",i.e., complain about lots of minor stuff. Pick one of these style files and delete what you don't like.

Let's assume your problem set contains the style definition style.xml. Then you add a check50 check as follows. The target can be more specific of course.

@check50.check(exists)
def checkstyle():
    """style police"""
    check50.include("style.xml")
    check50_checkstyle.run_and_interpret_checkstyle(
        checks_file='style.xml',
        target='*.java')

This will dump all warnings into the log (because check50 hard-codes its html template). Example output:

:( style police
    stylistic issues found
    Issues found:
    - In Credit.java(line 4, char 5): Missing a Javadoc comment.
    - In Basket.java(line 2, char 1): Wrong lexicographical order for 'java.util.ArrayList' import. Should be before 'java.util.List'.
    - In Basket.java(line 19, char 5): Missing a Javadoc comment.
    - In Basket.java(line 27, char 5): Missing a Javadoc comment.
    - In Basket.java(line 35, char 5): Missing a Javadoc comment.
    - In Basket.java(line 47): First sentence of Javadoc is missing an ending period.
    - In Item.java(line 27): Line is longer than 100 characters (found 102).
    - In Item.java(line 53, char 40): 'typecast' is not followed by whitespace.
    - In Snack.java(line 20, char 5): Missing a Javadoc comment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

check50_checkstyle-0.4.tar.gz (12.0 MB view details)

Uploaded Source

Built Distribution

check50_checkstyle-0.4-py3-none-any.whl (12.0 MB view details)

Uploaded Python 3

File details

Details for the file check50_checkstyle-0.4.tar.gz.

File metadata

  • Download URL: check50_checkstyle-0.4.tar.gz
  • Upload date:
  • Size: 12.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for check50_checkstyle-0.4.tar.gz
Algorithm Hash digest
SHA256 c026a7a50e92c655551bc32eb0f2e8ec442e8cff8c7277a210791530b22e01f4
MD5 3da93a7a04c878aae5eb32676f3ed1cb
BLAKE2b-256 e3d63d56c33f26fa70f4f4f9117812990aae6e2ba163f7c243a12e4018a85331

See more details on using hashes here.

File details

Details for the file check50_checkstyle-0.4-py3-none-any.whl.

File metadata

  • Download URL: check50_checkstyle-0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for check50_checkstyle-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c59b69a820b8a4a70ad3eb4b27bbe5d5a2afa66b339e83a187e93c675d5fcf6
MD5 cce8c45bb1937c54ed865e26eee7b51e
BLAKE2b-256 d314ebf0aeab40b166629fb334c11e39c2be6e8b8f2335a716286d26f0f12749

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page