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

NEW @W-17042397@ Detail output now has multilocation support #1673

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

jfeingold35
Copy link
Collaborator

No description provided.

message: This is a message
locations:
__PATH_TO_FILE_A__:20:1
**__PATH_TO_FILE_Z__:2:1 This is a comment at Location 2**
Copy link
Collaborator

@stephen-carter-at-sf stephen-carter-at-sf Nov 14, 2024

Choose a reason for hiding this comment

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

What does ** do? Is that just to mark it as primary?

You'll want to ask Marcelino about this one I think to see if he thinks this is a good way to display things.
I'm not sure how I feel about this. Also it may get in the way with the ability to click what turns into a link in vscode and intellij when folks run sf code-analyzer run from the terminal inside of their IDE. It is really a useful feature that /some/file.txt:20:1 is clickable. (This again is one of the reasons why I think we should have detail view as the default view). But if ** is attached ... not sure if it'll recognize the file:line:col pattern.
Maybe instead, we could have:

        __PATH_TO_FILE_A__:20:1
      > __PATH_TO_FILE_Z__:2:1 This is a comment at Location 2
        __PATH_TO_FILE_A__:1:1 This is a comment at Location 3

where the we replace the indent with > is inside of the indent here and it points to the primary without shifting it to the right and while leaving a space before it still.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do. Thanks.

Comment on lines 92 to 102
function stringifyLocations(codeLocations: CodeLocation[], primaryIndex: number): string[] {
const locationStrings: string[] = [];

codeLocations.forEach((loc, idx) => {
const commentPortion: string = loc.getComment() ? ` ${loc.getComment()}` : '';
const rawLocationString: string = `${loc.getFile()}:${loc.getStartLine()}:${loc.getStartColumn()}${commentPortion}`;
locationStrings.push(idx === primaryIndex ? `**${rawLocationString}**` : rawLocationString);
});

return locationStrings;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is an false assumption here that if the locations length is 1 then there is no comment. This may not be the case with flowtest or with other engines in the future.

So can we instead have on line 83

    location: stringifyLocation(primaryLocation)

and then here we would have something like:

function stringifyLocations(codeLocations: CodeLocation[], primaryIndex:number): string[] {
    codeLocations.map(stringifyLocations);
    codeLocations[primaryIndex] = `**${codeLocations[primaryIndex]}**`;
}

function stringifyLocation(loc: CodeLocation): string {
    const commentPortion: string = loc.getComment() ? ` ${loc.getComment()}` : '';
	return `${loc.getFile()}:${loc.getStartLine()}:${loc.getStartColumn()}${commentPortion}`;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Counterpoint: If there's only one location, then any comment that location might have is likely to be redundant with the top-level violation message. I'm trying to imagine a reason that they'd contain completely different information and nothing's coming to mind.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see your point... so the engine authors really shouldn't be doing this. But in the event they do - and they may have a legitimate reason for it... do we really want to prevent their comment from being seen? So best to code the clients to the core api and what it can can't do instead of assuming the current use cases will be the same as the future use cases.

Copy link
Collaborator

@stephen-carter-at-sf stephen-carter-at-sf left a comment

Choose a reason for hiding this comment

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

Just one small thing that you might consider fixing. Otherwise approved.

codeLocations.forEach((loc, idx) => {
const commentPortion: string = loc.getComment() ? ` ${loc.getComment()}` : '';
const locationString: string = `${loc.getFile()}:${loc.getStartLine()}:${loc.getStartColumn()}${commentPortion}`;
const mainPortion: string = `${primaryIndex != null && primaryIndex === idx ? '(main) ' : ''}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason you put this all in backticks?

Why not just do:
const mainPortion: string = primaryIndex != null && primaryIndex === idx ? '(main) ' : '';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, you're right, that's the better way to do it.

@jfeingold35 jfeingold35 merged commit 4981ee1 into dev-5 Nov 15, 2024
12 checks passed
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