Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

flake8 plugin to enforce short files #7

Open
zupo opened this issue Jan 20, 2019 · 14 comments
Open

flake8 plugin to enforce short files #7

zupo opened this issue Jan 20, 2019 · 14 comments

Comments

@zupo
Copy link
Member

zupo commented Jan 20, 2019

I'd like to have a flake8 plugin that would yell at me if any of the files is longer than 500 lines of code.

The 500 should be configurable. The plugin should support overriding the limit per file or skipping the limit altogether.

https://flake8.pycqa.org/en/latest/user/using-plugins.html

@zupo zupo changed the title flake8 plugin to enforce show files flake8 plugin to enforce short files Jan 21, 2019
@oscanx
Copy link

oscanx commented May 2, 2019

Hi Zupo, You could check this code from Flakes8 documentation if it helps. It sets exception based on the maximum length per line of code in pg 17 and also try for maximum complexity in page 24.

source: https://buildmedia.readthedocs.org/media/pdf/flake8/latest/flake8.pdf

FOR MAXIMUM LINE LENGTH

--max-line-length=
Go back to index
Set the maximum length that any line (with some exceptions) may be.
Exceptions include lines that are either strings or comments which are entirely URLs. For example:

https://some-super-long-domain-name.com/with/some/very/long/path

url = (
'http://...'
)
This defaults to: 79
Command-line example:
$ flake8 --max-line-length 99 dir/
This can be specified in config files.
Example config file usage:
max-line-length = 79

FOR MAXIMUM COMPLEXITY

--max-complexity=
Go back to index
Set the maximum allowed McCabe complexity value for a block of code.
This option is provided by the mccabe dependency’s Flake8 plugin.
Command-line usage:
$ flake8 --max-complexity 15 dir/
This can be specified in config files.
Example config file usage:
max-complexity = 15

oscanx added a commit to oscanx/ostasks that referenced this issue May 2, 2019
oscanx added a commit to oscanx/ostasks that referenced this issue May 2, 2019
@zupo
Copy link
Member Author

zupo commented May 4, 2019

This issue is about the length of files, not individual lines. I.e. we want flake8 to yell if a file has more than X lines of code.

@ayivima
Copy link
Contributor

ayivima commented May 26, 2019

Hello, does the limit pertain to physical lines or logical lines?

For example,

foo = [
    1, 2, 3, 
    4, 5, 6
]

The above should be one logical line, and four physical lines.

@zupo
Copy link
Member Author

zupo commented May 26, 2019

Physical lines is sufficient, logical lines is better.

@ayivima
Copy link
Contributor

ayivima commented May 26, 2019

Thanks :-)

@ayivima
Copy link
Contributor

ayivima commented May 26, 2019

...And to be very sure, the lines which count should not be comments or docstrings....
Even better, which lines should count?

@zupo
Copy link
Member Author

zupo commented May 26, 2019

I don't have a strong opinion. I propose to make the first version simple and dump: Count all physical lines. And then work from there when we see how people use it.

@oscanx
Copy link

oscanx commented May 26, 2019 via email

@oscanx
Copy link

oscanx commented May 26, 2019 via email

@oscanx
Copy link

oscanx commented May 26, 2019 via email

@ayivima
Copy link
Contributor

ayivima commented May 26, 2019

I don't have a strong opinion. I propose to make the first version simple and dump: Count all physical lines. And then work from there when we see how people use it.

Alright. I am working on it.

@oscanx
Copy link

oscanx commented May 26, 2019 via email

@oscanx
Copy link

oscanx commented May 26, 2019 via email

@ayivima
Copy link
Contributor

ayivima commented May 26, 2019

Check this guy out while working developing. It could be helpful too https://github.com/ambv/flake8-mypy Regards

Sent from my iPhone
On 26 May 2019, at 2:06 PM, oscar anomnihe @.> wrote: Maybe try using a simple code with Boolean Def code_limit(): Lines =[] # a list of str representing lines For i in len(Lines): If i >500 print(“ maximum limit of code reached”) Sent from my iPhone > On 26 May 2019, at 2:01 PM, ayivima @.> wrote: > > I don't have a strong opinion. I propose to make the first version simple and dump: Count all physical lines. And then work from there when we see how people use it. > > Alright. I working on it. > > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub, or mute the thread.

Alright, Thanks :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants