Flakes8 help on my short codes.

Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone

I don't know flake8 well, but one tactic is to wrap the flake8 call in a "lint" script, and do any extra checks you want in there, in Bash. eg looping over files and calling "wc -l" in this case.
Apologies this is not what you asked for.
On Sat, May 4, 2019, at 19:47, oscar anomnihe wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
-- Jonathan Hartley +1(507)513-1101 @tartley http://tartley.com/http://tartley.com

Flake8 allows you to create a plugin that accepts the parameter "lines" which will provide you with a list of strings representing all of the lines in the file (including empty/blank lines). You can then call "len(lines)" and return an violation if that exceeds 500.
On Sat, May 4, 2019 at 6:47 PM oscar anomnihe oscaranomnihe@gmail.com wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality

Thanks Ian,
Is there a short sample (one or two lines) code that could make your explanation clearer to me. I will highly appreciate that.
Regard Oscar Sent from my iPhone
On 5 May 2019, at 4:54 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Flake8 allows you to create a plugin that accepts the parameter "lines" which will provide you with a list of strings representing all of the lines in the file (including empty/blank lines). You can then call "len(lines)" and return an violation if that exceeds 500.
On Sat, May 4, 2019 at 6:47 PM oscar anomnihe oscaranomnihe@gmail.com wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality

Unfortunately, there's nothing that short that serves as an example. There is some documentation around building a plugin, though: http://flake8.pycqa.org/en/latest/plugin-development/index.html
On Sun, May 5, 2019 at 11:09 AM oscar anomnihe oscaranomnihe@gmail.com wrote:
Thanks Ian,
Is there a short sample (one or two lines) code that could make your explanation clearer to me. I will highly appreciate that.
Regard Oscar Sent from my iPhone
On 5 May 2019, at 4:54 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Flake8 allows you to create a plugin that accepts the parameter "lines" which will provide you with a list of strings representing all of the lines in the file (including empty/blank lines). You can then call "len(lines)" and return an violation if that exceeds 500.
On Sat, May 4, 2019 at 6:47 PM oscar anomnihe oscaranomnihe@gmail.com wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality

Thanks so much.
Sent from my iPhone
On 5 May 2019, at 5:20 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Unfortunately, there's nothing that short that serves as an example. There is some documentation around building a plugin, though: http://flake8.pycqa.org/en/latest/plugin-development/index.html
On Sun, May 5, 2019 at 11:09 AM oscar anomnihe oscaranomnihe@gmail.com wrote:
Thanks Ian,
Is there a short sample (one or two lines) code that could make your explanation clearer to me. I will highly appreciate that.
Regard Oscar Sent from my iPhone
On 5 May 2019, at 4:54 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Flake8 allows you to create a plugin that accepts the parameter "lines" which will provide you with a list of strings representing all of the lines in the file (including empty/blank lines). You can then call "len(lines)" and return an violation if that exceeds 500.
On Sat, May 4, 2019 at 6:47 PM oscar anomnihe oscaranomnihe@gmail.com wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality

Hi Oscar,
Just to echo what the others have said, yes this is doable with a plugin that checks the `lines` parameter.
Over the last year or so I've been working on a Flake8 plugin. I used Ian's documentation for plugin development **plus** I referred a lot to flake8-author (https://github.com/jparise/flake8-author/) a small plugin that I found.
My plugin uses both lines and AST passed from Flake8 - here https://github.com/jamescooke/flake8-aaa/blob/master/src/flake8_aaa/checker.... you can see the `Checker.__init__()` has the `lines` parameter Ian mentioned. This means that Flake8 passes the lines in each file it checks when initialising the class. That will then allow you to build a `run()` function to count those lines and raise errors as required.
I also found that pytest-flake8dir (https://github.com/adamchainz/pytest-flake8dir) was helpful when I was getting started, although I don't use it any more.
Hope that's helpful.
Cheers,
James
On Sun, 5 May 2019, at 5:42 PM, oscar anomnihe wrote:
Thanks so much.
Sent from my iPhone
On 5 May 2019, at 5:20 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Unfortunately, there's nothing that short that serves as an example. There is some documentation around building a plugin, though: http://flake8.pycqa.org/en/latest/plugin-development/index.html
On Sun, May 5, 2019 at 11:09 AM oscar anomnihe oscaranomnihe@gmail.com wrote:
Thanks Ian,
Is there a short sample (one or two lines) code that could make your explanation clearer to me. I will highly appreciate that.
Regard Oscar Sent from my iPhone
On 5 May 2019, at 4:54 PM, Ian Stapleton Cordasco graffatcolmingov@gmail.com wrote:
Flake8 allows you to create a plugin that accepts the parameter "lines" which will provide you with a list of strings representing all of the lines in the file (including empty/blank lines). You can then call "len(lines)" and return an violation if that exceeds 500.
On Sat, May 4, 2019 at 6:47 PM oscar anomnihe oscaranomnihe@gmail.com wrote:
Good day,
How can I get flakes8 plugin to yell at me when I exceed 500 lines of code(not individual lines)? I need it to help me not exceed 500 lines of code. Kindly advice
Regards
Oscar
Sent from my iPhone _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
participants (4)
-
Ian Stapleton Cordasco
-
James Cooke
-
Jonathan Hartley
-
oscar anomnihe