Skip to content

Commit b4b5209

Browse files
authored
feat: Support basedpyright linter (#1)
* feat: Support basedpyright linter * test: Update test snapshot for basedpyright * chore: Fix README and reformat * chore: Update test with circular deps * chore: Update test
1 parent 4dbfeab commit b4b5209

File tree

6 files changed

+809
-53
lines changed

6 files changed

+809
-53
lines changed

README.md

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,59 @@ Enable the following tools via:
3838
trunk check enable {linter}
3939
```
4040

41-
| Technology | Linters |
42-
| --------------- | ------------------------------------------------------------------------------------------------------------------------ |
43-
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
44-
| Ansible | [ansible-lint] |
45-
| Apex | [pmd] |
46-
| Bash | [shellcheck], [shfmt] |
47-
| Bazel, Starlark | [buildifier] |
48-
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
49-
| C# | [dotnet-format] |
50-
| CircleCI Config | [circleci] |
51-
| Cloudformation | [cfnlint], [checkov] |
52-
| CMake | [cmake-format] |
53-
| CSS, SCSS | [stylelint], [prettier] |
54-
| Cue | [cue-fmt] |
55-
| Dart | [dart] |
56-
| Docker | [hadolint], [checkov] |
57-
| Dotenv | [dotenv-linter] |
58-
| GitHub | [actionlint] |
59-
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
60-
| GraphQL | [graphql-schema-linter], [prettier] |
61-
| HAML | [haml-lint] |
62-
| HTML Templates | [djlint] |
63-
| Java | [google-java-format], [pmd], [semgrep] |
64-
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
65-
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
66-
| Kotlin | [detekt], [ktlint] |
67-
| Kubernetes | [kube-linter] |
68-
| Lua | [stylua] |
69-
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
70-
| Nix | [nixpkgs-fmt] |
71-
| package.json | [sort-package-json] |
72-
| Perl | [perlcritic], [perltidy] |
73-
| PHP | [php-cs-fixer], [phpstan] |
74-
| PNG | [oxipng] |
75-
| PowerShell | [psscriptanalyzer] |
76-
| Prisma | [prisma] |
77-
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
78-
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
79-
| Rego | [regal], [opa] |
80-
| Renovate | [renovate] |
81-
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
82-
| Rust | [clippy], [rustfmt] |
83-
| Scala | [scalafmt] |
84-
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
85-
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
86-
| SVG | [svgo] |
87-
| Swift | [stringslint], [swiftlint], [swiftformat] |
88-
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
89-
| Terragrunt | [terragrunt] |
90-
| Textproto | [txtpbfmt] |
91-
| TOML | [taplo] |
92-
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
93-
| YAML | [prettier], [semgrep], [yamllint] |
41+
| Technology | Linters |
42+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
43+
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
44+
| Ansible | [ansible-lint] |
45+
| Apex | [pmd] |
46+
| Bash | [shellcheck], [shfmt] |
47+
| Bazel, Starlark | [buildifier] |
48+
| C, C++ | [clang-format], [clang-tidy], [include-what-you-use], [pragma-once] |
49+
| C# | [dotnet-format] |
50+
| CircleCI Config | [circleci] |
51+
| Cloudformation | [cfnlint], [checkov] |
52+
| CMake | [cmake-format] |
53+
| CSS, SCSS | [stylelint], [prettier] |
54+
| Cue | [cue-fmt] |
55+
| Dart | [dart] |
56+
| Docker | [hadolint], [checkov] |
57+
| Dotenv | [dotenv-linter] |
58+
| GitHub | [actionlint] |
59+
| Go | [gofmt], [gofumpt], [goimports], [gokart], [golangci-lint], [golines], [semgrep] |
60+
| GraphQL | [graphql-schema-linter], [prettier] |
61+
| HAML | [haml-lint] |
62+
| HTML Templates | [djlint] |
63+
| Java | [google-java-format], [pmd], [semgrep] |
64+
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
65+
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
66+
| Kotlin | [detekt], [ktlint] |
67+
| Kubernetes | [kube-linter] |
68+
| Lua | [stylua] |
69+
| Markdown | [deno], [markdownlint], [markdownlint-cli2], [markdown-link-check], [markdown-table-prettify], [prettier], [remark-lint] |
70+
| Nix | [nixpkgs-fmt] |
71+
| package.json | [sort-package-json] |
72+
| Perl | [perlcritic], [perltidy] |
73+
| PHP | [php-cs-fixer], [phpstan] |
74+
| PNG | [oxipng] |
75+
| PowerShell | [psscriptanalyzer] |
76+
| Prisma | [prisma] |
77+
| Protobuf | [buf] (breaking, lint, and format), [clang-format], [clang-tidy] |
78+
| Python | [autopep8], [bandit], [black], [flake8], [isort], [mypy], [pylint], [basedpyright], [pyright], [semgrep], [yapf], [ruff], [sourcery] |
79+
| Rego | [regal], [opa] |
80+
| Renovate | [renovate] |
81+
| Ruby | [brakeman], [rubocop], [rufo], [semgrep], [standardrb] |
82+
| Rust | [clippy], [rustfmt] |
83+
| Scala | [scalafmt] |
84+
| Security | [checkov], [dustilock], [nancy], [osv-scanner], [snyk], [tfsec], [trivy], [trufflehog], [terrascan] |
85+
| SQL | [sqlfluff], [sqlfmt], [sql-formatter], [squawk] |
86+
| SVG | [svgo] |
87+
| Swift | [stringslint], [swiftlint], [swiftformat] |
88+
| Terraform | [terraform] (validate and fmt), [checkov], [tflint], [tfsec], [terrascan], [tofu] |
89+
| Terragrunt | [terragrunt] |
90+
| Textproto | [txtpbfmt] |
91+
| TOML | [taplo] |
92+
| Typescript | [deno], [eslint], [prettier], [rome], [semgrep] |
93+
| YAML | [prettier], [semgrep], [yamllint] |
9494

9595
[actionlint]: https://trunk.io/linters/infra/actionlint
9696
[ansible-lint]: https://github.com/ansible/ansible-lint#readme
@@ -157,6 +157,7 @@ trunk check enable {linter}
157157
[prisma]: https://github.com/prisma/prisma#readme
158158
[psscriptanalyzer]: https://github.com/PowerShell/PSScriptAnalyzer
159159
[pylint]: https://github.com/PyCQA/pylint#readme
160+
[basedpyright]: https://github.com/DetachHead/basedpyright
160161
[pyright]: https://github.com/microsoft/pyright
161162
[regal]: https://github.com/StyraInc/regal#readme
162163
[remark-lint]: https://github.com/remarkjs/remark-lint#readme
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { linterCheckTest } from "tests";
2+
3+
linterCheckTest({ linterName: "basedpyright" });
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import sys
5+
6+
results = []
7+
8+
for result in json.load(sys.stdin)["generalDiagnostics"]:
9+
parse = {
10+
"level": result["severity"] if result["severity"] != "information" else "note",
11+
"locations": [
12+
{
13+
"physicalLocation": {
14+
"artifactLocation": {
15+
"uri": result["file"],
16+
},
17+
# Add region only if range information is available
18+
# e.g. reportImportCycles does not have "range" information
19+
**(
20+
{
21+
"region": {
22+
"startLine": result["range"]["start"]["line"]
23+
+ 1, # basedpyright is 0-indexed, SARIF is 1-indexed
24+
"startColumn": result["range"]["start"]["character"]
25+
+ 1,
26+
"endLine": result["range"]["end"]["line"] + 1,
27+
"endColumn": result["range"]["end"]["character"] + 1,
28+
}
29+
}
30+
if "range" in result
31+
else {}
32+
),
33+
}
34+
}
35+
],
36+
"message": {
37+
"text": result["message"].replace("Â", ""),
38+
},
39+
}
40+
if "rule" in result:
41+
parse["ruleId"] = result["rule"]
42+
results.append(parse)
43+
44+
sarif = {
45+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
46+
"version": "2.1.0",
47+
"runs": [{"results": results}],
48+
}
49+
50+
print(json.dumps(sarif, indent=2))

linters/basedpyright/plugin.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: 0.1
2+
tools:
3+
definitions:
4+
- name: basedpyright
5+
runtime: python
6+
package: basedpyright
7+
shims: [basedpyright]
8+
known_good_version: 1.28.1
9+
lint:
10+
definitions:
11+
- name: basedpyright
12+
files: [python]
13+
suggest_if: config_present
14+
description:
15+
Basedpyright is a fork of pyright with various type checking improvements, pylance features
16+
and more
17+
commands:
18+
- name: lint
19+
output: sarif
20+
run: basedpyright --outputjson ${target}
21+
success_codes: [0, 1]
22+
read_output_from: stdout
23+
batch: true
24+
cache_results: false
25+
parser:
26+
runtime: python
27+
run: python3 ${plugin}/linters/basedpyright/basedpyright_to_sarif.py
28+
tools: [basedpyright]
29+
direct_configs:
30+
- pyrightconfig.json
31+
affects_cache:
32+
- pyproject.toml
33+
- setup.cfg
34+
issue_url_format: https://github.com/DetachHead/basedpyright/blob/main/docs/configuration/config-files.md#{}
35+
known_good_version: 1.28.1
36+
version_command:
37+
parse_regex: basedpyright ${semver}
38+
run: basedpyright --version

0 commit comments

Comments
 (0)