Skip to content

Zzzen/pyright-lint

Repository files navigation

Pyright Lint

🚧 A expremental linter based on Pyright at early stage of development. Do not use it in production. 🚧

Table of contents

Available Rules

consistentUnionTypeDeclarations

Require consistently using either X | Y or Union[X, Y] for union type declarations.

from typing import Union
a: Union[int, float]
# ⚠️ Use `|` instead of `Typing.Union`.

noExplicitAny

Disallow the Any type.

a: Any
# ⚠️ Unexpected Any. Specify a different type.

noMisusedAwaitable

Disallow Awaitable in places not designed to handle them.

import asyncio
async def foo():
    pass
if foo():
    pass
# ⚠️ Expected non-Awaitable value in a boolean conditional. Did you forget to use 'await'?

noRedundantTypeConstituents

Disallow members of unions that do nothing.

foo: Any | int = 1
# ⚠️ 'Any' overrides all other types in this union type.
bar: int | Literal[1] = 1
# ⚠️ 'Literal[1]' is overridden by 'int' in this union type.

preferReturnSelfType

Enforce that Self is used when only Self type is returned.

class Foo:
    def foo(self) -> "Foo":
        return self
# ⚠️ Use `Self` type instead.

restrictTemplateExpressions

Enforce template literal expressions to be of string type.

class Foo:
    pass
f"{Foo()}"
# ⚠️ Invalid type "Foo" of template literal expression.

Configuration

This project assumes you have configured pyright properly. You can configure the rules in your pyright-lint.config.json file.

{
  "include": ["**/*.py"],
  "consistentUnionTypeDeclarations": true,
  "noExplicitAny": true,
  "noMisusedAwaitable": true,
  "noRedundantTypeConstituents": true,
  "preferReturnSelfType": true,
  "restrictTemplateExpressions": true
}

Development

Setup

npm install

Test

npm run test

Lint

npm run lint

Build

npm run build

Issues

if you have any questions or suggestions, please create an issue.

License

MIT

Acknowledgements

About

A expremental linter based on Pyright.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published