Browse Source

Dont treat virtual function definitions and overrides as magic numbers

Josef Hofer 4 years ago
parent
commit
da477b66cf

+ 4 - 4
metrixpp/ext/std/code/magic.ini

@@ -1,15 +1,15 @@
 ;
 ;    Metrix++, Copyright 2009-2019, Metrix++ Project
 ;    Link: https://github.com/metrixplusplus/metrixplusplus
-;    
+;
 ;    This file is a part of Metrix++ Tool.
-;    
+;
 
 [Plugin]
-version: 1.2
+version: 1.3
 package: std.code
 module:  magic
 class:   Plugin
 depends: None
 actions: collect
-enabled: True
+enabled: True

+ 14 - 5
metrixpp/ext/std/code/magic.py

@@ -28,16 +28,23 @@ class Plugin(api.Plugin,
     
     def initialize(self):
         pattern_to_search_java = re.compile(
-            r'''((const(\s+[_$a-zA-Z][_$a-zA-Z0-9]*)+\s*[=]\s*)[-+]?[0-9]+\b)|(\b[0-9]+\b)''')
-        pattern_to_search_cpp_cs = re.compile(
-            r'''((const(\s+[_a-zA-Z][_a-zA-Z0-9]*)+\s*[=]\s*)[-+]?[0-9]+\b)|(\b[0-9]+\b)''')
+            r'''((const(\s+[_$a-zA-Z][_$a-zA-Z0-9]*)+\s*[=]\s*)[-+]?[0-9]+\b)'''
+            r'''|(\b[0-9]+\b)''')
+        pattern_to_search_cpp = re.compile(
+            r'''((const(\s+[_a-zA-Z][_a-zA-Z0-9]*)+\s*[=]\s*)[-+]?[0-9]+\b)'''
+            r'''|(virtual\s+.*\s*[=]\s*[0]\s*[,;])'''
+            r'''|(override\s+[=]\s*[0]\s*[,;])'''
+            r'''|(\b[0-9]+\b)''')
+        pattern_to_search_cs = re.compile(
+            r'''((const(\s+[_a-zA-Z][_a-zA-Z0-9]*)+\s*[=]\s*)[-+]?[0-9]+\b)'''
+            r'''|(\b[0-9]+\b)''')
         self.declare_metric(self.is_active_numbers,
                             self.Field('numbers', int,
                                 non_zero=True),
                             {
                              'std.code.java': (pattern_to_search_java, self.NumbersCounter),
-                             'std.code.cpp': (pattern_to_search_cpp_cs, self.NumbersCounter),
-                             'std.code.cs': (pattern_to_search_cpp_cs, self.NumbersCounter),
+                             'std.code.cpp': (pattern_to_search_cpp, self.NumbersCounter),
+                             'std.code.cs': (pattern_to_search_cs, self.NumbersCounter),
                             },
                             marker_type_mask=api.Marker.T.CODE,
                             region_type_mask=api.Region.T.ANY)
@@ -51,6 +58,8 @@ class Plugin(api.Plugin,
     class NumbersCounter(api.MetricPluginMixin.IterIncrementCounter):
         def increment(self, match):
             if (match.group(0).startswith('const') or
+                match.group(0).startswith('virtual') or
+                match.group(0).startswith('override') or
                 (self.plugin.is_active_numbers_simplier == True and
                  match.group(0) in ['0', '1', '-1', '+1'])):
                 return 0

+ 1 - 1
metrixpp/tests/general/test_basic/test_workflow_info_default_stdout.gold.txt

@@ -8,7 +8,7 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.java:version: 1.1
 	std.code.java:files: *.java
 	std.code.lines:version: 1.1
-	std.code.magic:version: 1.2
+	std.code.magic:version: 1.3
 	std.code.magic:number.simplier: False
 	std.code.todo:version: 1.0
 	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX

+ 1 - 1
metrixpp/tests/general/test_basic/test_workflow_info_second_stdout.gold.txt

@@ -8,7 +8,7 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.java:version: 1.1
 	std.code.java:files: *.java
 	std.code.lines:version: 1.1
-	std.code.magic:version: 1.2
+	std.code.magic:version: 1.3
 	std.code.magic:number.simplier: False
 	std.code.todo:version: 1.0
 	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX

+ 1 - 1
metrixpp/tests/system/test_boost_parts/test_workflow_info_default_stdout.gold.txt

@@ -8,7 +8,7 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.java:version: 1.1
 	std.code.java:files: *.java
 	std.code.lines:version: 1.1
-	std.code.magic:version: 1.2
+	std.code.magic:version: 1.3
 	std.code.magic:number.simplier: False
 	std.code.todo:version: 1.0
 	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX