https://bugs.documentfoundation.org/show_bug.cgi?id=158803

--- Comment #25 from Leonard Sasse <[email protected]> ---
(In reply to Hossein from comment #0)
> Description:
> There are Python scripts for various purposes in LibreOffice: from UITests
> to wizards, SDK examples and other places. This task is defined to do static
> code checking on Python scripts to do cleanup and fix some errors as they
> are found.
> 
> Pyflakes is a tool for checking Python files for various problems. It can be
> installed using pip:
> 
> Pyflakes: A simple program which checks Python source files for errors 
> https://github.com/PyCQA/pyflakes
> 
> Some of the issues reported by Pyflakes are:
> 
> * Unused imports
> * Unnecessary re-imports
> * Undefined variables
> * Name Shadowing
> * Syntax Errors
> 
> And many other issues, some of them described here:
> https://github.com/PyCQA/pyflakes/issues?q=is%3Aissue+is%3Aclosed
> 
> At first, you have to run pyflakes to find those issues, and then fix them
> one by one. If you go to a specific path, and invoke "pyflakes .", it will
> try finding Python scripts inside the current folder, and report the errors.
> Then, you have to fix them one by one.
> 
> As an example, let's check a test inside "unotest" folder:
> $ pyflakes sw/qa/uitest/writer_tests7/tdf156900.py
> sw/qa/uitest/writer_tests7/tdf156900.py:18:13: local variable 'xToolkit' is
> assigned to but never used
> 
> The output shows there are some unused local variable. To fix it, this line
> should be removed:
> 
> xToolkit =
> self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
> 
> Some unused imports must remain, if they are there to test if importing
> something is actually possible, and give error message if it is not.
> 
> We have another issue for pyflakes, but it is specifically about finding
> unused imports in UITests:
> 
> tdf#132293 - Run pyflakes on python uitest files to find unused imports
> https://bugs.documentfoundation.org/show_bug.cgi?id=132293
> 
> Therefore, if you are working on unused imports for UITests only, use the
> above issue instead. This new one is about all the other issues, and also
> Python scripts beyond UITests.

I would propose even extending the scope of this issue and to fix issues raised
by ruff: https://github.com/astral-sh/ruff

ruff is a superset of multiple python linting tools and extremely fast. Even
when I run it on the whole LibreOffice/core repo, it is finished checking
almost instantaneously, whereas other tools such as pyflakes take quite a bit
longer. This fast execution also makes ruff a good candidate to be included in
the CI to make sure that these kinds of errors don't creep back into the code
base.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to