All Projects → guilatrova → tryceratops

guilatrova / tryceratops

Licence: MIT license
A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to tryceratops

Flake8
The official GitHub mirror of https://gitlab.com/pycqa/flake8
Stars: ✭ 1,112 (+191.86%)
Mutual labels:  stylelint, styleguide, static-code-analysis, linter, static-analysis
Pep8speaks
A GitHub app to automatically review Python code style over Pull Requests
Stars: ✭ 546 (+43.31%)
Mutual labels:  styleguide, static-code-analysis, linter, static-analysis
lints
Lint all your JavaScript, CSS, HTML, Markdown and Dockerfiles with a single command
Stars: ✭ 14 (-96.33%)
Mutual labels:  stylelint, static-code-analysis, linter, static-analysis
sonar-css-plugin
SonarQube CSS / SCSS / Less Analyzer
Stars: ✭ 46 (-87.93%)
Mutual labels:  stylelint, styleguide, linter, static-analysis
Pmd
An extensible multilanguage static code analyzer.
Stars: ✭ 3,667 (+862.47%)
Mutual labels:  static-code-analysis, linter, static-analysis
Pylint
It's not just a linter that annoys you!
Stars: ✭ 3,733 (+879.79%)
Mutual labels:  static-code-analysis, linter, static-analysis
Sonar Jproperties Plugin
SonarQube Java Properties Analyzer
Stars: ✭ 5 (-98.69%)
Mutual labels:  styleguide, linter, static-analysis
static-code-analysis-plugin
A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Stars: ✭ 36 (-90.55%)
Mutual labels:  static-code-analysis, linter, static-analysis
Security Code Scan
Vulnerability Patterns Detector for C# and VB.NET
Stars: ✭ 550 (+44.36%)
Mutual labels:  static-code-analysis, code, static-analysis
Static Analysis
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.
Stars: ✭ 9,310 (+2343.57%)
Mutual labels:  static-code-analysis, linter, static-analysis
Cflint
Static code analysis for CFML (a linter)
Stars: ✭ 156 (-59.06%)
Mutual labels:  static-code-analysis, linter, static-analysis
Pytype
A static type analyzer for Python code
Stars: ✭ 3,545 (+830.45%)
Mutual labels:  static-code-analysis, linter, static-analysis
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+1091.86%)
Mutual labels:  static-code-analysis, linter, static-analysis
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-68.77%)
Mutual labels:  static-code-analysis, linter, static-analysis
Abaplint
Standalone linter for ABAP
Stars: ✭ 111 (-70.87%)
Mutual labels:  static-code-analysis, linter, static-analysis
Spotbugs
SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.
Stars: ✭ 2,569 (+574.28%)
Mutual labels:  static-code-analysis, linter, static-analysis
codeclimate-eslint
Code Climate Engine for ESLint
Stars: ✭ 86 (-77.43%)
Mutual labels:  static-code-analysis, linter, static-analysis
Unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 96 (-74.8%)
Mutual labels:  static-code-analysis, linter, static-analysis
Revive
🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
Stars: ✭ 3,139 (+723.88%)
Mutual labels:  static-code-analysis, linter, static-analysis
sonar-gherkin-plugin
SonarQube Cucumber Gherkin Analyzer
Stars: ✭ 33 (-91.34%)
Mutual labels:  styleguide, linter, static-analysis

Prevent Exception Handling AntiPatterns in Python

Actions Status PyPI Semantic Release GitHub Downloads Code style: black try/except style: tryceratops Follow guilatrova

Inspired by this blog post. I described the building process of this tool here.

“For those who like dinosaurs 🦖 and clean try/except blocks.”

Summary


Installation and usage

Installation

pip install tryceratops

OR

poetry add -D tryceratops

Usage

tryceratops [filename or dir...]

You can enable experimental analyzers by running:

tryceratops --experimental [filename or dir...]

You can ignore specific violations by using: --ignore TCXXX repeatedly:

tryceratops --ignore TC201 --ignore TC202 [filename or dir...]

You can exclude dirs by using: --exclude dir/path repeatedly:

tryceratops --exclude tests --exclude .venv [filename or dir...]

You can also autofix some violations:

tryceratops --autofix [filename or dir...]

example

flake8 Plugin

🦖 Tryceratops is also a plugin for flake8, so you can:

❯ flake8 --select TC src/tests/samples/violations/call_raise_vanilla.py
src/tests/samples/violations/call_raise_vanilla.py:13:9: TC002 Create your own exception
src/tests/samples/violations/call_raise_vanilla.py:13:9: TC003 Avoid specifying long messages outside the exception class
src/tests/samples/violations/call_raise_vanilla.py:21:9: TC201 Simply use 'raise' without specifying exception object again

Violations

All violations and its descriptions can be found in docs.

Autofix support

So far, autofix only supports violations: TC200, TC201, and TC400.

Ignoring violations

If you want to ignore a violation in a specific file, you can either:

  • Add a comment with noqa to the top of the file you want to ignore
  • Add a comment with noqa to the line you want to ignore
  • Add a comment with noqa: CODE to the line you want to ignore a specific violation

Example:

def verbose_reraise_1():
    try:
        a = 1
    except Exception as ex:
        raise ex  # noqa: TC202

Configuration

You can set up a pyproject.toml file to set rules. This is useful to avoid reusing the same CLI flags over and over again and helps to define the structure of your project.

Example:

[tool.tryceratops]
exclude = ["samples"]
ignore = ["TC002", "TC200", "TC300"]
experimental = true

CLI flags always overwrite the config file.

Pre-commit

If you wish to use pre-commit, add this:

  - repo: https://github.com/guilatrova/tryceratops
    rev: v1.1.0
    hooks:
      - id: tryceratops

Show your style

try/except style: tryceratops

Add this fancy badge to your project's README.md:

[![try/except style: tryceratops](https://img.shields.io/badge/try%2Fexcept%20style-tryceratops%20%F0%9F%A6%96%E2%9C%A8-black)](https://github.com/guilatrova/tryceratops)

Extra Resources

If you want to read more about:

Contributing

Thank you for considering making Tryceratops better for everyone!

Refer to Contributing docs.

Change log

See CHANGELOG.

License

MIT

Credits

Thanks to God for the inspiration 🙌 ☁️ ☀️

The black project for insights.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].