.. _panes-pylint: ############# Code Analysis ############# The **Code Analysis** pane detects style issues, bad practices, potential bugs, and other quality problems in your code, all without having to actually execute it. Based on these results, it also gives your code an overall quality score. Spyder's code analyzer is powered by the `Pylint`_ backend, which can intelligently detect an enormous and customizable range of potential errors, bad practices, quality issues, style violations, and more. .. _Pylint: https://pylint.pycqa.org/ .. image:: /images/pylint/code-analysis-standard.png :alt: Spyder Pylint pane, showing numerous issues discovered in a file .. _panes-pylint-using: ======================= Using the code analyzer ======================= To select the desired file to analyze, make sure it is focused in the :ref:`panes-editor` by clicking anywhere within it. Then, the run the analysis, press the configurable shortcut (:kbd:`F8` by default), select :menuselection:`Source --> Run code analysis` from the menu bar or click the :guilabel:`Analyze` button in the Code Analysis pane. If the Code Analysis pane is not visible, you can open it under :menuselection:`View --> Panes --> Code Analysis`. All standard checks are run by default. Click any detected issue to go directly to the line with the failed check in the :ref:`panes-editor`. .. image:: /images/pylint/code-analysis-editor.gif :alt: Spyder Pylint pane, showing running analysis and clicking failed check You can also manually enter the path of a file you'd like it to check in the path entry box in the pane's toolbar, which works with both individual scripts and whole Python packages (directories containing an :file:`__init__.py` file). .. image:: /images/pylint/code-analysis-file.gif :alt: Spyder Pylint pane, showing running analysis browsing file Cancel analyzing a file with the :guilabel:`Stop` button, and in case the analysis were to fail, click the :guilabel:`Output` button to find out why. Otherwise, assuming Pylint succeeds, the :guilabel:`Output` will show the raw plain text analysis results on the selected file, allowing you to easily browse and copy/paste the full message names and descriptions. .. image:: /images/pylint/code-analysis-output.png :alt: Spyder Pylint pane, showing output Finally, you can click the dropdown arrow in the filename field to view results of previous analyses. .. image:: /images/pylint/code-analysis-history.png :alt: Spyder Pylint pane, showing history .. _panes-pylint-options: ============ Options menu ============ The number of recent runs Spyder should remember can be customized in the :guilabel:`History...` dialog, available from the Code Analysis options (hamburger) menu in the top right of the pane. .. image:: /images/pylint/code-analysis-history-custom.gif :alt: Spyder Pylint pane, customizing history dialog You can also expand or collapse one or all the sections in the pane by using the corresponding options in that menu. .. image:: /images/pylint/code-analysis-expand-collapse.gif :alt: Spyder Pylint pane, expanding and collapsing sections .. _panes-pylint-advanced: ================ Advanced options ================ You can turn certain messages off at the line, block or file/module level by adding a ``# pylint: disable=MESSAGE-NAMES`` comment at the respective `scope`_, where ``MESSAGE_NAMES`` should be replaced with a comma-separated list (or single value) of `Pylint message names`_. For example, a directive might look like ``# pylint: disable=invalid-name``, or ``# pylint: disable=fixme, line-too-long``. .. _scope: https://pylint.pycqa.org/en/stable/user_guide/message-control.html .. _Pylint message names: https://pylint.pycqa.org/en/latest/user_guide/checkers/features.html#pylint-checkers-options-and-switches .. image:: /images/pylint/code-analysis-pylint-disable.gif :alt: Spyder Pylint pane, showing disabling a message locally Or, you can globally suppress specific messages and adjust other Pylint settings by editing the :file:`.pylintrc` configuration file in your user home folder. If it doesn't exist, you can generate it by running ``pylint --generate-rcfile > .pylintrc`` in your user home folder, from the Anaconda Prompt (on Windows) or your terminal (macOS/Linux). For more details on configuring Pylint, see the `Pylint configuration documentation`_. .. _Pylint configuration documentation: https://pylint.pycqa.org/en/latest/user_guide/configuration/index.html .. image:: /images/pylint/code-analysis-pylint-file.gif :alt: Spyder Pylint pane, disabling a message globally in the .pylintrc .. _panes-pylint-related: ============= Related panes ============= * :ref:`panes-editor` * :ref:`panes-profiler`