28 "version": Info.VersionOnly, |
28 "version": Info.VersionOnly, |
29 "className": "SyntaxCheckerPlugin", |
29 "className": "SyntaxCheckerPlugin", |
30 "packageName": "__core__", |
30 "packageName": "__core__", |
31 "shortDescription": "Show the Syntax Checker dialog.", |
31 "shortDescription": "Show the Syntax Checker dialog.", |
32 "longDescription": ( |
32 "longDescription": ( |
33 """This plugin implements the Syntax Checker dialog.""" |
33 """This plugin implements the Syntax Checker dialog. Syntax Checker is used""" |
34 """ Syntax Checker is used to check Python source files for correct""" |
34 """ to check Python, JavaScript, JSON, TOML and YAML files for correct""" |
35 """ syntax.""" |
35 """ syntax.""" |
36 ), |
36 ), |
37 "pyqtApi": 2, |
37 "pyqtApi": 2, |
38 } |
38 } |
39 # End-Of-Header |
39 # End-Of-Header |
118 fn, problems |
119 fn, problems |
119 ), |
120 ), |
120 self.syntaxCheckService.serviceErrorTOML, |
121 self.syntaxCheckService.serviceErrorTOML, |
121 ) |
122 ) |
122 |
123 |
|
124 # JavaScript syntax check via Python3 |
|
125 self.syntaxCheckService.addLanguage( |
|
126 "JavaScript", |
|
127 "Python3", |
|
128 path, |
|
129 "jsCheckSyntax", |
|
130 lambda: [], # No options |
|
131 lambda: [".js"], |
|
132 lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( |
|
133 fn, problems |
|
134 ), |
|
135 self.syntaxCheckService.serviceErrorJavaScript, |
|
136 ) |
|
137 |
123 def __initialize(self): |
138 def __initialize(self): |
124 """ |
139 """ |
125 Private slot to (re)initialize the plugin. |
140 Private slot to (re)initialize the plugin. |
126 """ |
141 """ |
127 self.__projectAct = None |
142 self.__projectAct = None |
153 |
168 |
154 If checkFlakes is True, warnings contains a list of strings containing |
169 If checkFlakes is True, warnings contains a list of strings containing |
155 the warnings (marker, file name, line number, message) |
170 the warnings (marker, file name, line number, message) |
156 The values are only valid, if nok is False. |
171 The values are only valid, if nok is False. |
157 |
172 |
158 @param fn filename of the checked file (str) |
173 @param fn filename of the checked file |
159 @param problems dictionary with the keys 'error' and 'warnings' which |
174 @type str |
160 hold a list containing details about the error/ warnings |
175 @param problems list of dictionaries with the keys 'error', 'py_warnings' and |
161 (file name, line number, column, codestring (only at syntax |
176 'warnings' which contain a tuple with details about the syntax error or a |
162 errors), the message, a list with arguments for the message) |
177 list of tuples with details about Python warnings and PyFlakes warnings. |
|
178 Each tuple contains the file name, line number, column, code string (only |
|
179 for syntax errors), the message and an optional list with arguments for |
|
180 the message. |
|
181 @type list of dict |
163 """ |
182 """ |
164 from eric7.Plugins.CheckerPlugins.SyntaxChecker.pyflakes.translations import ( |
183 from eric7.Plugins.CheckerPlugins.SyntaxChecker.pyflakes.translations import ( |
165 getTranslatedFlakesMessage, |
184 getTranslatedFlakesMessage, |
166 ) |
185 ) |
167 |
186 |
176 |
195 |
177 def activate(self): |
196 def activate(self): |
178 """ |
197 """ |
179 Public method to activate this plugin. |
198 Public method to activate this plugin. |
180 |
199 |
181 @return tuple of None and activation status (boolean) |
200 @return tuple of None and activation status |
|
201 @rtype bool |
182 """ |
202 """ |
183 menu = ericApp().getObject("Project").getMenu("Checks") |
203 menu = ericApp().getObject("Project").getMenu("Checks") |
184 if menu: |
204 if menu: |
185 self.__projectAct = EricAction( |
205 self.__projectAct = EricAction( |
186 self.tr("Check Syntax"), |
206 self.tr("Check Syntax"), |
257 def __projectShowMenu(self, menuName, menu): # noqa: U100 |
277 def __projectShowMenu(self, menuName, menu): # noqa: U100 |
258 """ |
278 """ |
259 Private slot called, when the the project menu or a submenu is |
279 Private slot called, when the the project menu or a submenu is |
260 about to be shown. |
280 about to be shown. |
261 |
281 |
262 @param menuName name of the menu to be shown (string) |
282 @param menuName name of the menu to be shown |
263 @param menu reference to the menu (QMenu) |
283 @type str |
|
284 @param menu reference to the menu |
|
285 @type QMenu |
264 """ |
286 """ |
265 if menuName == "Checks" and self.__projectAct is not None: |
287 if menuName == "Checks" and self.__projectAct is not None: |
266 self.__projectAct.setEnabled( |
288 self.__projectAct.setEnabled( |
267 ericApp().getObject("Project").getProjectLanguage() |
289 ericApp().getObject("Project").getProjectLanguage() |
268 in self.syntaxCheckService.getLanguages() |
290 in self.syntaxCheckService.getLanguages() |
271 def __projectBrowserShowMenu(self, menuName, menu): |
293 def __projectBrowserShowMenu(self, menuName, menu): |
272 """ |
294 """ |
273 Private slot called, when the the project browser menu or a submenu is |
295 Private slot called, when the the project browser menu or a submenu is |
274 about to be shown. |
296 about to be shown. |
275 |
297 |
276 @param menuName name of the menu to be shown (string) |
298 @param menuName name of the menu to be shown |
277 @param menu reference to the menu (QMenu) |
299 @type str |
|
300 @param menu reference to the menu |
|
301 @type QMenu |
278 """ |
302 """ |
279 if ( |
303 if ( |
280 menuName == "Checks" |
304 menuName == "Checks" |
281 and ericApp().getObject("Project").getProjectLanguage() |
305 and ericApp().getObject("Project").getProjectLanguage() |
282 in self.syntaxCheckService.getLanguages() |
306 in self.syntaxCheckService.getLanguages() |
348 |
372 |
349 def __editorOpened(self, editor): |
373 def __editorOpened(self, editor): |
350 """ |
374 """ |
351 Private slot called, when a new editor was opened. |
375 Private slot called, when a new editor was opened. |
352 |
376 |
353 @param editor reference to the new editor (QScintilla.Editor) |
377 @param editor reference to the new editor |
|
378 @type QScintilla.Editor |
354 """ |
379 """ |
355 menu = editor.getMenu("Checks") |
380 menu = editor.getMenu("Checks") |
356 if menu is not None: |
381 if menu is not None: |
357 menu.addAction(self.__editorAct) |
382 menu.addAction(self.__editorAct) |
358 editor.showMenu.connect(self.__editorShowMenu) |
383 editor.showMenu.connect(self.__editorShowMenu) |
360 |
385 |
361 def __editorClosed(self, editor): |
386 def __editorClosed(self, editor): |
362 """ |
387 """ |
363 Private slot called, when an editor was closed. |
388 Private slot called, when an editor was closed. |
364 |
389 |
365 @param editor reference to the editor (QScintilla.Editor) |
390 @param editor reference to the editor |
|
391 @type QScintilla.Editor |
366 """ |
392 """ |
367 with contextlib.suppress(ValueError): |
393 with contextlib.suppress(ValueError): |
368 self.__editors.remove(editor) |
394 self.__editors.remove(editor) |
369 |
395 |
370 def __editorShowMenu(self, menuName, menu, editor): |
396 def __editorShowMenu(self, menuName, menu, editor): |
371 """ |
397 """ |
372 Private slot called, when the the editor context menu or a submenu is |
398 Private slot called, when the the editor context menu or a submenu is |
373 about to be shown. |
399 about to be shown. |
374 |
400 |
375 @param menuName name of the menu to be shown (string) |
401 @param menuName name of the menu to be shown |
376 @param menu reference to the menu (QMenu) |
402 @type str |
|
403 @param menu reference to the menu |
|
404 @type QMenu |
377 @param editor reference to the editor |
405 @param editor reference to the editor |
|
406 @type QScintilla.Editor |
378 """ |
407 """ |
379 if menuName == "Checks": |
408 if menuName == "Checks": |
380 if self.__editorAct not in menu.actions(): |
409 if self.__editorAct not in menu.actions(): |
381 menu.addAction(self.__editorAct) |
410 menu.addAction(self.__editorAct) |
382 self.__editorAct.setEnabled( |
411 self.__editorAct.setEnabled( |