简体   繁体   中英

How to change the way pylint lints the comments

I need to have this line in the beginning of a python file:

#script_exec_time: 500

There should not be any space between the # and script_exec_time . This is because the python file is parsed by another script and it will not consider the script_exec_time if there is a space.

I cannot modify the script that parses my python file because I do not have access to it.

Now when I lint using pylint, it automatically gives a space between the # and script_exec_time .

I tried using other linters like flake8, but even they do the same thing.

I still want to use the linter because it makes it much easier to code.

Is there any way to modify pylint settings so that it ignores comments from it's automatic formatting? Or is there any workaround I could use here?

Edit: I tried the same thing by disabling the linter. The problem persisted. It was not related to linter I think. Anyway I found a workaround and I am posting that as an answer.

As Vaibhav Vishal pointed out in his comment, linters like Pylint and flake8 do not reformat code, they just flag code that triggers a lint rule.

You most likely have a formatter installed and configured. See the formatting docs on how this is done and basically do the reverse. :)

All I did was to wrap the original comment in side a block comment, like so:

#script_exec_time:5000
'''
#scrript_exec_time:5000
'''

Vscode will not format anything that is there inside the block comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM