-
Notifications
You must be signed in to change notification settings - Fork 47
(Feat): Add linter: ty #1028
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): Add linter: ty #1028
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @TylerJang27, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces the ty
linter to the Trunk toolset. According to the description, ty
is a static type checker for Python. The changes include adding ty
to the list of supported linters in the README.md
file and creating a new plugin configuration file (plugin.yaml
) for ty
. Additionally, test data and snapshot files are added to ensure the linter functions as expected.
Highlights
- Linter Integration: The primary focus is the integration of the
ty
linter into the Trunk ecosystem, enabling static type checking for Python code. - Configuration File: A
plugin.yaml
file is created to define the linter's version, download location, and execution commands. - Test Cases: Test cases and snapshot files are added to verify the linter's functionality and ensure consistent output.
Changelog
Click here to see the changelog
- README.md
- Added
ty
to the list of supported Python linters in the table. - Added a link to the
ty
linter's repository in the references section.
- Added
- linters/ty/plugin.yaml
- Created a new plugin configuration file for the
ty
linter. - Configured the linter's download location, version, and execution commands.
- Defined health checks to ensure the linter is functioning correctly.
- Configured the linter to run on Python and Python interface files.
- Created a new plugin configuration file for the
- linters/ty/test_data/basic.in.py
- Added a basic Python test file for the
ty
linter. - The test file includes type annotations and code that should trigger type checking errors.
- Added a basic Python test file for the
- linters/ty/test_data/interface.in.pyi
- Added a Python interface test file for the
ty
linter. - This file tests the linter's ability to check Python interface files (.pyi).
- Added a Python interface test file for the
- linters/ty/test_data/ty_v0.0.1-alpha.1_basic.check.shot
- Created a snapshot file for the basic Python test case.
- This file contains the expected output of the
ty
linter when run on the basic test file.
- linters/ty/test_data/ty_v0.0.1-alpha.1_interface.check.shot
- Created a snapshot file for the Python interface test case.
- This file contains the expected output of the
ty
linter when run on the interface test file.
- linters/ty/ty.test.ts
- Added a test file to run the
ty
linter and compare its output to the snapshot files.
- Added a test file to run the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A new linter arrives,
ty
checks types with zeal,
Code's safety thrives.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Code-Quality-on-PRs is deprecated and will soon be removed. Please see the migration guide for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the ty
linter to the Trunk toolset, which enhances Python code analysis. The changes include modifications to the README to reflect the addition of ty
and the creation of necessary configuration and test files for the linter. Overall, the integration seems well-structured, but there are a few points that could be improved.
Summary of Findings
- README.md Linter Alphabetization: The
ty
linter was added to the README.md file, but it was not alphabetized with the other linters. - plugin.yaml Download Source Descriptions: The download sources in the plugin.yaml file lack descriptions, which can reduce readability and maintainability.
- plugin.yaml Suggest If Field: The
suggest_if: never
field in plugin.yaml lacks a comment explaining why Trunk should never suggest enabling this linter. - Test File Descriptions: The test files lack descriptions, which can make it difficult to understand their purpose and what aspects of the linter they are designed to test.
- Snapshot Issues: The snapshots contain several issues related to missing imports and definitions, which can reduce the accuracy of the tests.
Merge Readiness
The pull request introduces the ty
linter to the Trunk toolset. While the integration appears well-structured, there are several issues that need to be addressed before merging. Specifically, the linter alphabetization in the README.md file, the download source descriptions in the plugin.yaml file, the suggest_if
field in the plugin.yaml file, the test file descriptions, and the snapshot issues. I am unable to approve this pull request, and recommend that it not be merged until these issues are addressed.
| 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], [ty] | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files: [python, python-interface] | ||
tools: [ty] | ||
known_good_version: 0.0.1-alpha.1 | ||
suggest_if: never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "5", | ||
"linter": "ty", | ||
"message": "Return type does not match returned value: Expected \`str\`, found \`int\`", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "revealed-type", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_LOW", | ||
"line": "50", | ||
"linter": "ty", | ||
"message": "Revealed type: \`int | None\`", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "undefined-reveal", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_MEDIUM", | ||
"line": "50", | ||
"linter": "ty", | ||
"message": "\`reveal_type\` used without importing it", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "unsupported-operator", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "51", | ||
"linter": "ty", | ||
"message": "Operator \`+\` is unsupported between objects of type \`int | None\` and \`Literal[1]\`", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "revealed-type", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_LOW", | ||
"line": "53", | ||
"linter": "ty", | ||
"message": "Revealed type: \`int | None\`", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "undefined-reveal", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_MEDIUM", | ||
"line": "53", | ||
"linter": "ty", | ||
"message": "\`reveal_type\` used without importing it", | ||
"targetType": "python", | ||
}, | ||
{ | ||
"code": "unsupported-operator", | ||
"column": "1", | ||
"file": "test_data/basic.in.py", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "53", | ||
"linter": "ty", | ||
"message": "Operator \`+\` is unsupported between objects of type \`int | None\` and \`Literal[1]\`", | ||
"targetType": "python", | ||
}, | ||
], | ||
"lintActions": [ | ||
{ | ||
"command": "check", | ||
"fileGroupName": "python", | ||
"linter": "ty", | ||
"paths": [ | ||
"test_data/basic.in.py", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "check", | ||
"fileGroupName": "python", | ||
"linter": "ty", | ||
"paths": [ | ||
"test_data/basic.in.py", | ||
], | ||
"upstream": true, | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [], | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter ty test interface 1`] = ` | ||
{ | ||
"issues": [ | ||
{ | ||
"code": "unresolved-reference", | ||
"column": "1", | ||
"file": "test_data/interface.in.pyi", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "11", | ||
"linter": "ty", | ||
"message": "Name \`overload\` used when not defined", | ||
"targetType": "python-interface", | ||
}, | ||
{ | ||
"code": "unresolved-reference", | ||
"column": "1", | ||
"file": "test_data/interface.in.pyi", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "14", | ||
"linter": "ty", | ||
"message": "Name \`overload\` used when not defined", | ||
"targetType": "python-interface", | ||
}, | ||
{ | ||
"code": "unresolved-reference", | ||
"column": "1", | ||
"file": "test_data/interface.in.pyi", | ||
"issueClass": "ISSUE_CLASS_EXISTING", | ||
"level": "LEVEL_HIGH", | ||
"line": "31", | ||
"linter": "ty", | ||
"message": "Name \`decorated\` used when not defined", | ||
"targetType": "python-interface", | ||
}, | ||
], | ||
"lintActions": [ | ||
{ | ||
"command": "check", | ||
"fileGroupName": "python-interface", | ||
"linter": "ty", | ||
"paths": [ | ||
"test_data/interface.in.pyi", | ||
], | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
{ | ||
"command": "check", | ||
"fileGroupName": "python-interface", | ||
"linter": "ty", | ||
"paths": [ | ||
"test_data/interface.in.pyi", | ||
], | ||
"upstream": true, | ||
"verb": "TRUNK_VERB_CHECK", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [], | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible this may need some pyright-like configuration |
Fixes #1024. https://github.com/astral-sh/ty#readme