Skip to content

Latest commit

 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lintkit is a framework for building linters/code checking rules

  • Multiple formats: Python-first, but supports YAML, JSON and TOML
  • Comprehensive: noqa comments, file skips and standardized pretty output
  • Quick: Create and run custom rules in a few lines of code
  • Flexible: Rules over file(s), their subelements and more (see Files tutorial)
  • Minimal: Gentle learning curve - <1000 lines of code, tutorials, API reference

🚀 Quick start 📚 Documentation 🤝 Contribute 👍 Adopters 📜 Legal

Quick start

Tip

Check out more examples (here) to get a better feel of lintkit.

Below are ~20 lines of code implementing custom linter with two rules and running it on three files:

import lintkit

# Set the application identity and public rule prefix
lintkit.settings.name.tool = "noutils"
lintkit.settings.name.rule = "NOUTILS"


class _NoUtils(lintkit.check.Regex, lintkit.loader.Python, lintkit.rule.Node):
    def regex(self):
        # Regex to match util(s) variations in function/class name
        return r"_?[Uu]til(s|ities)?"

    def values(self):
        # Yield class or function names from a Python file
        data = self.getitem("nodes_map")
        for node in data[self.ast_class()]:
            yield lintkit.Value.from_python(node.name, node)

    def message(self, _):
        return f"{self.ast_class()} name contains util(s) word"


# Concrete rules and their codes
# Disabling linter using noqas supported out of the box!
class ClassNoUtils(_NoUtils, code=0):  # noqa: NOUTILS0
    # ast type we want to focus on in this rule
    def ast_class(self):
        return ast.ClassDef


class FunctionNoUtils(_NoUtils, code=1):  # noqa: NOUTILS0
    def ast_class(self):
        return ast.FunctionDef


lintkit.run(["linter.py", "file1.py", "file2.py"])

# Example output
# /path/file1.py:23:17 NOUTILS0: ClassDef name contains util(s) word
# /path/file2.py:73:21 NOUTILS1: FunctionDef name contains util(s) word

Installation

Tip

You can use your favorite package manager like uv, hatch or pdm instead of pip.

> pip install lintkit

Note

lintkit provides extras (config, mcp, output, rich, toml, yaml, and all containing everything) to provide additional functionality.

# To create rules utilizing YAML
> pip install lintkit[rich, yaml]

# To load linter configuration
> pip install lintkit[config]

Learn

Check out the following links to learn more about lintkit:

Contribute

We welcome your contributions! Start here:

Legal

  • This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
  • This project is copyrighted by open-nudge - the appropriate copyright notice is included in each file.

About

Build your own linter in minutes - from Python code to config files (YAML, JSON, TOML)

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

14 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages