Apply syntax check before running black

This commit is contained in:
Nyall Dawson 2023-03-17 12:40:33 +10:00
parent 3312bf1ad2
commit a4f325c92f
2 changed files with 7 additions and 1 deletions

View File

@ -184,7 +184,7 @@ def somefunc(param1: str='', param2=0):
'''A docstring'''
if param1 > param2: # interesting
print('Gre\'ater'.lower())
return (param2 - param1 + 1 + 0b10l) or None
return (param2 - param1 + 1 + 0b10) or None
class SomeClass:
"""

View File

@ -454,6 +454,12 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
{
const bool normalize = settings.value( QStringLiteral( "pythonConsole/blackNormalizeQuotes" ), true ).toBool();
if ( !checkSyntax() )
{
showMessage( tr( "Reformat Code" ), tr( "Code formatting failed -- the code contains syntax errors" ), Qgis::MessageLevel::Warning );
return newText;
}
const QString defineReformat = QStringLiteral(
"def __qgis_reformat(script):\n"
" try:\n"