Skip to content

Commit

Permalink
Revert to previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
lyriccoder committed Aug 12, 2020
1 parent 2dd195a commit c4f350f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
64 changes: 32 additions & 32 deletions PATTERNS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ such patterns may affect the quality of source code.

*Title*: Assert in code

*Code*: **[P1](#p1)**
*Code*: **P1**

*Description*: If there is an `assert` statement in code block, and name
of class doesn't end with `Test`, it is considered a pattern.
Expand All @@ -28,7 +28,7 @@ class Book {
***
*Title*: Setter

*Code*: **[P2](#p2)**
*Code*: **P2**

Description: The method's name starts with set, then goes the name of the attribute. There are attributes assigning in the method. Also, asserts are ignored.
Expand Down Expand Up @@ -84,7 +84,7 @@ class Book {
***
*Title*: Empty Rethrow
*Code*: **[P3](#p3)**
*Code*: **P3**
Description: We throw the same exception as it was caught
Expand All @@ -107,7 +107,7 @@ class Book {
*Title*: ErClass
*Code*: **[P4](#p4)**
*Code*: **P4**
Description: If a class name is one of the following (or ends with this word), it's the pattern:

Expand All @@ -119,7 +119,7 @@ Holder, Interceptor

*Title*: Force type casting.

*Code:* **[P5](#p5)**
*Code:* **P5**

*Description*: The force type casting considered as a pattern.

Expand All @@ -136,7 +136,7 @@ public int square (int n) {

*Title*: If return if detection

*Code*: **[P6](#p6)**
*Code*: **P6**

Description: If there is a return in if condition, it's a pattern.
Expand All @@ -158,7 +158,7 @@ class T1 {
*Title*: Implements Multi
*Code*: **[P7](#p7)**
*Code*: **P7**
Description: If a class implements more than 1 interface it's a pattern

Expand Down Expand Up @@ -187,7 +187,7 @@ public class a implements A, B {

*Title*: Using ```instanceof``` operator.

*Code:* **[P8](#p8)**
*Code:* **P8**

*Description*: Using of ```instanceof``` operator considered as pattern.

Expand Down Expand Up @@ -216,7 +216,7 @@ class Test

*Title*: Many primary ctors

*Code*: **[P9](#p9)**
*Code*: **P9**

*Description*: If there is more than one primary constructors in a class, it is
considered a pattern.
Expand All @@ -240,7 +240,7 @@ class Book {

*Title*: Usage of method chaining more than one time.

*Code*: **[P10](#p10)**
*Code*: **P10**

*Description*: If we use more than one method chaining invocation.

Expand All @@ -260,7 +260,7 @@ public void start() {

*Title*: Multiple Try

*Code*: **[P11](#p11)**
*Code*: **P11**

Description: Once we see more than one try in a single method, it's a pattern.
Expand Down Expand Up @@ -288,7 +288,7 @@ class Foo {
*Title*: Non final attributes
*Code*: **[P12](#p12)**
*Code*: **P12**
*Description*: Once we see a mutable attribute (without final modifier), it's considered a pattern.

Expand All @@ -303,7 +303,7 @@ class Book {

*Title*: Null checks

*Code*: **[P13](#p13)**
*Code*: **P13**

*Description*: If we check that something equals (or not equals) null (except in constructor)
it is considered a pattern.
Expand All @@ -325,7 +325,7 @@ class Foo {

*Title*: Partial synchronized

*Code*: **[P14](#p14)**
*Code*: **P14**

*Description*: Here, the synchronized block doesn't include all statements of the method. Something stays out of the block.
Expand All @@ -347,7 +347,7 @@ class Book {
*Title*: Redundant catch
*Code*: **[P15](#p15)**
*Code*: **P15**
Description: Here, the method foo() throws IOException, but we catch it inside the method.
Expand All @@ -369,7 +369,7 @@ class Book {
*Title*: Return null
*Code*: **[P16](#p16)**
*Code*: **P16**
Description: When we return null, it's a pattern.

Expand All @@ -388,7 +388,7 @@ class Book {

*Title*: String concatenation using ```+``` operator.

*Code:* **[P17](#p17)**
*Code:* **P17**

*Description*: Any usage string concatenation using ```+``` operator is considered
as pattern match.
Expand All @@ -410,7 +410,7 @@ public void start() {

*Title*: Override method calls parent method.

*Code:* **[P18](#p18)**
*Code:* **P18**

*Description*: If we call parent method from override class method it is considered
as the pattern.
Expand All @@ -429,7 +429,7 @@ public void method1() {

*Title*: Class constructor except ```this``` contains other code.

*Code:* **[P19](#p19)**
*Code:* **P19**

*Description*:
The first constructor has this() and some other statements. This is the "hybrid constructor" pattern.
Expand All @@ -453,7 +453,7 @@ class Book {

*Title*: Line distance between variable declaration and first usage greater then threshold.

*Code:* **[P20_5](#p20_5), [P20_7](#p20_7), [P20_11](#p20_11)**
*Code:* **P20_5, P20_7, P20_11**

*Description*: If line distance between variable declaration and first usage
exceeds some threshold we consider it as the pattern. We calculate only non-empty
Expand All @@ -477,7 +477,7 @@ static void myMethod() {

*Title*: Variable is declared in the middle of the method body.

*Code:* **[P21](#p21)**
*Code:* **P21**

*Description*: All variable we need have to be declared at the
beginning of its scope. If variable declared inside the scope following
Expand All @@ -498,7 +498,7 @@ static void myMethod2() {

*Title*: Array as argument

*Code*: **[P22](#p22)**
*Code*: **P22**

Description: If we pass an `array` as an argument, it's a pattern. It's better to use objects, instead of arrays.

Expand All @@ -514,7 +514,7 @@ class Foo {

*Title*: Joined Validation

*Code*: **[P23](#p23)**
*Code*: **P23**

Description: Once you see a validation (if with a single throw inside) and its condition contains more than one condition joined with OR -- it's a pattern.
Expand All @@ -535,7 +535,7 @@ class Book {
*Title*: Class declaration must always be `final`
*Code*: **[P24](#p24)**
*Code*: **P24**
*Description*: Once you see a non `final` method, it's a pattern..

Expand All @@ -551,7 +551,7 @@ class Book {
***
*Title*: Private static method

*Code*: **[P25](#p25)**
*Code*: **P25**

*Description*: Once you see a `private static` method, it's a pattern.
Expand All @@ -568,7 +568,7 @@ class Book {
***
*Title*: Public static method
*Code*: **[P26](#p26)**
*Code*: **P26**
*Description*: Once you see a `public static` method, it's a pattern.

Expand All @@ -585,7 +585,7 @@ class Book {
***
*Title*: Var siblings

*Code*: **[27](#p27)**
*Code*: **27**

*Description*: Here fileSize and fileDate are "siblings" because they both have file as first part of their compound names. It's better to rename them to size and date.
Expand All @@ -605,7 +605,7 @@ class Foo {
***
*Title*: Assign null
*Code*: **[P28](#p28)**
*Code*: **P28**
Description: Once we see `= null`, it's a pattern.

Expand All @@ -623,7 +623,7 @@ class Foo {

*Title*: Multiple ```While``` pattern

*Code:* **[code](#code)**
*Code:* **P29**

*Description*: Once you see two or more ```while``` statements in a method body, it's a pattern.
Expand All @@ -645,7 +645,7 @@ class Book {
*Title*: Protected method
*Code*: **[P30](#p30)**
*Code*: **P30**
Description: Once we find a protected method in a class, it's a pattern.

Expand All @@ -654,7 +654,7 @@ Description: Once we find a protected method in a class, it's a pattern.

*Title*: Send null

*Code*: **[P31](#p31)**
*Code*: **P31**

Description: Once we see that `null` is being given as an argument to some method, it's a pattern.
Expand All @@ -672,7 +672,7 @@ class Foo {
*Title*: Nested loop
*Code*: **[P32](#p32)**
*Code*: **P32**
*Description*: Once we find a loop (`for` / `while`) inside another loop it's a pattern.

Expand Down
6 changes: 4 additions & 2 deletions aibolit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ def get_exit_code(results):
def create_text(results, full_report, is_long=False):
importances_for_all_classes = []
buffer = []
http_link = ''
total_patterns = 0
if not full_report:
buffer.append('Show pattern with the largest contribution to Cognitive Complexity')
Expand All @@ -555,7 +554,7 @@ def create_text(results, full_report, is_long=False):
buffer.append(output_string)
elif results_item and not ex:
# get unique patterns score
patterns_scores = print_total_score_for_file(importances_for_all_classes, result_for_file)
patterns_scores = print_total_score_for_file(buffer, filename, importances_for_all_classes, result_for_file)
patterns_number = len(patterns_scores)
pattern_number = 0
cur_pattern_name = ''
Expand Down Expand Up @@ -607,13 +606,16 @@ def show_summary(buffer, importances_for_all_classes, is_long, results, total_pa


def print_total_score_for_file(
buffer: List[str],
filename: str,
importances_for_all_classes: List[int],
result_for_file):
patterns_scores = {}
for x in result_for_file['results']:
patterns_scores[x['pattern_name']] = x['importance']
importances_for_class = sum(patterns_scores.values())
importances_for_all_classes.append(importances_for_class)
buffer.append('{} score: {}'.format(filename, importances_for_class))
return patterns_scores


Expand Down

0 comments on commit c4f350f

Please sign in to comment.