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.
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!
Execute the following command from the console such as the command prompt
pip install flake8
Install cornflakes-linter from VS Code Marketplace
Open the setting screen with File> User Settings> Settings
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 **)
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 **
--** Disable ** if Pylint is enabled by default
--Default flake8 is ** disabled **
--The default Lint On Save is ** disabled **
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.
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 ...!
https://qiita.com/psychoroid/items/2c2acc06c900d2c0c8cb https://blog.daisukekonishi.com/post/python-black/
Recommended Posts