From 1ad03c89d97830170f04a4c0517978495d5c365e Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Mon, 6 Nov 2017 15:48:42 -0200 Subject: [PATCH 1/3] Replace php with python for the new engine --- Makefile | 4 +-- README.md | 12 +++---- build.gradle | 2 +- fixtures/app/config.json | 2 +- fixtures/app/main.php | 10 ------ fixtures/app/main.py | 5 +++ settings.gradle | 2 +- .../sanity_check_expected_issues.json | 31 ++++--------------- 8 files changed, 20 insertions(+), 48 deletions(-) delete mode 100644 fixtures/app/main.php create mode 100644 fixtures/app/main.py diff --git a/Makefile b/Makefile index ca557f7..c55ca7b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ .PHONY: image test -IMAGE_NAME ?= codeclimate/codeclimate-sonar-php +IMAGE_NAME ?= codeclimate/codeclimate-sonar-python image: docker build --rm -t $(IMAGE_NAME) . test: image - docker run --rm -ti -w /usr/src/app -u root $(IMAGE_NAME) gradle clean test + docker run --rm -ti -w /usr/src/app -u root $(IMAGE_NAME) gradle clean test --info diff --git a/README.md b/README.md index f5b21e8..1b7b493 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ -# Code Climate Sonar-PHP Engine +# Code Climate Sonar-Python Engine -[![CircleCI](https://circleci.com/gh/codeclimate/codeclimate-sonar-php.svg?style=svg&circle-token=72a9e9a49dc6a8653be6a69321012fe1d84abc3d)](https://circleci.com/gh/codeclimate/codeclimate-sonar-php) -[![Maintainability](https://api.codeclimate.com/v1/badges/2bdcb2e92bbc0efb855b/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate-sonar-php/maintainability) -[![Test Coverage](https://api.codeclimate.com/v1/badges/2bdcb2e92bbc0efb855b/test_coverage)](https://codeclimate.com/github/codeclimate/codeclimate-sonar-php/test_coverage) - -`codeclimate-sonar-php` is a Code Climate engine that wraps [Sonarlint](http://www.sonarlint.org) in standalone mode. +`codeclimate-sonar-python` is a Code Climate engine that wraps [Sonarlint](http://www.sonarlint.org) in standalone mode. ## Installation ``` @@ -22,7 +18,7 @@ make test 2. Configure a `.codeclimate.yml` file in your repo. ```yml engines: - sonar-php: + sonar-python: enabled: true config: tests_patterns: @@ -38,7 +34,7 @@ exclude_paths: Ignore issues with severity below the minimum: ``` engines: - sonar-php: + sonar-python: enabled: true config: minimum_severity: critical # default: major diff --git a/build.gradle b/build.gradle index 2ebd895..70b2ecf 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ dependencies { compile("com.github.codeclimate:sonar-wrapper:master-SNAPSHOT") // Plugins - compile("org.sonarsource.php:sonar-php-plugin:2.10.0.2087") + compile("org.sonarsource.python:sonar-python-plugin:1.8.0.1496") testCompile("org.assertj:assertj-core:2.8.0") testCompile("org.skyscreamer:jsonassert:1.5.0") diff --git a/fixtures/app/config.json b/fixtures/app/config.json index f99ca21..9d369e8 100644 --- a/fixtures/app/config.json +++ b/fixtures/app/config.json @@ -1,6 +1,6 @@ { "enabled": true, "include_paths": [ - "main.php" + "main.py" ] } diff --git a/fixtures/app/main.php b/fixtures/app/main.php deleted file mode 100644 index 5c8dea9..0000000 --- a/fixtures/app/main.php +++ /dev/null @@ -1,10 +0,0 @@ -name != NULL) { - } - } -} diff --git a/fixtures/app/main.py b/fixtures/app/main.py new file mode 100644 index 0000000..8353ae6 --- /dev/null +++ b/fixtures/app/main.py @@ -0,0 +1,5 @@ +class MyClass: + def __enter__(self): + pass + def __exit__(self, exc_type, exc_val): # Noncompliant + pass diff --git a/settings.gradle b/settings.gradle index 7717ad2..cf8e9f5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,4 +15,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'codeclimate-sonar-php' +rootProject.name = 'codeclimate-sonar-python' diff --git a/src/test/resources/sanity_check_expected_issues.json b/src/test/resources/sanity_check_expected_issues.json index 8ed380f..92a03ce 100644 --- a/src/test/resources/sanity_check_expected_issues.json +++ b/src/test/resources/sanity_check_expected_issues.json @@ -1,36 +1,17 @@ [ { "type": "issue", - "check_name": "php:S108", - "severity": "major", - "description": "Either remove or fill this block of code.", - "content": { - "body": "

Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

\n

Noncompliant Code Example

\n
\nfor ($i = 0; $i < 42; $i++){}  // Empty on purpose or missing piece of code ?\n
\n

Exceptions

\n

When a block contains a comment, this block is not considered to be empty.

" - }, - "location": { - "path": "main.php", - "lines": { - "begin": 7, - "end": 8 - } - }, - "categories": [ - "Bug Risk" - ] - }, - { - "type": "issue", - "check_name": "php:S2014", + "check_name": "python:S2733", "severity": "blocker", - "description": "Remove this use of \"$this\".", + "description": "Add the missing argument.", "content": { - "body": "

$this refers to the current class instance. But static methods can be accessed without instantiating the class, and $this\nis not available to them. Using $this in a static context will result in a fatal error at runtime.

\n

Noncompliant Code Example

\n
\nclass Clazz {\n  $name=NULL;  // instance variable\n\n  public static function foo(){\n    if ($this->name != NULL) {\n      // ...\n    }\n  }\n}\n
\n

Compliant Solution

\n
\nclass Clazz {\n  $name=NULL;  // instance variable\n\n  public static function foo($nameParam){\n    if ($nameParam != NULL) {\n      // ...\n    }\n  }\n}\n
" + "body": "

The __exit__ method is invoked with four arguments: self, type, value and traceback. Leave one of these out of the method declaration\nand the result will be a TypeError at runtime.

\n

Noncompliant Code Example

\n
\nclass MyClass:\n   def __enter__(self):\n       pass\n   def __exit__(self, exc_type, exc_val):  # Noncompliant\n       pass\n
" }, "location": { - "path": "main.php", + "path": "main.py", "lines": { - "begin": 7, - "end": 7 + "begin": 4, + "end": 4 } }, "categories": [ From ddab0c4d68479acff374dcf9736f462a954e4e57 Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Mon, 6 Nov 2017 16:10:32 -0200 Subject: [PATCH 2/3] kick_build From 1b6461a93f8d7aff06b8c531bdd4ea7322b0cf8d Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Mon, 6 Nov 2017 16:28:36 -0200 Subject: [PATCH 3/3] Remove verbosity --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c55ca7b..8de6d82 100644 --- a/Makefile +++ b/Makefile @@ -6,4 +6,4 @@ image: docker build --rm -t $(IMAGE_NAME) . test: image - docker run --rm -ti -w /usr/src/app -u root $(IMAGE_NAME) gradle clean test --info + docker run --rm -ti -w /usr/src/app -u root $(IMAGE_NAME) gradle clean test