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

Write analysis JSON to provided file, format #13

Merged
merged 1 commit into from
Mar 25, 2024
Merged

Write analysis JSON to provided file, format #13

merged 1 commit into from
Mar 25, 2024

Conversation

ryangreenberg
Copy link
Contributor

hakana analyze only respects --output if the filename is "checkpoint_results.json". This PR changes the command to writes the output to any given path and adds --json-format to specify the desired output format.

The options allowed for --json-format are:

  • checkpoint: the current default
  • hh_client: format that can be interpreted in the same way as error messages from Meta's Hack typechecker
  • full: the issue and description with all information from the HPos

After adding hh_client and documenting the meaning of start and end, I opted to add full because it's easier to work with. Details inline; happy to drop hh_client entirely. Can also rename full if desired.

path: path.to_string(),
line: issue.pos.start_line,
start: issue.pos.start_column as u32,
end: (issue.pos.end_offset - issue.pos.start_offset) + (issue.pos.start_column as u32),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explaining this code prompted me to switch to creating FullEntry instead.

I find the meaning of start and end somewhat confusing: they are offsets starting from the offset of the given line. This is equivalent to start_column, end_column when the error is contained to a single line but different for multi-line errors. This is a little annoying to work with programmatically (start_offset and end_offset from the start of the file would be easier).

For this input:

function example(): void {
	takes_int(
		"the quick brown fox jumped over the lazy dog".
		"the quick brown fox jumped over the lazy dog".
		"the quick brown fox jumped over the lazy dog",
	);
}

function takes_int(int $i): void {}

hh_client produces the following output (via hh_client --json | jq .):

{
  "descr": "Invalid argument",
  "path": "/mnt/dev1725/example.hack",
  "line": 3,
  "start": 3,
  "end": 148,
  "code": 4110
}

This shows up as an error at:

function example(): void {
	takes_int(
		"the quick brown fox jumped over the lazy dog".
		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		"the quick brown fox jumped over the lazy dog".
		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		"the quick brown fox jumped over the lazy dog",
		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	);
}

In the given example, the start of line 3 corresponds to character 38. +3 chars gives you the opening " and +148 chars gives you the closing " 2 lines later.

@ryangreenberg ryangreenberg marked this pull request as ready for review March 25, 2024 17:01
@muglug muglug merged commit fa2087a into main Mar 25, 2024
2 checks passed
@muglug muglug deleted the json_output branch March 25, 2024 17:14
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