Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Framework for writing custom linting-rules in python?

+4
−0

I hope this somewhat open-ended question is allowed, I have used SO a lot and I would not post it there, but I have seen open-ended questions on this site

I have a situation where custom linting-rules for python-code would be very helpful[1].

Some random examples of rules I want to enforce:

  • All imports must be absolute, at top-level and reference existing modules.

  • All classes that define a class-variable event_map must inherit from proprietaryOrm.Object and event_map must have a certain structure

  • ctx.set_object_result and ctx.url must not be called in the same function

So this is not random clean-code rules, this is very specific and I need to code them up using a combination of techniques, mostly AST-inspection and dynamic inspection of live-objects[2]. The question is not how to write these rules but where to put them. If I write a unittest, I put it in a test-framework. Now I don't have to worry about things like the test-runner and IDE-integration. If I write a linting-rule, I put it where?

I have not found any 'linting-framework' online, but maybe I just did not find it. Finding such a thing would be ideal. But if there is nothing like this, is there at least some standard for integrating linters into IDEs? "Output your linter-violations in this specific format and this standard plugin can pick it up". Or can you bend a regular test-framework like pytest to do this?



  1. Specifically, my python-code is loaded into a proprietary application, which means simple errors in the code can be very hard to trace. There are also consistency rules that have to do with the framework, not the python-language, and they are painful-to-discover and not well-known. ↩︎

  2. I don't know if inspecting live objects is technically still considered 'linting' or 'static code analysis' in the literature since I am importing code and thereby executing something, but anyways. My point is, the tool should validate code without the programmer having to write a test. ↩︎

History

2 comment threads

pylint-plugins can do some of this (1 comment)
simple (non-)solution for now (1 comment)

Sign up to answer this question »