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

SONARPY-2014 SONARPY-2377 Repair rules reading PythonVisitorContext.pythonFile.contents() on Jupyter notebooks #2192

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

ghislainpiot
Copy link
Contributor

@ghislainpiot ghislainpiot commented Nov 29, 2024

SONARPY-2377

SONARPY-2014 TrailingWhitespaceCheck

@ghislainpiot ghislainpiot changed the title SONARPY-2377 Repair rules reading PythonVisitorContext.pythonFile.contents() on Jupyter notebooks SONARPY-2014 SONARPY-2377 Repair rules reading PythonVisitorContext.pythonFile.contents() on Jupyter notebooks Nov 29, 2024
@ghislainpiot ghislainpiot force-pushed the SONARPY-2014-b branch 7 times, most recently from 3f9b32d to d7eee32 Compare November 29, 2024 10:51
@ghislainpiot ghislainpiot marked this pull request as ready for review November 29, 2024 10:56
@joke1196
Copy link
Contributor

joke1196 commented Dec 2, 2024

Small reminder to rebase master as there are changes in the notebook parser test

@joke1196
Copy link
Contributor

joke1196 commented Dec 2, 2024

We should maybe create a ticket to refactor .pythonLine to have a specific type so that the user will not use .line instead of .pythonLine

Copy link
Contributor

@joke1196 joke1196 left a comment

Choose a reason for hiding this comment

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

I think this looks good, as we mitigate a lot of issues. I think the next step is creating a few tickets.
And for this PR we could maybe move the parser to the frontend?

String fileId = path != null ? path.toString() : ipynbFile.toString();
LocationInFile locationInFile;
if (begin.isCompresssed()) {
var next = mapping.get(lineNumber + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we could do a null check on next, even if it should not happen we could create tests that can throw NPEs.
We could also just create a ticket (if it does not exists yet) and reference it in the code, specifying what we should
do to compute the correct location. This ticket should have a low priority as this should work for the majority of cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would we do if next is null? I am not sure it is recoverable


@Test
void trailing_whitespace() throws IOException {
var inputFile = createInputFile(baseDir, "notebook_trailing_whitespace.ipynb", InputFile.Status.CHANGED, InputFile.Type.MAIN);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this parser then to the frontend? Not sure if there is a reason why we kept it here

@ghislainpiot ghislainpiot requested a review from joke1196 December 2, 2024 14:35
Copy link
Contributor

@joke1196 joke1196 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ghislainpiot ghislainpiot merged commit d7b4278 into master Dec 2, 2024
12 checks passed
@ghislainpiot ghislainpiot deleted the SONARPY-2014-b branch December 2, 2024 15:35
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