Skip to content

Commit

Permalink
CheckstyleBear: Load google and sun rules from jar
Browse files Browse the repository at this point in the history
The google and sun ruleset have been provided in the
checkstyle jar since version 6.2.

Load the rulesets from the linter jar so the rules
are known to be compatible with the linter version.

Fixes coala#1017
Fixes coala#1034
  • Loading branch information
jayvdb committed Nov 22, 2016
1 parent f41b6cf commit 9b86d14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
15 changes: 10 additions & 5 deletions bears/java/CheckstyleBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from coalib.settings.Setting import path


known_checkstyles = {
"google": "https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml",
"sun": 'https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml',
_online_styles = {
"android-check-easy": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-easy.xml",
"android-check-hard": "https://raw.githubusercontent.com/noveogroup/android-check/master/android-check-plugin/src/main/resources/checkstyle/checkstyle-hard.xml",
"geosoft": "http://geosoft.no/development/geosoft_checks.xml"}

# To be deprecated
known_checkstyles = dict(_online_styles, **{'google': None, 'sun': None})


def check_invalid_configuration(checkstyle_configs, use_spaces, indent_size):
if (checkstyle_configs is 'google' and
Expand Down Expand Up @@ -75,9 +76,13 @@ def create_arguments(
check_invalid_configuration(
checkstyle_configs, use_spaces, indent_size)

if checkstyle_configs in known_checkstyles:
if checkstyle_configs in ('google', 'sun'):
# Checkstyle included these two rulesets since version 6.2
# Locate the file as an absolute resource into the checkstyle jar
checkstyle_configs = '/%s_checks.xml' % checkstyle_configs
elif checkstyle_configs in _online_styles:
checkstyle_configs = self.download_cached_file(
known_checkstyles[checkstyle_configs],
_online_styles[checkstyle_configs],
checkstyle_configs + ".xml")

return ('-jar', self.checkstyle_jar_file, '-c',
Expand Down
17 changes: 16 additions & 1 deletion tests/java/CheckstyleBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,25 @@ def test_run(self):
self.check_validity(self.uut, [], self.good_file)
self.check_validity(self.uut, [], self.bad_file, valid=False)

def test_known_configs(self):
def test_style_google(self):
self.section["checkstyle_configs"] = "google"
self.check_validity(self.uut, [], self.good_file)

def test_style_sun(self):
self.section["checkstyle_configs"] = "sun"
self.check_validity(self.uut, [], self.good_file)

def test_style_android(self):
self.section["checkstyle_configs"] = "android-check-easy"
self.check_validity(self.uut, [], self.good_file)

self.section["checkstyle_configs"] = "android-check-hard"
self.check_validity(self.uut, [], self.good_file)

def test_style_geosoft(self):
self.section["checkstyle_configs"] = "geosoft"
self.check_validity(self.uut, [], self.good_file)

def test_config_failure_use_spaces(self):
self.section["checkstyle_configs"] = "google"
self.section.append(Setting('use_spaces', False))
Expand Down

0 comments on commit 9b86d14

Please sign in to comment.