Introduction to Code Linting
What linting is
Section titled “What linting is”Linting is static analysis that flags issues like:
- unused imports/variables
- suspicious logic
- inconsistent style
- complexity / maintainability issues
Linting runs without executing your code.
Linting vs formatting vs type checking
Section titled “Linting vs formatting vs type checking”- Linting: “this looks wrong / risky / inconsistent”
- Formatting: “make code look consistent” (e.g., Black)
- Type checking: “types don’t match” (e.g., Mypy)
Diagram: quality tools overview
Section titled “Diagram: quality tools overview”graph TD A[Source code] --> B["Formatter\n(Black)"] A --> C["Linter\n(Pylint/Flake8)"] A --> D["Type checker\n(Mypy)"] A --> E["Security scan\n(Bandit)"] A --> F["Complexity\n(Radon)"]
Why linting matters
Section titled “Why linting matters”- catches bugs before runtime
- keeps large codebases consistent
- makes PR reviews faster
Visualize it
Section titled “Visualize it”Source code typically passes through a formatter, a linter, and a type checker before a commit is allowed through the quality gate.
flowchart LR A["Source code"] --> B["Formatter (black)"] B --> C["Linter (flake8/pylint)"] C --> D["Type checker (mypy)"] D --> E["Pass"] D --> F["Block commit"]
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Write a unittest TestCase
Section titled “Exercise 1 – Write a unittest TestCase”Exercise 2 – assertRaises
Section titled “Exercise 2 – assertRaises”Exercise 3 – setUp and tearDown
Section titled “Exercise 3 – setUp and tearDown”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading