Sat, 25 Nov 2023 18:19:21 +0100
Syntax Checker
- Re-introduced the JavaScript syntax checker. This time it is based on the `esprima` package.
--- a/docs/changelog.md Fri Nov 24 14:59:26 2023 +0100 +++ b/docs/changelog.md Sat Nov 25 18:19:21 2023 +0100 @@ -30,6 +30,8 @@ plugins. - Syntax Checker - Added code to show some per file and overall statistics of the check. + - Re-introduced the JavaScript syntax checker. This time it is based on + the `esprima` package. ### Version 23.11 - bug fixes
--- a/eric7.epj Fri Nov 24 14:59:26 2023 +0100 +++ b/eric7.epj Sat Nov 25 18:19:21 2023 +0100 @@ -1550,6 +1550,7 @@ "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py", "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py", "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/__init__.py", + "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsCheckSyntax.py", "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsonCheckSyntax.py", "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyCheckSyntax.py", "src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/__init__.py",
--- a/pyproject.toml Fri Nov 24 14:59:26 2023 +0100 +++ b/pyproject.toml Sat Nov 25 18:19:21 2023 +0100 @@ -66,6 +66,7 @@ "PyQt6-QScintilla>=2.13.0", "docutils", "Markdown", + "esprima", "pyyaml", "tomlkit", "chardet", @@ -83,7 +84,6 @@ "coverage>=6.5.0", "semver", "pipdeptree", - "importlib-metadata; python_version<'3.8'", "pywin32>=1.0;platform_system=='Windows'", ] dynamic = ["version"]
--- a/scripts/install-dependencies.py Fri Nov 24 14:59:26 2023 +0100 +++ b/scripts/install-dependencies.py Sat Nov 25 18:19:21 2023 +0100 @@ -85,6 +85,7 @@ "chardet", "pyenchant", "wheel", + "esprima", ) packages = []
--- a/scripts/install.py Fri Nov 24 14:59:26 2023 +0100 +++ b/scripts/install.py Sat Nov 25 18:19:21 2023 +0100 @@ -1643,6 +1643,7 @@ "chardet": ("chardet", ""), "pyenchant": ("enchant", ""), "wheel": ("wheel", ""), + "esprima": ("esprima", ""), } if withPyqt6Tools: optionalModulesList["qt6-applications"] = ("qt6_applications", "")
--- a/src/eric7/APIs/Python3/eric7.api Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/APIs/Python3/eric7.api Sat Nov 25 18:19:21 2023 +0100 @@ -4865,6 +4865,11 @@ eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.SyntaxCheckerDialog.startForBrowser?4(fn) eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.SyntaxCheckerDialog.warningRole?7 eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.SyntaxCheckerDialog?1(parent=None) +eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.initBatchService?4() +eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.initService?4() +eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.jsSyntaxBatchCheck?4(argumentsList, send, fx, cancelled, maxProcesses=0) +eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.jsSyntaxCheck?4(file, codestring) +eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.workerTask?4(inputQueue, outputQueue) eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.initBatchService?4() eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.initService?4() eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.jsonSyntaxBatchCheck?4(argumentsList, send, fx, cancelled, maxProcesses=0)
--- a/src/eric7/Documentation/Help/source.qhp Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Help/source.qhp Sat Nov 25 18:19:21 2023 +0100 @@ -519,6 +519,7 @@ <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker" ref="index-eric7.Plugins.CheckerPlugins.SyntaxChecker.html"> <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService.html" /> <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.html" /> + <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html" /> <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html" /> <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html" /> <section title="eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html" /> @@ -19427,6 +19428,7 @@ <keyword name="__initChannelModesDict" id="__initChannelModesDict" ref="eric7.Network.IRC.IrcUtilities.html#__initChannelModesDict" /> <keyword name="__init__" id="__init__" ref="eric7.Plugins.WizardPlugins.EricPluginWizard.Templates.html#__init__" /> <keyword name="__initializeCondaInterface" id="__initializeCondaInterface" ref="eric7.CondaInterface.__init__.html#__initializeCondaInterface" /> + <keyword name="__jsSyntaxCheck" id="__jsSyntaxCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#__jsSyntaxCheck" /> <keyword name="__jsonSyntaxCheck" id="__jsonSyntaxCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#__jsonSyntaxCheck" /> <keyword name="__main__ (Module)" id="__main__ (Module)" ref="eric7.__main__.html" /> <keyword name="__mapType" id="__mapType" ref="eric7.Project.UicLoadUi5.html#__mapType" /> @@ -20185,6 +20187,7 @@ <keyword name="indentation" id="indentation" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.pycodestyle.html#indentation" /> <keyword name="information" id="information" ref="eric7.EricWidgets.EricMessageBox.html#information" /> <keyword name="initBatchService" id="initBatchService" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html#initBatchService" /> + <keyword name="initBatchService" id="initBatchService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#initBatchService" /> <keyword name="initBatchService" id="initBatchService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#initBatchService" /> <keyword name="initBatchService" id="initBatchService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html#initBatchService" /> <keyword name="initBatchService" id="initBatchService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html#initBatchService" /> @@ -20194,6 +20197,7 @@ <keyword name="initRecentSettings" id="initRecentSettings" ref="eric7.Preferences.__init__.html#initRecentSettings" /> <keyword name="initSSL" id="initSSL" ref="eric7.EricNetwork.EricSslUtilities.html#initSSL" /> <keyword name="initService" id="initService" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html#initService" /> + <keyword name="initService" id="initService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#initService" /> <keyword name="initService" id="initService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#initService" /> <keyword name="initService" id="initService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html#initService" /> <keyword name="initService" id="initService" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html#initService" /> @@ -20248,6 +20252,9 @@ <keyword name="isinpath" id="isinpath" ref="eric7.SystemUtilities.FileSystemUtilities.html#isinpath" /> <keyword name="jinja2Templates (Module)" id="jinja2Templates (Module)" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.Checks.jinja2Templates.html" /> <keyword name="joinext" id="joinext" ref="eric7.SystemUtilities.FileSystemUtilities.html#joinext" /> + <keyword name="jsCheckSyntax (Module)" id="jsCheckSyntax (Module)" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html" /> + <keyword name="jsSyntaxBatchCheck" id="jsSyntaxBatchCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#jsSyntaxBatchCheck" /> + <keyword name="jsSyntaxCheck" id="jsSyntaxCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#jsSyntaxCheck" /> <keyword name="jsonCheckSyntax (Module)" id="jsonCheckSyntax (Module)" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html" /> <keyword name="jsonSyntaxBatchCheck" id="jsonSyntaxBatchCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#jsonSyntaxBatchCheck" /> <keyword name="jsonSyntaxCheck" id="jsonSyntaxCheck" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#jsonSyntaxCheck" /> @@ -20608,6 +20615,7 @@ <keyword name="windowsDesktopEntries" id="windowsDesktopEntries" ref="eric7.eric7_post_install.html#windowsDesktopEntries" /> <keyword name="windowsProgramsEntry" id="windowsProgramsEntry" ref="eric7.eric7_post_install.html#windowsProgramsEntry" /> <keyword name="workerTask" id="workerTask" ref="eric7.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleChecker.html#workerTask" /> + <keyword name="workerTask" id="workerTask" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html#workerTask" /> <keyword name="workerTask" id="workerTask" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html#workerTask" /> <keyword name="workerTask" id="workerTask" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html#workerTask" /> <keyword name="workerTask" id="workerTask" ref="eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html#workerTask" /> @@ -21022,6 +21030,7 @@ <file>eric7.Plugins.CheckerPlugins.CodeStyleChecker.translations.html</file> <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService.html</file> <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.html</file> + <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html</file> <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html</file> <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html</file> <file>eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html</file>
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService.html Sat Nov 25 18:19:21 2023 +0100 @@ -164,19 +164,25 @@ </p> <dl> -<dt><i>filename</i></dt> +<dt><i>filename</i> (str)</dt> <dd> -of the sourcefile (str) +of the sourcefile </dd> -<dt><i>source</i></dt> +<dt><i>source</i> (str)</dt> <dd> -code of the file (str) +code of the file </dd> </dl> <dl> <dt>Return:</dt> <dd> -language of the file or None if not found (str or None) +language of the file or None if not found +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +str or None </dd> </dl> <a NAME="SyntaxCheckService.__serviceError" ID="SyntaxCheckService.__serviceError"></a> @@ -188,13 +194,13 @@ </p> <dl> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.addLanguage" ID="SyntaxCheckService.addLanguage"></a> @@ -206,40 +212,39 @@ </p> <dl> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -new language to check syntax (str) +new language to check syntax </dd> -<dt><i>env</i></dt> +<dt><i>env</i> (str)</dt> <dd> -the environment in which the checker is implemented (str) +the environment in which the checker is implemented </dd> -<dt><i>path</i></dt> +<dt><i>path</i> (str)</dt> <dd> -full path to the module (str) +full path to the module </dd> -<dt><i>module</i></dt> +<dt><i>module</i> (str)</dt> <dd> -name to import (str) +name to import </dd> -<dt><i>getArgs</i></dt> +<dt><i>getArgs</i> (function)</dt> <dd> function to collect the required arguments to call the - syntax checker on client side (function) + syntax checker on client side </dd> -<dt><i>getExt</i></dt> +<dt><i>getExt</i> (function)</dt> <dd> function that returns the supported file extensions of - the syntax checker (function) + the syntax checker </dd> -<dt><i>callback</i></dt> +<dt><i>callback</i> (function)</dt> <dd> -function on service response (function) +function on service response </dd> -<dt><i>onError</i></dt> +<dt><i>onError</i> (function)</dt> <dd> callback function if client or service isn't available - (function) </dd> </dl> <a NAME="SyntaxCheckService.batchJobDone" ID="SyntaxCheckService.batchJobDone"></a> @@ -251,13 +256,13 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> </dl> <a NAME="SyntaxCheckService.cancelSyntaxBatchCheck" ID="SyntaxCheckService.cancelSyntaxBatchCheck"></a> @@ -278,7 +283,13 @@ <dl> <dt>Return:</dt> <dd> -set of all supported file extensions (set of str) +set of all supported file extensions +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +set of str </dd> </dl> <a NAME="SyntaxCheckService.getLanguages" ID="SyntaxCheckService.getLanguages"></a> @@ -291,7 +302,13 @@ <dl> <dt>Return:</dt> <dd> -list of languanges supported (list of str) +list of languanges supported +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +list of str </dd> </dl> <a NAME="SyntaxCheckService.removeLanguage" ID="SyntaxCheckService.removeLanguage"></a> @@ -303,9 +320,9 @@ </p> <dl> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language to remove (str) +language to remove </dd> </dl> <a NAME="SyntaxCheckService.serviceErrorJSON" ID="SyntaxCheckService.serviceErrorJSON"></a> @@ -317,21 +334,21 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.serviceErrorJavaScript" ID="SyntaxCheckService.serviceErrorJavaScript"></a> @@ -343,21 +360,21 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.serviceErrorPy3" ID="SyntaxCheckService.serviceErrorPy3"></a> @@ -369,21 +386,21 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.serviceErrorTOML" ID="SyntaxCheckService.serviceErrorTOML"></a> @@ -395,21 +412,21 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.serviceErrorYAML" ID="SyntaxCheckService.serviceErrorYAML"></a> @@ -421,21 +438,21 @@ </p> <dl> -<dt><i>fx</i></dt> +<dt><i>fx</i> (str)</dt> <dd> -service name (string) +service name </dd> -<dt><i>lang</i></dt> +<dt><i>lang</i> (str)</dt> <dd> -language (string) +language </dd> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -file name (string) +file name </dd> -<dt><i>msg</i></dt> +<dt><i>msg</i> (str)</dt> <dd> -message text (string) +message text </dd> </dl> <a NAME="SyntaxCheckService.syntaxBatchCheck" ID="SyntaxCheckService.syntaxBatchCheck"></a> @@ -447,10 +464,10 @@ </p> <dl> -<dt><i>argumentsList</i></dt> +<dt><i>argumentsList</i> (list of tuples of (str, str))</dt> <dd> -list of arguments tuples with each tuple - containing filename and source (string, string) +list of argument tuples with each tuple + containing filename and source </dd> </dl> <a NAME="SyntaxCheckService.syntaxCheck" ID="SyntaxCheckService.syntaxCheck"></a>
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog.html Sat Nov 25 18:19:21 2023 +0100 @@ -368,12 +368,14 @@ <dd> filename of the checked file </dd> -<dt><i>problems</i> (dict)</dt> +<dt><i>problems</i> (list of dict)</dt> <dd> -dictionary with the keys 'error', 'py_warnings' and - 'warnings' which hold a list containing details about the error or - warnings (file name, line number, column, codestring (only at syntax - errors), message) +list of dictionaries with the keys 'error', 'py_warnings' and + 'warnings' which contain a tuple with details about the syntax error or a + list of tuples with details about Python warnings and PyFlakes warnings. + Each tuple contains the file name, line number, column, code string (only + for syntax errors), the message and an optional list with arguments for + the message. </dd> </dl> <a NAME="SyntaxCheckerDialog.__resetStatistics" ID="SyntaxCheckerDialog.__resetStatistics"></a>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html Sat Nov 25 18:19:21 2023 +0100 @@ -0,0 +1,222 @@ +<!DOCTYPE html> +<html><head> +<title>eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax</title> +<meta charset="UTF-8"> +<link rel="stylesheet" href="styles.css"> +</head> +<body> +<a NAME="top" ID="top"></a> +<h1>eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax</h1> + +<p> +Module implementing the syntax check for JavaScript. +</p> +<h3>Global Attributes</h3> + +<table> +<tr><td>None</td></tr> +</table> +<h3>Classes</h3> + +<table> +<tr><td>None</td></tr> +</table> +<h3>Functions</h3> + +<table> + +<tr> +<td><a href="#__jsSyntaxCheck">__jsSyntaxCheck</a></td> +<td>Function to check a JavaScript source file for syntax errors.</td> +</tr> +<tr> +<td><a href="#initBatchService">initBatchService</a></td> +<td>Initialize the batch service and return the entry point.</td> +</tr> +<tr> +<td><a href="#initService">initService</a></td> +<td>Initialize the service and return the entry point.</td> +</tr> +<tr> +<td><a href="#jsSyntaxBatchCheck">jsSyntaxBatchCheck</a></td> +<td>Module function to check syntax for a batch of files.</td> +</tr> +<tr> +<td><a href="#jsSyntaxCheck">jsSyntaxCheck</a></td> +<td>Function to check a Javascript source file for syntax errors.</td> +</tr> +<tr> +<td><a href="#workerTask">workerTask</a></td> +<td>Module function acting as the parallel worker for the syntax check.</td> +</tr> +</table> +<hr /> +<hr /> +<a NAME="__jsSyntaxCheck" ID="__jsSyntaxCheck"></a> +<h2>__jsSyntaxCheck</h2> +<b>__jsSyntaxCheck</b>(<i>file, codestring</i>) + +<p> + Function to check a JavaScript source file for syntax errors. +</p> +<dl> + +<dt><i>file</i> (str)</dt> +<dd> +source filename +</dd> +<dt><i>codestring</i> (str)</dt> +<dd> +string containing the code to check +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +list of dict +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="initBatchService" ID="initBatchService"></a> +<h2>initBatchService</h2> +<b>initBatchService</b>(<i></i>) + +<p> + Initialize the batch service and return the entry point. +</p> +<dl> +<dt>Return:</dt> +<dd> +the entry point for the background client +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +function +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="initService" ID="initService"></a> +<h2>initService</h2> +<b>initService</b>(<i></i>) + +<p> + Initialize the service and return the entry point. +</p> +<dl> +<dt>Return:</dt> +<dd> +the entry point for the background client +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +function +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="jsSyntaxBatchCheck" ID="jsSyntaxBatchCheck"></a> +<h2>jsSyntaxBatchCheck</h2> +<b>jsSyntaxBatchCheck</b>(<i>argumentsList, send, fx, cancelled, maxProcesses=0</i>) + +<p> + Module function to check syntax for a batch of files. +</p> +<dl> + +<dt><i>argumentsList</i> (list)</dt> +<dd> +list of arguments tuples as given for jsSyntaxCheck +</dd> +<dt><i>send</i> (function)</dt> +<dd> +reference to send function +</dd> +<dt><i>fx</i> (str)</dt> +<dd> +registered service name +</dd> +<dt><i>cancelled</i> (function)</dt> +<dd> +reference to function checking for a cancellation +</dd> +<dt><i>maxProcesses</i> (int)</dt> +<dd> +number of processes to be used +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="jsSyntaxCheck" ID="jsSyntaxCheck"></a> +<h2>jsSyntaxCheck</h2> +<b>jsSyntaxCheck</b>(<i>file, codestring</i>) + +<p> + Function to check a Javascript source file for syntax errors. +</p> +<dl> + +<dt><i>file</i> (str)</dt> +<dd> +source filename +</dd> +<dt><i>codestring</i> (str)</dt> +<dd> +string containing the code to check +</dd> +</dl> +<dl> +<dt>Return:</dt> +<dd> +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +list of dict +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +<hr /> +<a NAME="workerTask" ID="workerTask"></a> +<h2>workerTask</h2> +<b>workerTask</b>(<i>inputQueue, outputQueue</i>) + +<p> + Module function acting as the parallel worker for the syntax check. +</p> +<dl> + +<dt><i>inputQueue</i> (multiprocessing.Queue)</dt> +<dd> +input queue +</dd> +<dt><i>outputQueue</i> (multiprocessing.Queue)</dt> +<dd> +output queue +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /> +</body></html> \ No newline at end of file
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html Sat Nov 25 18:19:21 2023 +0100 @@ -73,16 +73,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -104,7 +103,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -126,7 +125,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -143,9 +142,9 @@ <dt><i>argumentsList</i> (list)</dt> <dd> -list of arguments tuples as given for yamlSyntaxCheck +list of arguments tuples as given for jsonSyntaxCheck </dd> -<dt><i>send</i> (func)</dt> +<dt><i>send</i> (function)</dt> <dd> reference to send function </dd> @@ -153,7 +152,7 @@ <dd> registered service name </dd> -<dt><i>cancelled</i> (func)</dt> +<dt><i>cancelled</i> (function)</dt> <dd> reference to function checking for a cancellation </dd> @@ -186,16 +185,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div>
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.pyCheckSyntax.html Sat Nov 25 18:19:21 2023 +0100 @@ -95,17 +95,17 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error', 'py_warnings' and 'warnings' which - hold a list containing details about the syntax error, Python warnings - and PyFlakes warnings (file name, line number, column, codestring (only - for syntax errors), the message and an optional list with arguments for - the message) +list of dictionaries with the keys 'error', 'py_warnings' and 'warnings' + which contain a tuple with details about the syntax error or a list of + tuples with details about Python warnings and PyFlakes warnings. Each tuple + contains the file name, line number, column, code string (only for syntax + errors), the message and an optional list with arguments for the message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -210,7 +210,7 @@ <dd> list of arguments tuples as given for pySyntaxAndPyflakesCheck </dd> -<dt><i>send</i> (func)</dt> +<dt><i>send</i> (function)</dt> <dd> reference to send function </dd> @@ -218,7 +218,7 @@ <dd> registered service name </dd> -<dt><i>cancelled</i> (func)</dt> +<dt><i>cancelled</i> (function)</dt> <dd> reference to function checking for a cancellation </dd> @@ -264,17 +264,17 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error', 'py_warnings' and 'warnings' which - hold a list containing details about the syntax error, Python warnings - and PyFlakes warnings (file name, line number, column, codestring (only - for syntax errors), the message and an optional list with arguments for - the message) +list of dictionaries with the keys 'error', 'py_warnings' and 'warnings' + which contain a tuple with details about the syntax error or a list of + tuples with details about Python warnings and PyFlakes warnings. Each tuple + contains the file name, line number, column, code string (only for syntax + errors), the message and an optional list with arguments for the message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div>
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.tomlCheckSyntax.html Sat Nov 25 18:19:21 2023 +0100 @@ -73,16 +73,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -104,7 +103,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -126,7 +125,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -145,7 +144,7 @@ <dd> list of arguments tuples as given for tomlSyntaxCheck </dd> -<dt><i>send</i> (func)</dt> +<dt><i>send</i> (function)</dt> <dd> reference to send function </dd> @@ -153,7 +152,7 @@ <dd> registered service name </dd> -<dt><i>cancelled</i> (func)</dt> +<dt><i>cancelled</i> (function)</dt> <dd> reference to function checking for a cancellation </dd> @@ -186,16 +185,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div>
--- a/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.yamlCheckSyntax.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.SyntaxChecker.yamlCheckSyntax.html Sat Nov 25 18:19:21 2023 +0100 @@ -73,16 +73,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -104,7 +103,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -126,7 +125,7 @@ <dl> <dt>Return Type:</dt> <dd> -func +function </dd> </dl> <div align="right"><a href="#top">Up</a></div> @@ -166,7 +165,7 @@ <dd> list of arguments tuples as given for yamlSyntaxCheck </dd> -<dt><i>send</i> (func)</dt> +<dt><i>send</i> (function)</dt> <dd> reference to send function </dd> @@ -174,7 +173,7 @@ <dd> registered service name </dd> -<dt><i>cancelled</i> (func)</dt> +<dt><i>cancelled</i> (function)</dt> <dd> reference to function checking for a cancellation </dd> @@ -207,16 +206,15 @@ <dl> <dt>Return:</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. </dd> </dl> <dl> <dt>Return Type:</dt> <dd> -dict +list of dict </dd> </dl> <div align="right"><a href="#top">Up</a></div>
--- a/src/eric7/Documentation/Source/eric7.Plugins.PluginSyntaxChecker.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/eric7.Plugins.PluginSyntaxChecker.html Sat Nov 25 18:19:21 2023 +0100 @@ -126,9 +126,9 @@ </p> <dl> -<dt><i>ui</i></dt> +<dt><i>ui</i> (UI.UserInterface)</dt> <dd> -reference to the user interface object (UI.UserInterface) +reference to the user interface object </dd> </dl> <a NAME="SyntaxCheckerPlugin.__editorClosed" ID="SyntaxCheckerPlugin.__editorClosed"></a> @@ -140,9 +140,9 @@ </p> <dl> -<dt><i>editor</i></dt> +<dt><i>editor</i> (QScintilla.Editor)</dt> <dd> -reference to the editor (QScintilla.Editor) +reference to the editor </dd> </dl> <a NAME="SyntaxCheckerPlugin.__editorOpened" ID="SyntaxCheckerPlugin.__editorOpened"></a> @@ -154,9 +154,9 @@ </p> <dl> -<dt><i>editor</i></dt> +<dt><i>editor</i> (QScintilla.Editor)</dt> <dd> -reference to the new editor (QScintilla.Editor) +reference to the new editor </dd> </dl> <a NAME="SyntaxCheckerPlugin.__editorShowMenu" ID="SyntaxCheckerPlugin.__editorShowMenu"></a> @@ -169,15 +169,15 @@ </p> <dl> -<dt><i>menuName</i></dt> +<dt><i>menuName</i> (str)</dt> <dd> -name of the menu to be shown (string) +name of the menu to be shown </dd> -<dt><i>menu</i></dt> +<dt><i>menu</i> (QMenu)</dt> <dd> -reference to the menu (QMenu) +reference to the menu </dd> -<dt><i>editor</i></dt> +<dt><i>editor</i> (QScintilla.Editor)</dt> <dd> reference to the editor </dd> @@ -227,13 +227,13 @@ </p> <dl> -<dt><i>menuName</i></dt> +<dt><i>menuName</i> (str)</dt> <dd> -name of the menu to be shown (string) +name of the menu to be shown </dd> -<dt><i>menu</i></dt> +<dt><i>menu</i> (QMenu)</dt> <dd> -reference to the menu (QMenu) +reference to the menu </dd> </dl> <a NAME="SyntaxCheckerPlugin.__projectBrowserSyntaxCheck" ID="SyntaxCheckerPlugin.__projectBrowserSyntaxCheck"></a> @@ -254,13 +254,13 @@ </p> <dl> -<dt><i>menuName</i></dt> +<dt><i>menuName</i> (str)</dt> <dd> -name of the menu to be shown (string) +name of the menu to be shown </dd> -<dt><i>menu</i></dt> +<dt><i>menu</i> (QMenu)</dt> <dd> -reference to the menu (QMenu) +reference to the menu </dd> </dl> <a NAME="SyntaxCheckerPlugin.__projectSyntaxCheck" ID="SyntaxCheckerPlugin.__projectSyntaxCheck"></a> @@ -284,16 +284,18 @@ </p> <dl> -<dt><i>fn</i></dt> +<dt><i>fn</i> (str)</dt> <dd> -filename of the checked file (str) +filename of the checked file </dd> -<dt><i>problems</i></dt> +<dt><i>problems</i> (list of dict)</dt> <dd> -dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) +list of dictionaries with the keys 'error', 'py_warnings' and + 'warnings' which contain a tuple with details about the syntax error or a + list of tuples with details about Python warnings and PyFlakes warnings. + Each tuple contains the file name, line number, column, code string (only + for syntax errors), the message and an optional list with arguments for + the message. </dd> </dl> <a NAME="SyntaxCheckerPlugin.activate" ID="SyntaxCheckerPlugin.activate"></a> @@ -306,7 +308,13 @@ <dl> <dt>Return:</dt> <dd> -tuple of None and activation status (boolean) +tuple of None and activation status +</dd> +</dl> +<dl> +<dt>Return Type:</dt> +<dd> +bool </dd> </dl> <a NAME="SyntaxCheckerPlugin.deactivate" ID="SyntaxCheckerPlugin.deactivate"></a>
--- a/src/eric7/Documentation/Source/index-eric7.Plugins.CheckerPlugins.SyntaxChecker.html Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Documentation/Source/index-eric7.Plugins.CheckerPlugins.SyntaxChecker.html Sat Nov 25 18:19:21 2023 +0100 @@ -24,6 +24,10 @@ <td>Module implementing a simple Python syntax checker.</td> </tr> <tr> +<td><a href="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsCheckSyntax.html">jsCheckSyntax</a></td> +<td>Module implementing the syntax check for JavaScript.</td> +</tr> +<tr> <td><a href="eric7.Plugins.CheckerPlugins.SyntaxChecker.jsonCheckSyntax.html">jsonCheckSyntax</a></td> <td>Module implementing the syntax check for JSON.</td> </tr>
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py Sat Nov 25 18:19:21 2023 +0100 @@ -48,9 +48,12 @@ """ Private method to determine the language of the file. - @param filename of the sourcefile (str) - @param source code of the file (str) - @return language of the file or None if not found (str or None) + @param filename of the sourcefile + @type str + @param source code of the file + @type str + @return language of the file or None if not found + @rtype str or None """ pyVer = PythonUtilities.determinePythonVersion(filename, source) if pyVer: @@ -66,17 +69,24 @@ """ Public method to register a new language to the supported languages. - @param lang new language to check syntax (str) - @param env the environment in which the checker is implemented (str) - @param path full path to the module (str) - @param module name to import (str) + @param lang new language to check syntax + @type str + @param env the environment in which the checker is implemented + @type str + @param path full path to the module + @type str + @param module name to import + @type str @param getArgs function to collect the required arguments to call the - syntax checker on client side (function) + syntax checker on client side + @type function @param getExt function that returns the supported file extensions of - the syntax checker (function) - @param callback function on service response (function) + the syntax checker + @type function + @param callback function on service response + @type function @param onError callback function if client or service isn't available - (function) + @type function """ self.__supportedLanguages[lang] = env, getArgs, getExt # Connect to the background service @@ -94,7 +104,8 @@ """ Public method to return the supported language names. - @return list of languanges supported (list of str) + @return list of languanges supported + @rtype list of str """ return list(self.__supportedLanguages.keys()) + ["MicroPython"] @@ -102,7 +113,8 @@ """ Public method to remove the language from syntax check. - @param lang language to remove (str) + @param lang language to remove + @type str """ self.__supportedLanguages.pop(lang, None) self.backgroundService.serviceDisconnect("{0}Syntax".format(lang), lang) @@ -112,7 +124,8 @@ Public method to return all supported file extensions for the syntax checker dialog. - @return set of all supported file extensions (set of str) + @return set of all supported file extensions + @rtype set of str """ extensions = set() for _env, _getArgs, getExt in self.__supportedLanguages.values(): @@ -154,8 +167,9 @@ """ Public method to prepare a syntax check on multiple source files. - @param argumentsList list of arguments tuples with each tuple - containing filename and source (string, string) + @param argumentsList list of argument tuples with each tuple + containing filename and source + @type list of tuples of (str, str) """ data = {} for lang in self.getLanguages(): @@ -203,8 +217,10 @@ """ Private slot handling service errors. - @param fn file name (string) - @param msg message text (string) + @param fn file name + @type str + @param msg message text + @type str """ self.error.emit(fn, msg) @@ -212,10 +228,14 @@ """ Public method handling service errors for Python 3. - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) + @param fx service name + @type str + @param lang language + @type str + @param fn file name + @type str + @param msg message text + @type str """ if fx in ["Python3Syntax", "batch_Python3Syntax"]: if fx == "Python3Syntax": @@ -228,10 +248,14 @@ """ Public method handling service errors for JavaScript. - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) + @param fx service name + @type str + @param lang language + @type str + @param fn file name + @type str + @param msg message text + @type str """ if fx in ["JavaScriptSyntax", "batch_JavaScriptSyntax"]: if fx == "JavaScriptSyntax": @@ -244,10 +268,14 @@ """ Public method handling service errors for YAML. - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) + @param fx service name + @type str + @param lang language + @type str + @param fn file name + @type str + @param msg message text + @type str """ if fx in ["YAMLSyntax", "batch_YAMLSyntax"]: if fx == "YAMLSyntax": @@ -260,10 +288,14 @@ """ Public method handling service errors for JSON. - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) + @param fx service name + @type str + @param lang language + @type str + @param fn file name + @type str + @param msg message text + @type str """ if fx in ["JSONSyntax", "batch_JSONSyntax"]: if fx == "JSONSyntax": @@ -276,10 +308,14 @@ """ Public method handling service errors for TOML. - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) + @param fx service name + @type str + @param lang language + @type str + @param fn file name + @type str + @param msg message text + @type str """ if fx in ["TOMLSyntax", "batch_TOMLSyntax"]: if fx == "TOMLSyntax": @@ -292,8 +328,10 @@ """ Public slot handling the completion of a batch job. - @param fx service name (string) - @param lang language (string) + @param fx service name + @type str + @param lang language + @type str """ if fx in [ "Python3Syntax",
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py Sat Nov 25 18:19:21 2023 +0100 @@ -506,11 +506,13 @@ @param fn filename of the checked file @type str - @param problems dictionary with the keys 'error', 'py_warnings' and - 'warnings' which hold a list containing details about the error or - warnings (file name, line number, column, codestring (only at syntax - errors), message) - @type dict + @param problems list of dictionaries with the keys 'error', 'py_warnings' and + 'warnings' which contain a tuple with details about the syntax error or a + list of tuples with details about Python warnings and PyFlakes warnings. + Each tuple contains the file name, line number, column, code string (only + for syntax errors), the message and an optional list with arguments for + the message. + @type list of dict """ if self.__finished: return
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsCheckSyntax.py Sat Nov 25 18:19:21 2023 +0100 @@ -0,0 +1,180 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> +# Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the syntax check for JavaScript. +""" + +import multiprocessing +import queue + + +def initService(): + """ + Initialize the service and return the entry point. + + @return the entry point for the background client + @rtype function + """ + return jsSyntaxCheck + + +def initBatchService(): + """ + Initialize the batch service and return the entry point. + + @return the entry point for the background client + @rtype function + """ + return jsSyntaxBatchCheck + + +def jsSyntaxCheck(file, codestring): + """ + Function to check a Javascript source file for syntax errors. + + @param file source filename + @type str + @param codestring string containing the code to check + @type str + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict + """ + return __jsSyntaxCheck(file, codestring) + + +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 + @type function + @param fx registered service name + @type str + @param cancelled reference to function checking for a cancellation + @type function + @param maxProcesses number of processes to be used + @type int + """ + if maxProcesses == 0: + # determine based on CPU count + try: + NumberOfProcesses = multiprocessing.cpu_count() + if NumberOfProcesses >= 1: + NumberOfProcesses -= 1 + except NotImplementedError: + NumberOfProcesses = 1 + else: + NumberOfProcesses = maxProcesses + + # Create queues + taskQueue = multiprocessing.Queue() + doneQueue = multiprocessing.Queue() + + # Submit tasks (initially two time number of processes + tasks = len(argumentsList) + initialTasks = 2 * NumberOfProcesses + for _ in range(initialTasks): + taskQueue.put(argumentsList.pop(0)) + + # Start worker processes + workers = [ + multiprocessing.Process(target=workerTask, args=(taskQueue, doneQueue)) + for _ in range(NumberOfProcesses) + ] + for worker in workers: + worker.start() + + # Get and send results + for _ in range(tasks): + resultSent = False + wasCancelled = False + + while not resultSent: + try: + # get result (waiting max. 3 seconds and send it to frontend + filename, result = doneQueue.get() + send(fx, filename, result) + resultSent = True + except queue.Empty: + # ignore empty queue, just carry on + if cancelled(): + wasCancelled = True + break + + if wasCancelled or cancelled(): + # just exit the loop ignoring the results of queued tasks + break + + if argumentsList: + taskQueue.put(argumentsList.pop(0)) + + # Tell child processes to stop + for _ in range(NumberOfProcesses): + taskQueue.put("STOP") + + for worker in workers: + worker.join() + worker.close() + + taskQueue.close() + doneQueue.close() + + +def workerTask(inputQueue, outputQueue): + """ + Module function acting as the parallel worker for the syntax check. + + @param inputQueue input queue + @type multiprocessing.Queue + @param outputQueue output queue + @type multiprocessing.Queue + """ + for filename, args in iter(inputQueue.get, "STOP"): + source = args[0] + result = __jsSyntaxCheck(filename, source) + outputQueue.put((filename, result)) + + +def __jsSyntaxCheck(file, codestring): + """ + Function to check a JavaScript source file for syntax errors. + + @param file source filename + @type str + @param codestring string containing the code to check + @type str + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict + """ + if codestring: + try: + import esprima # noqa: I101, I102 + except ImportError: + error = "esprima not available. Install it via the PyPI interface." + return [{"error": (file, 0, 0, "", error)}] + + try: + esprima.parse(codestring, esnext=True, sourceType="module") + # Parsing is just done to get syntax errors. + except esprima.Error as exc: + line = exc.lineNumber + column = exc.column + error = exc.message.split(":", 1)[-1].strip() + + codelines = codestring.splitlines() + cline = min(len(codelines), line) - 1 + code = codelines[cline] + + return [{"error": (file, line, column, code, error)}] + + return [{}]
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsonCheckSyntax.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/jsonCheckSyntax.py Sat Nov 25 18:19:21 2023 +0100 @@ -17,7 +17,7 @@ Initialize the service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return jsonSyntaxCheck @@ -27,7 +27,7 @@ Initialize the batch service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return jsonSyntaxBatchCheck @@ -40,11 +40,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ return __jsonSyntaxCheck(file, codestring) @@ -53,14 +52,14 @@ """ Module function to check syntax for a batch of files. - @param argumentsList list of arguments tuples as given for yamlSyntaxCheck + @param argumentsList list of arguments tuples as given for jsonSyntaxCheck @type list @param send reference to send function - @type func + @type function @param fx registered service name @type str @param cancelled reference to function checking for a cancellation - @type func + @type function @param maxProcesses number of processes to be used @type int """ @@ -152,11 +151,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ if codestring: try:
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyCheckSyntax.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/pyCheckSyntax.py Sat Nov 25 18:19:21 2023 +0100 @@ -107,12 +107,12 @@ @type bool @param additionalBuiltins list of names pyflakes should consider as builtins @type list of str - @return dictionary with the keys 'error', 'py_warnings' and 'warnings' which - hold a list containing details about the syntax error, Python warnings - and PyFlakes warnings (file name, line number, column, codestring (only - for syntax errors), the message and an optional list with arguments for - the message) - @rtype dict + @return list of dictionaries with the keys 'error', 'py_warnings' and 'warnings' + which contain a tuple with details about the syntax error or a list of + tuples with details about Python warnings and PyFlakes warnings. Each tuple + contains the file name, line number, column, code string (only for syntax + errors), the message and an optional list with arguments for the message. + @rtype list of dict """ return __pySyntaxAndPyflakesCheck( filename, codestring, checkFlakes, ignoreStarImportWarnings, additionalBuiltins @@ -126,11 +126,11 @@ @param argumentsList list of arguments tuples as given for pySyntaxAndPyflakesCheck @type list @param send reference to send function - @type func + @type function @param fx registered service name @type str @param cancelled reference to function checking for a cancellation - @type func + @type function @param maxProcesses number of processes to be used @type int """ @@ -238,12 +238,12 @@ @type bool @param additionalBuiltins list of names pyflakes should consider as builtins @type list of str - @return dictionary with the keys 'error', 'py_warnings' and 'warnings' which - hold a list containing details about the syntax error, Python warnings - and PyFlakes warnings (file name, line number, column, codestring (only - for syntax errors), the message and an optional list with arguments for - the message) - @rtype dict + @return list of dictionaries with the keys 'error', 'py_warnings' and 'warnings' + which contain a tuple with details about the syntax error or a list of + tuples with details about Python warnings and PyFlakes warnings. Each tuple + contains the file name, line number, column, code string (only for syntax + errors), the message and an optional list with arguments for the message. + @rtype list of dict """ if codestring: errorDict = {}
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/tomlCheckSyntax.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/tomlCheckSyntax.py Sat Nov 25 18:19:21 2023 +0100 @@ -16,7 +16,7 @@ Initialize the service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return tomlSyntaxCheck @@ -26,7 +26,7 @@ Initialize the batch service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return tomlSyntaxBatchCheck @@ -39,11 +39,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ return __tomlSyntaxCheck(file, codestring) @@ -55,11 +54,11 @@ @param argumentsList list of arguments tuples as given for tomlSyntaxCheck @type list @param send reference to send function - @type func + @type function @param fx registered service name @type str @param cancelled reference to function checking for a cancellation - @type func + @type function @param maxProcesses number of processes to be used @type int """ @@ -151,11 +150,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ if codestring: try:
--- a/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/yamlCheckSyntax.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/SyntaxChecker/yamlCheckSyntax.py Sat Nov 25 18:19:21 2023 +0100 @@ -16,7 +16,7 @@ Initialize the service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return yamlSyntaxCheck @@ -26,7 +26,7 @@ Initialize the batch service and return the entry point. @return the entry point for the background client - @rtype func + @rtype function """ return yamlSyntaxBatchCheck @@ -39,11 +39,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ return __yamlSyntaxCheck(file, codestring) @@ -55,11 +54,11 @@ @param argumentsList list of arguments tuples as given for yamlSyntaxCheck @type list @param send reference to send function - @type func + @type function @param fx registered service name @type str @param cancelled reference to function checking for a cancellation - @type func + @type function @param maxProcesses number of processes to be used @type int """ @@ -151,11 +150,10 @@ @type str @param codestring string containing the code to check @type str - @return dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) - @rtype dict + @return list of dictionaries with the key 'error' which contain a tuple with + details about the syntax error. Each tuple contains the file name, line + number, column, code string and the error message. + @rtype list of dict """ if codestring: try:
--- a/src/eric7/Plugins/PluginSyntaxChecker.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/Plugins/PluginSyntaxChecker.py Sat Nov 25 18:19:21 2023 +0100 @@ -30,8 +30,8 @@ "packageName": "__core__", "shortDescription": "Show the Syntax Checker dialog.", "longDescription": ( - """This plugin implements the Syntax Checker dialog.""" - """ Syntax Checker is used to check Python source files for correct""" + """This plugin implements the Syntax Checker dialog. Syntax Checker is used""" + """ to check Python, JavaScript, JSON, TOML and YAML files for correct""" """ syntax.""" ), "pyqtApi": 2, @@ -50,7 +50,8 @@ """ Constructor - @param ui reference to the user interface object (UI.UserInterface) + @param ui reference to the user interface object + @type UI.UserInterface """ from eric7.Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import ( SyntaxCheckService, @@ -120,6 +121,20 @@ self.syntaxCheckService.serviceErrorTOML, ) + # JavaScript syntax check via Python3 + self.syntaxCheckService.addLanguage( + "JavaScript", + "Python3", + path, + "jsCheckSyntax", + lambda: [], # No options + lambda: [".js"], + lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( + fn, problems + ), + self.syntaxCheckService.serviceErrorJavaScript, + ) + def __initialize(self): """ Private slot to (re)initialize the plugin. @@ -155,11 +170,15 @@ the warnings (marker, file name, line number, message) The values are only valid, if nok is False. - @param fn filename of the checked file (str) - @param problems dictionary with the keys 'error' and 'warnings' which - hold a list containing details about the error/ warnings - (file name, line number, column, codestring (only at syntax - errors), the message, a list with arguments for the message) + @param fn filename of the checked file + @type str + @param problems list of dictionaries with the keys 'error', 'py_warnings' and + 'warnings' which contain a tuple with details about the syntax error or a + list of tuples with details about Python warnings and PyFlakes warnings. + Each tuple contains the file name, line number, column, code string (only + for syntax errors), the message and an optional list with arguments for + the message. + @type list of dict """ from eric7.Plugins.CheckerPlugins.SyntaxChecker.pyflakes.translations import ( getTranslatedFlakesMessage, @@ -178,7 +197,8 @@ """ Public method to activate this plugin. - @return tuple of None and activation status (boolean) + @return tuple of None and activation status + @rtype bool """ menu = ericApp().getObject("Project").getMenu("Checks") if menu: @@ -259,8 +279,10 @@ Private slot called, when the the project menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu """ if menuName == "Checks" and self.__projectAct is not None: self.__projectAct.setEnabled( @@ -273,8 +295,10 @@ Private slot called, when the the project browser menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu """ if ( menuName == "Checks" @@ -350,7 +374,8 @@ """ Private slot called, when a new editor was opened. - @param editor reference to the new editor (QScintilla.Editor) + @param editor reference to the new editor + @type QScintilla.Editor """ menu = editor.getMenu("Checks") if menu is not None: @@ -362,7 +387,8 @@ """ Private slot called, when an editor was closed. - @param editor reference to the editor (QScintilla.Editor) + @param editor reference to the editor + @type QScintilla.Editor """ with contextlib.suppress(ValueError): self.__editors.remove(editor) @@ -372,9 +398,12 @@ Private slot called, when the the editor context menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu @param editor reference to the editor + @type QScintilla.Editor """ if menuName == "Checks": if self.__editorAct not in menu.actions():
--- a/src/eric7/QScintilla/Editor.py Fri Nov 24 14:59:26 2023 +0100 +++ b/src/eric7/QScintilla/Editor.py Sat Nov 25 18:19:21 2023 +0100 @@ -6710,6 +6710,11 @@ if line == 0: line = 1 # hack to show a syntax error marker, if line is reported to be 0 + + line = min(line, self.lines()) + # Limit the line number to the ones we really have to ensure proper display + # of the error annotation. + if setError: # set a new syntax error marker markers = self.markersAtLine(line - 1) @@ -6864,6 +6869,11 @@ if line == 0: line = 1 # hack to show a warning marker, if line is reported to be 0 + + line = min(line, self.lines()) + # Limit the line number to the ones we really have to ensure proper display + # of the warning annotation. + if setWarning: # set/amend a new warning marker warn = (msg, warningType)