Blogthedata.com is coming together! We now have perfect* Google Lighthouse score, open issues[1, 2] to achieve a perfect* Mozilla Observatory score, and 100% unit test coverage.
Now, what about the code style? That's where linting comes in. There are several linters for Python, I use Pylint.
VScode has native Pylint integration. Pylint analyzes your code for several issues including very Pythonic things like ensuring variables conform to snake casing (sorry JavaScript 😆) as well as data structure suggestions such as when it might be better to use a tuple over a list. Most Pylint suggestions are based on Python's famous PEP 8 style guide authored by the great Guido van Rossum.
Now, it's time to spill the beans. I don't 'exactly' have 100% Pylint compliance. I added the following to my VScode settings.json to ignore some Pylint checkers:
# settings.json
{
"python.linting.pylintArgs": [
"--disable=C0301",
"--disable=C0114",
"--disable=C0115",
"--disable=C0116",
"--disable=E0401",
]
}
C0301 - Line too Long
I don't like lines being too long, but sometimes code just makes more sense on one line even if it’s long. I do include the following rulers in VScode to see PEP 8's line length guidelines within the editor.
# settings.json
{"editor.rulers": [79, 120]}
Rulers in VScode
C0114, C0115, C0116, (missing class, module, function docstrings)
I am no stranger to documentation. I love documenting things! That being said, I will soon be'reactifying' blogthedata.com which will drastically change code architecture. Once I split the front and backend of the app, I'll turn these checkers back on so I can crank out documentation.
E0401 - import-error
I haven't quite figured this one out. The error is supposed to be about a failed import, but I’ve run into cases where Pylint says the import is failing, but it's clearing working in my code. I turned the error off until I can figure out why Pylint is confused.
Other than those exclusions, blogthedata.com is Pylint compliant and attempts to follow PEP 8 style guidelines wherever possible.
Get a linter and clean up yo code!
Comments
- No comments yet.
John Solly
Hi, I'm John, a Software Engineer with a decade of experience building, deploying, and maintaining cloud-native geospatial solutions. I currently serve as a senior software engineer at HazardHub (A Guidewire Offering), where I work on a variety of infrastructure and application development projects.
Throughout my career, I've built applications on platforms like Esri and Mapbox while also leveraging open-source GIS technologies such as OpenLayers, GeoServer, and GDAL. This blog is where I share useful articles with the GeoDev community. Check out my portfolio to see my latest work!
0