Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mobility-university/flake8-newspaper-style
https://github.com/mobility-university/flake8-newspaper-style
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mobility-university/flake8-newspaper-style
- Owner: mobility-university
- License: mit
- Created: 2022-05-07T06:31:32.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-16T14:10:06.000Z (about 2 years ago)
- Last Synced: 2024-07-08T19:13:51.506Z (4 months ago)
- Language: Python
- Size: 34.2 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flake8-extensions - flake8-newspaper-style - Ensures the function definition goes below its usage. (Clean code)
README
# Enforce Newspaper Style with Flake
## Motivation
Good code reads like a newspaper. Start with the highest abstraction, go to the details.
This also enables to read the code without an editor.Quoting Robert C. Martin from his Clean Code book.
“Think of a well-written newspaper article. You read it vertically. At the top you expect a headline that will tell you what the story is about and allows you to decide whether it is something you want to read. The first paragraph gives you a synopsis of the whole story, hiding all the details while giving you the broad-brush concepts. As you continue downward, the details increase until you have all the dates, names, quotes, claims, and other minutia.”
In Python newspaper code should look like this.
```py
def headline():
text()def text(): # this needs to be defined after the usage.
...
```There hasn't been an automatic way in python to check for this. So here it is.
## Usage
```py
# install the flake8 extension for newspaper style
pip3 install flake8-newspaper-style==0.4.2
# then check your code
flake8 --select=NEW src # here it restricts flake8 to newspaper style issues
```## References
- Clean Code book by Robert C. Martin
- [Clean Code formatting matters](https://www.codingblocks.net/podcast/clean-code-formatting-matters/)