Allow real-time code checking in Python development with VS Code

Introduction

Until now, when using Python, there were many scenes where I wrote a little script, and for the time being, I typed in and executed it in Jupyter Notebook and noticed the violation of the coding standard later and fixed it ...

I want to develop with Visual Studio Code with Django, which is a Python web application framework! So we introduced static code checking and formatting tools.

I referred to some articles for the setting, but I could not find an article that sets the check to run in real time at the time of input like the ESLint plug-in of JavaScript, so I made it as a reminder.

Overview

There are several types of Python code checks, and there are many that can currently be set in VS Code as follows.

The features of each are not described in this article, but the ** flake8 ** installed this time has a plug-in called ** cornflakes-linter ** for VS Code, and by installing it, it will be installed in real time according to the input. You can run the code check! cornflakes.gif

environment

Installation procedure

Install flake8

Execute the following command from the console such as the command prompt

pip install flake8

Install the cornflakes-linter plugin

Install cornflakes-linter from VS Code Marketplace image.png

Set cornflakes-linter in VScode

Open the setting screen with File> User Settings> Settings image.png

If you search by keywords such as cornflake, the item Cornflakes> Linter will appear, so set as shown in the figure below.

--flake8 installation path --Code check timing (I want to do it in real time this time, so select ** onType **) image.png

Change the default Linting settings in VS Code [Important]

Open the VS Code setting screen as in the previous step, and set the Python> Linting item as shown in the figure below.

--Python Linting itself is ** enabled ** image.png

--** Disable ** if Pylint is enabled by default image.png

--Default flake8 is ** disabled ** image.png

--The default Lint On Save is ** disabled ** image.png

that's all! I was able to set it in a very simple procedure. If you edit the .py file in this state, the code check should work.

in conclusion

The format tool has black installed separately and is set to be automatically formatted when saved. (Second reference link) In any case, I save it for automatic formatting, and I have a diligent saving habit, but if it is a real-time check, I immediately notice it when I make a mistake (such as a variable name typo ...), or while writing, "Oh, There are many merits, such as getting feedback immediately asking "Is this kind of writing useless?", So I think it should be used properly.

If you are doing web development with Python, please give it a try ...!

Reference link

https://qiita.com/psychoroid/items/2c2acc06c900d2c0c8cb https://blog.daisukekonishi.com/post/python-black/

Recommended Posts

Allow real-time code checking in Python development with VS Code
Use Python in Anaconda environment with VS Code
Python with VS Code (Windows 10)
Debug Python with VS Code
VS Code settings for developing in Python with completion
Revive symbol search in Python workspace with VS Code
Install python with mac vs code
UpNext2 Development Record # 1 Build Python CI environment in VS Code
Pass PYTHONPATH in 1 minute with VS Code
Create a simple Python development environment with VS Code and Docker
Build Python development environment with Visual Studio Code
Python (Windows 10) Virtual Environment / Package with VS Code
Debug with VS Code using boost python numpy
Use Docker development container conveniently with VS Code
Make your Python environment "easy" with VS Code
Build a python execution environment with VS Code
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Framework development in Python
Development environment in Python
Slackbot development in Python
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Specific sample code for working with SQLite3 in Python
Try touching the micro: bit with VS Code + Python
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Expose settings.json for efficient Python coding in VS Code
Get country code with python
Scraping with selenium in Python
Working with LibreOffice in Python
Debugging with pdb in Python
Write Spigot in VS Code
Working with sounds in Python
Scraping with Selenium in Python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Python development in Visual Studio 2017
Generate QR code in Python
Python development in Visual Studio
Character code learned in Python
Document Python code with Doxygen
Settings when developing App Engine / Python apps with VS Code
Let's run jupyter natively supported by VS Code with python3.8
Set up a Python development environment with Visual Studio Code
Video cannot be loaded with Spyder in Python development environment
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
The story that Python stopped working with VS Code (Windows 10)
Specification generation and code generation in REST API development (Python edition)
I want to be able to run Python in VS Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
[No venv required] The strongest Python development environment created with Remote Containers [VS Code / Docker]
Number recognition in images with Python
Create a Python environment for professionals in VS Code on Windows
[Windows 10] [Development environment construction] How to resolve when unresolved import'django.xxx' python (unresolved-import) occurs in VS Code
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Scraping with Selenium in Python (Basic)
CSS parsing with cssutils in Python
Web application development memo in python