src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsCheckSyntax.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9279
e252f827aaa7
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsCheckSyntax.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsCheckSyntax.py	Wed Jul 13 14:55:47 2022 +0200
@@ -16,7 +16,7 @@
 def initService():
     """
     Initialize the service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     path = __file__
@@ -29,7 +29,7 @@
 def initBatchService():
     """
     Initialize the batch service and return the entry point.
-    
+
     @return the entry point for the background client (function)
     """
     return jsSyntaxBatchCheck
@@ -38,22 +38,22 @@
 def normalizeCode(codestring):
     """
     Function to normalize the given code.
-    
+
     @param codestring code to be normalized (string)
     @return normalized code (string)
     """
     codestring = codestring.replace("\r\n", "\n").replace("\r", "\n")
 
-    if codestring and codestring[-1] != '\n':
-        codestring += '\n'
-    
+    if codestring and codestring[-1] != "\n":
+        codestring += "\n"
+
     return codestring
 
 
 def jsSyntaxCheck(file, codestring):
     """
     Function to check a Javascript source file for syntax errors.
-    
+
     @param file source filename (string)
     @param codestring string containing the code to check (string)
     @return dictionary with the keys 'error' and 'warnings' which
@@ -67,7 +67,7 @@
 def jsSyntaxBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0):
     """
     Module function to check syntax for a batch of files.
-    
+
     @param argumentsList list of arguments tuples as given for jsSyntaxCheck
     @type list
     @param send reference to send function
@@ -101,9 +101,8 @@
 
     # Start worker processes
     workers = [
-        multiprocessing.Process(
-            target=workerTask, args=(taskQueue, doneQueue)
-        ) for _ in range(NumberOfProcesses)
+        multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue))
+        for _ in range(NumberOfProcesses)
     ]
     for worker in workers:
         worker.start()
@@ -113,7 +112,7 @@
     for i in range(len(argumentsList)):
         resultSent = False
         wasCancelled = False
-        
+
         while not resultSent:
             try:
                 # get result (waiting max. 3 seconds and send it to frontend
@@ -125,18 +124,18 @@
                 if cancelled():
                     wasCancelled = True
                     break
-        
+
         if wasCancelled or cancelled():
             # just exit the loop ignoring the results of queued tasks
             break
-        
+
         if i < endIndex:
             taskQueue.put(argumentsList[i + initialTasks])
 
     # Tell child processes to stop
     for _ in range(NumberOfProcesses):
-        taskQueue.put('STOP')
-    
+        taskQueue.put("STOP")
+
     for worker in workers:
         worker.join()
         worker.close()
@@ -145,11 +144,11 @@
 def workerTask(inputQueue, outputQueue):
     """
     Module function acting as the parallel worker for the syntax check.
-    
+
     @param inputQueue input queue (multiprocessing.Queue)
     @param outputQueue output queue (multiprocessing.Queue)
     """
-    for filename, args in iter(inputQueue.get, 'STOP'):
+    for filename, args in iter(inputQueue.get, "STOP"):
         source = args[0]
         result = __jsSyntaxCheck(filename, source)
         outputQueue.put((filename, result))
@@ -158,7 +157,7 @@
 def __jsSyntaxCheck(file, codestring):
     """
     Function to check a Javascript source file for syntax errors.
-    
+
     @param file source filename (string)
     @param codestring string containing the code to check (string)
     @return dictionary with the keys 'error' and 'warnings' which
@@ -168,9 +167,9 @@
     """
     import jasy.script.parse.Parser as jsParser
     import jasy.script.tokenize.Tokenizer as jsTokenizer
-    
+
     codestring = normalizeCode(codestring)
-    
+
     try:
         jsParser.parse(codestring, file)
     except (jsParser.SyntaxError, jsTokenizer.ParseError) as exc:
@@ -178,14 +177,23 @@
         error, details = details.splitlines()
         fn, line = details.strip().rsplit(":", 1)
         error = error.split(":", 1)[1].strip()
-        
+
         cline = min(len(codestring.splitlines()), int(line)) - 1
         code = codestring.splitlines()[cline]
-        return [{'error': (fn, int(line), 0, code, error)}]
+        return [{"error": (fn, int(line), 0, code, error)}]
     except IndexError:
         error = "Incomplete source file"
         splittedCode = codestring.splitlines()
-        return [{'error': (file, len(splittedCode) + 1, len(splittedCode[-1]),
-                           splittedCode[-1], error)}]
-    
+        return [
+            {
+                "error": (
+                    file,
+                    len(splittedCode) + 1,
+                    len(splittedCode[-1]),
+                    splittedCode[-1],
+                    error,
+                )
+            }
+        ]
+
     return [{}]

eric ide

mercurial