Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support basedpyright linter #990

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 54 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,59 @@ Enable the following tools via:
trunk check enable {linter}
```

| Technology | Linters |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
| Bazel, Starlark | [buildifier] |
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
| C# | [dotnet-format] |
| CircleCI Config | [circleci] |
| Cloudformation | [cfnlint], [checkov] |
| CMake | [cmake-format] |
| CSS, SCSS | [stylelint], [prettier] |
| Cue | [cue-fmt] |
| Dart | [dart] |
| Docker | [hadolint], [checkov] |
| Dotenv | [dotenv-linter] |
| GitHub | [actionlint] |
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
| GraphQL | [graphql-schema-linter], [prettier] |
| HAML | [haml-lint] |
| HTML Templates | [djlint] |
| Java | [google-java-format], [pmd], [semgrep] |
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
| Kotlin | [detekt], [ktlint] |
| Kubernetes | [kube-linter] |
| Lua | [stylua] |
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
| Nix | [nixpkgs-fmt] |
| package.json | [sort-package-json] |
| Perl | [perlcritic], [perltidy] |
| PHP | [php-cs-fixer], [phpstan] |
| PNG | [oxipng] |
| PowerShell | [psscriptanalyzer] |
| Prisma | [prisma] |
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
| Rego | [regal], [opa] |
| Renovate | [renovate] |
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
| Rust | [clippy], [rustfmt] |
| Scala | [scalafmt] |
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
| SVG | [svgo] |
| Swift | [stringslint], [swiftlint], [swiftformat] |
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
| Terragrunt | [terragrunt] |
| Textproto | [txtpbfmt] |
| TOML | [taplo] |
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
| YAML | [prettier], [semgrep], [yamllint] |
| Technology | Linters |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
| Bazel, Starlark | [buildifier] |
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
| C# | [dotnet-format] |
| CircleCI Config | [circleci] |
| Cloudformation | [cfnlint], [checkov] |
| CMake | [cmake-format] |
| CSS, SCSS | [stylelint], [prettier] |
| Cue | [cue-fmt] |
| Dart | [dart] |
| Docker | [hadolint], [checkov] |
| Dotenv | [dotenv-linter] |
| GitHub | [actionlint] |
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
| GraphQL | [graphql-schema-linter], [prettier] |
| HAML | [haml-lint] |
| HTML Templates | [djlint] |
| Java | [google-java-format], [pmd], [semgrep] |
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
| Kotlin | [detekt], [ktlint] |
| Kubernetes | [kube-linter] |
| Lua | [stylua] |
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
| Nix | [nixpkgs-fmt] |
| package.json | [sort-package-json] |
| Perl | [perlcritic], [perltidy] |
| PHP | [php-cs-fixer], [phpstan] |
| PNG | [oxipng] |
| PowerShell | [psscriptanalyzer] |
| Prisma | [prisma] |
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [basedpyright], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
| Rego | [regal], [opa] |
| Renovate | [renovate] |
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
| Rust | [clippy], [rustfmt] |
| Scala | [scalafmt] |
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
| SVG | [svgo] |
| Swift | [stringslint], [swiftlint], [swiftformat] |
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
| Terragrunt | [terragrunt] |
| Textproto | [txtpbfmt] |
| TOML | [taplo] |
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
| YAML | [prettier], [semgrep], [yamllint] |

[actionlint]: https://trunk.io/linters/infra/actionlint
[ansible-lint]: https://github.com/ansible/ansible-lint#readme
Expand Down Expand Up @@ -157,6 +157,7 @@ trunk check enable {linter}
[prisma]: https://github.com/prisma/prisma#readme
[psscriptanalyzer]: https://github.com/PowerShell/PSScriptAnalyzer
[pylint]: https://github.com/PyCQA/pylint#readme
[basedpyright]: https://github.com/DetachHead/basedpyright
[pyright]: https://github.com/microsoft/pyright
[regal]: https://github.com/StyraInc/regal#readme
[remark-lint]: https://github.com/remarkjs/remark-lint#readme
Expand Down
3 changes: 3 additions & 0 deletions linters/basedpyright/basedpyright.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { linterCheckTest } from "tests";

linterCheckTest({ linterName: "basedpyright" });
50 changes: 50 additions & 0 deletions linters/basedpyright/basedpyright_to_sarif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

import json
import sys

results = []

for result in json.load(sys.stdin)["generalDiagnostics"]:
parse = {
"level": result["severity"] if result["severity"] != "information" else "note",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": result["file"],
},
# Add region only if range information is available
# e.g. reportImportCycles does not have "range" information
**(
{
"region": {
"startLine": result["range"]["start"]["line"]
+ 1, # basedpyright is 0-indexed, SARIF is 1-indexed
"startColumn": result["range"]["start"]["character"]
+ 1,
"endLine": result["range"]["end"]["line"] + 1,
"endColumn": result["range"]["end"]["character"] + 1,
}
}
if "range" in result
else {}
),
}
}
],
"message": {
"text": result["message"].replace("Â", ""),
},
}
if "rule" in result:
parse["ruleId"] = result["rule"]
results.append(parse)

sarif = {
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [{"results": results}],
}

print(json.dumps(sarif, indent=2))
38 changes: 38 additions & 0 deletions linters/basedpyright/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 0.1
tools:
definitions:
- name: basedpyright
runtime: python
package: basedpyright
shims: [basedpyright]
known_good_version: 1.28.1
lint:
definitions:
- name: basedpyright
files: [python]
suggest_if: config_present
description:
Basedpyright is a fork of pyright with various type checking improvements, pylance features
and more
commands:
- name: lint
output: sarif
run: basedpyright --outputjson ${target}
success_codes: [0, 1]
read_output_from: stdout
batch: true
cache_results: false
parser:
runtime: python
run: python3 ${plugin}/linters/basedpyright/basedpyright_to_sarif.py
tools: [basedpyright]
direct_configs:
- pyrightconfig.json
affects_cache:
- pyproject.toml
- setup.cfg
issue_url_format: https://github.com/DetachHead/basedpyright/blob/main/docs/configuration/config-files.md#{}
known_good_version: 1.28.1
version_command:
parse_regex: basedpyright ${semver}
run: basedpyright --version
Loading