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

PromptString linter: Only error when the reported violation is within one of the changed range #3810

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

philipp-spiess
Copy link
Contributor

@philipp-spiess philipp-spiess commented Apr 16, 2024

As the title suggest, we only want to emit linter errors when new call sites were added. The previous rule would fire too often.

Test plan

  • Add a change to the bottom of vscode/src/chat/chat-view/SimpleChatPanelProvider.ts that adds an unsafe_ API call
  • Run pnpm ts-node lints/safe-prompts.ts pnpm ts-node lints/git-diff-ts-ranges.ts`
  • Observe that only an error for this change is emitted.

Copy link

‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces usage of unsafe_ functions or abuses PromptString.

@@ -1255,3 +1255,6 @@ function newChatModelFromSerializedChatTranscript(
function isAbortError(error: Error): boolean {
return error.message === 'aborted' || error.message === 'socket hang up'
}

// Only this unsafe usage should be report
PromptString.unsafe_fromUserQuery('EVIL!')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see only this violation was reported, not the other violations in this file


const EXTENSIONS = ['ts', 'tsx']

exec('git diff --unified=0 origin/main', (error, stdout, stderr) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 100% cody's doing but I validated it against @umpox's PR: #3797 and the ranges it yields seem great!

Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix :)

@philipp-spiess philipp-spiess merged commit ac5fae2 into main Apr 16, 2024
21 checks passed
@philipp-spiess philipp-spiess deleted the ps/only-lint-on-added-content branch April 16, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants