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

[bug] json output is off by one #1002

Closed
cameronbrill opened this issue Mar 19, 2024 · 3 comments
Closed

[bug] json output is off by one #1002

cameronbrill opened this issue Mar 19, 2024 · 3 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@cameronbrill
Copy link

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

Code:

ObjectName.increment_counter(
  foo="bar",
  tags=[
    f"tag_name:'{tag_value.an_id}'"
  ],
)

Pattern:

rule:
  kind: keyword_argument
  regex: (?i)(?:\{id\}|\{.+_id\}|\{.+\.id\})
  inside:
    pattern: ObjectName.increment_counter($$$)
    stopBy: end

πŸ™ Actual behavior

The start and end lines for all json output are off by one. I am using a VS Code task with a problem matcher to display squiggly lines when ast-grep finds an error, but the squiggly lines currently show up on the wrong line because of this.

  • βœ… ast-grep scan shows the correct start line and column (3:3)
  • βœ… ast-grep scan --format github shows the correct start and end lines (line=3,endLine=5)
  • ❌ ast-grep scan --json=stream lines off by one ({start: {line: 2}, end: {line:4}})
  • ❌ ast-grep scan --json=pretty lines off by one ({start: {line: 2}, end: {line:4}})
  • ❌ ast-grep scan --json=compact lines off by one ({start: {line: 2}, end: {line:4}})

πŸ™‚ Expected behavior

I expect the start and end lines in the json output to be the same as those from other output formats.

  • βœ… ast-grep scan --json=stream should show ({start: {line: 3}, end: {line:5}})
  • βœ… ast-grep scan --json=pretty should show ({start: {line: 3}, end: {line:5}})
  • βœ… ast-grep scan --json=compact should show ({start: {line: 3}, end: {line:5}})
@cameronbrill cameronbrill added the bug Something isn't working label Mar 19, 2024
@HerringtonDarkholme
Copy link
Member

JSON's output line and column is zero-based because most of programming language is zero based.

@HerringtonDarkholme
Copy link
Member

Also, if you need to display errors. https://marketplace.visualstudio.com/items?itemName=ast-grep.ast-grep-vscode the official LSP plugin is recommended.

@HerringtonDarkholme HerringtonDarkholme added question Further information is requested wontfix This will not be worked on and removed bug Something isn't working labels Mar 19, 2024
@cameronbrill
Copy link
Author

okay that's fair, we were trying this because the vs code extension doesn't work on my teams codebase right now. but, that's unrelated to this repo, so I'll just open an issue on the vs code extension repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants