eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 7610
df7025fe26a3
parent 7360
9190402e4505
child 7611
d546c4e72f52
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Thu Jun 04 17:57:20 2020 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py	Sat Jun 06 19:42:15 2020 +0200
@@ -74,7 +74,13 @@
             line_number, offset, code, check, *args)
         if code and (self.counters[code] == 1 or self.__repeat):
             self.errors.append(
-                (self.filename, line_number, offset, (code, args))
+                {
+                    "file": self.filename,
+                    "line": line_number,
+                    "offset": offset,
+                    "code": code,
+                    "args": args,
+                }
             )
         return code
 
@@ -261,11 +267,21 @@
         annotationArgs, errors, eol, encoding, backup)
     @type list of (str, str, bool, str, str, bool, int, list of (int, int),
         bool, str, dict, dict, list of str, str, str, bool)
-    @return tuple of statistics (dict) and list of results (tuple for each
-        found violation of style (lineno, position, text, ignored, fixed,
-        autofixing, fixedMsg))
-    @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool,
-        str))
+    @return tuple of statistics data and list of result dictionaries with
+        keys:
+        <ul>
+        <li>file: file name</li>
+        <li>line: line_number</li>
+        <li>offset: offset within line</li>
+        <li>code: message code</li>
+        <li>args: list of arguments to format the message</li>
+        <li>ignored: flag indicating this issue was ignored</li>
+        <li>fixed: flag indicating this issue was fixed</li>
+        <li>autofixing: flag indicating that a fix can be done</li>
+        <li>fixcode: message code for the fix</li>
+        <li>fixargs: list of arguments to format the fix message</li>
+        </ul>
+    @rtype tuple of (dict, list of dict)
     """
     (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes,
      fixIssues, maxLineLength, maxDocLineLength, blankLines, hangClosing,
@@ -322,7 +338,7 @@
         report = styleGuide.check_files([filename])
         stats.update(report.counters)
         errors = report.errors
-
+        
         # check documentation style
         docStyleChecker = DocStyleChecker(
             source, filename, select, ignore, [], repeatMessages,
@@ -358,19 +374,19 @@
             errors += annotationsChecker.errors
     
     errorsDict = {}
-    for _fname, lineno, position, text in errors:
-        if lineno > len(source):
-            lineno = len(source)
+    for error in errors:
+        if error["line"] > len(source):
+            error["line"] = len(source)
         # inverse processing of messages and fixes
-        errorLine = errorsDict.setdefault(lineno, [])
-        errorLine.append([position, text])
+        errorLine = errorsDict.setdefault(error["line"], [])
+        errorLine.append((error["offset"], error))
     deferredFixes = {}
     results = []
-    for lineno, errors in errorsDict.items():
-        errors.sort(key=lambda x: x[0], reverse=True)
-        for position, text in errors:
+    for lineno, errorsList in errorsDict.items():
+        errorsList.sort(key=lambda x: x[0], reverse=True)
+        for _, error in errorsList:
             if source:
-                code = text[0]
+                code = error["code"]
                 lineFlags = extractLineFlags(source[lineno - 1].strip())
                 try:
                     lineFlags += extractLineFlags(source[lineno].strip(),
@@ -379,35 +395,66 @@
                     pass
                 if not ignoreCode(code, lineFlags):
                     if fixer:
-                        res, msg, id_ = fixer.fixIssue(lineno, position, text)
+                        pass
+                        res, fixcode, fixargs, id_ = fixer.fixIssue(
+                            lineno, error["offset"], code)
                         if res == -1:
-                            itm = [lineno, position, text]
-                            deferredFixes[id_] = itm
+                            deferredFixes[id_] = error
                         else:
-                            itm = [lineno, position, text, False,
-                                   res == 1, True, msg]
+                            error.update({
+                                "ignored": False,
+                                "fixed": res == 1,
+                                "autofixing": True,
+                                "fixcode": fixcode,
+                                "fixargs": fixargs,
+                            })
                     else:
-                        itm = [lineno, position, text, False,
-                               False, False, '']
-                    results.append(itm)
+                        error.update({
+                            "ignored": False,
+                            "fixed": False,
+                            "autofixing": False,
+                            "fixcode": "",
+                            "fixargs": [],
+                        })
                 else:
-                    results.append([lineno, position, text, True,
-                                    False, False, ''])
+                    error.update({
+                        "ignored": True,
+                        "fixed": False,
+                        "autofixing": False,
+                        "fixcode": "",
+                        "fixargs": [],
+                    })
             else:
-                results.append([lineno, position, text, False,
-                                False, False, ''])
+                error.update({
+                    "ignored": False,
+                    "fixed": False,
+                    "autofixing": False,
+                    "fixcode": "",
+                    "fixargs": [],
+                })
+            
+            results.append(error)
     
     if fixer:
         deferredResults = fixer.finalize()
         for id_ in deferredResults:
-            fixed, msg = deferredResults[id_]
-            itm = deferredFixes[id_]
-            itm.extend([False, fixed == 1, True, msg])
+            fixed, fixcode, fixargs = deferredResults[id_]
+            error = deferredFixes[id_]
+            error.update({
+                "ignored": False,
+                "fixed": fixed == 1,
+                "autofixing": True,
+                "fixcode": fixcode,
+                "fixargs": fixargs,
+            })
 
-        errMsg = fixer.saveFile(encoding)
-        if errMsg:
-            for result in results:
-                result[-1] = errMsg
+        saveError = fixer.saveFile(encoding)
+        if saveError:
+            for error in results:
+                error.update({
+                    "fixcode": saveError[0],
+                    "fixargs": saveError[1],
+                })
 
     return stats, results
 

eric ide

mercurial