From f6d9528789e1b4c7a780ff629d230b4e37d0ef34 Mon Sep 17 00:00:00 2001 From: Marcelo Cenerino Date: Wed, 28 Feb 2018 00:33:47 +0000 Subject: [PATCH] Address review comments - Remove redundant expressions in AnnotationScopes test - Update docs to include example of mixing @SuppressWarnings and comments --- .../test/escapeHatch/AnnotationScopes.scala | 127 ++---------------- .../src/main/tut/docs/users/configuration.md | 13 +- 2 files changed, 20 insertions(+), 120 deletions(-) diff --git a/scalafix-tests/input/src/main/scala/test/escapeHatch/AnnotationScopes.scala b/scalafix-tests/input/src/main/scala/test/escapeHatch/AnnotationScopes.scala index af2aba073..b1a04f562 100644 --- a/scalafix-tests/input/src/main/scala/test/escapeHatch/AnnotationScopes.scala +++ b/scalafix-tests/input/src/main/scala/test/escapeHatch/AnnotationScopes.scala @@ -57,138 +57,49 @@ object AnnotationScopes { // Class @SuppressWarnings(Array("NoDummy")) class DummyClass_1(val aDummy: Int, val bDummy: Int) { - val cDummy = 0 - var dDummy = 0 - - def this(eDummy: String, fDummy: String) { - this(eDummy.toInt, fDummy.toInt) - } - - def gDummy(hDummy: Int, iDummy: Int): Unit = { - val jDummy = 0 - var hDummy = 0 - } } // Primary constructor class DummyClass_2 @SuppressWarnings(Array("NoDummy"))( // assert: NoDummy val aDummy: Int, val bDummy: Int) { - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } - - def gDummy( // assert: NoDummy - hDummy: Int, // assert: NoDummy - iDummy: Int): Unit = { // assert: NoDummy - val jDummy = 0 // assert: NoDummy - var hDummy = 0 // assert: NoDummy - } } // Primary constructor parameter class DummyClass_3( // assert: NoDummy @SuppressWarnings(Array("NoDummy")) val aDummy: Int, val bDummy: Int) { // assert: NoDummy - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } - - def gDummy( // assert: NoDummy - hDummy: Int, // assert: NoDummy - iDummy: Int): Unit = { // assert: NoDummy - val jDummy = 0 // assert: NoDummy - var hDummy = 0 // assert: NoDummy - } } // Field - class DummyClass_4( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - + class DummyClass_4 { // assert: NoDummy @SuppressWarnings(Array("NoDummy")) val cDummy = 0 - @SuppressWarnings(Array("NoDummy")) - var dDummy = 0 - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } - - def gDummy( // assert: NoDummy - hDummy: Int, // assert: NoDummy - iDummy: Int): Unit = { // assert: NoDummy - val jDummy = 0 // assert: NoDummy - var hDummy = 0 // assert: NoDummy - } + var dDummy = 0 // assert: NoDummy } // Secondary constructor - class DummyClass_5( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy + class DummyClass_5 { // assert: NoDummy @SuppressWarnings(Array("NoDummy")) def this(eDummy: String, fDummy: String) { - this(eDummy.toInt, fDummy.toInt) - } - - def gDummy( // assert: NoDummy - hDummy: Int, // assert: NoDummy - iDummy: Int): Unit = { // assert: NoDummy - val jDummy = 0 // assert: NoDummy - var hDummy = 0 // assert: NoDummy + this } } // Secondary constructor parameter - class DummyClass_6( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy + class DummyClass_6 { // assert: NoDummy def this(@SuppressWarnings(Array("NoDummy")) eDummy: String, fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } - - def gDummy( // assert: NoDummy - hDummy: Int, // assert: NoDummy - iDummy: Int): Unit = { // assert: NoDummy - val jDummy = 0 // assert: NoDummy - var hDummy = 0 // assert: NoDummy + this } } // Method - class DummyClass_7( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } + class DummyClass_7 { // assert: NoDummy @SuppressWarnings(Array("NoDummy")) def gDummy(hDummy: Int, iDummy: Int): Unit = { @@ -198,17 +109,7 @@ object AnnotationScopes { } // Method parameter - class DummyClass_8( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } + class DummyClass_8 { // assert: NoDummy def gDummy( // assert: NoDummy @SuppressWarnings(Array("NoDummy")) hDummy: Int, @@ -219,17 +120,7 @@ object AnnotationScopes { } // Local variable - class DummyClass_9( // assert: NoDummy - val aDummy: Int, // assert: NoDummy - val bDummy: Int) { // assert: NoDummy - - val cDummy = 0 // assert: NoDummy - var dDummy = 0 // assert: NoDummy - - def this(eDummy: String, // assert: NoDummy - fDummy: String) { // assert: NoDummy - this(eDummy.toInt, fDummy.toInt) // assert: NoDummy - } + class DummyClass_9 { // assert: NoDummy def gDummy( // assert: NoDummy hDummy: Int, // assert: NoDummy diff --git a/website/src/main/tut/docs/users/configuration.md b/website/src/main/tut/docs/users/configuration.md index a38e3be5c..ee206790c 100644 --- a/website/src/main/tut/docs/users/configuration.md +++ b/website/src/main/tut/docs/users/configuration.md @@ -205,5 +205,14 @@ List(1, "") // scalafix:ok NoInfer.any   **Note:** Suppression via comments and `@SuppressWarnings` can be combined in the same source file. Be mindful not to -introduce overlaps between the two as it can cause confusion. Scalafix gracefully handles overlaps by given -precedence to the `@SuppressWarnings` annotation. \ No newline at end of file +introduce overlaps between the two as it can cause confusion and counter-intuitive behavior. Scalafix handles overlaps +by giving precedence to the `@SuppressWarnings` annotation: + +```scala +@SuppressWarnings(Array("scalafix:Disable.null")) +def overlap(): Unit = { + val a = null + // scalafix:on Disable.null + val b = null // rule is still disabled because the annotation takes precedence over the comment +} +``` \ No newline at end of file