Skip to content

SONARPY-898 Avoid failing on older SonarLint #1002

Merged
guillaume-dequenne merged 3 commits intomasterfrom
SONARPY-898
Nov 15, 2021
Merged

SONARPY-898 Avoid failing on older SonarLint #1002
guillaume-dequenne merged 3 commits intomasterfrom
SONARPY-898

Conversation

@guillaume-dequenne
Copy link
Copy Markdown
Contributor

No description provided.

@guillaume-dequenne guillaume-dequenne force-pushed the SONARPY-898 branch 2 times, most recently from 09d0b9c to 63bd839 Compare November 15, 2021 08:49
@guillaume-dequenne guillaume-dequenne changed the title wip sonarpy-898 SONARPY-898 Avoid failing on older SonarLint Nov 15, 2021
@guillaume-dequenne guillaume-dequenne marked this pull request as ready for review November 15, 2021 09:26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To me it's not clear what constructor will be called when PythonIndexer is present and PythonCustomRuleRepository is not.

public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactory checkFactory, NoSonarFilter noSonarFilter, AnalysisWarnings analysisWarnings) {
this(fileLinesContextFactory, checkFactory, noSonarFilter, null, null, analysisWarnings);
public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactory checkFactory,
NoSonarFilter noSonarFilter, AnalysisWarningsWrapper defaultAnalysisWarningsWrapper) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can call the parameter analysisWarnings for consistency with other constructors

this(fileLinesContextFactory, checkFactory, noSonarFilter, null, null, defaultAnalysisWarningsWrapper);
}

public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactory checkFactory, NoSonarFilter noSonarFilter,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In recent version of SonarLint, my understanding is that PythonIndexer will be injected, while PythonCustomRuleRepository won't be found. So what constructor will be called in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Indeed, due to the missing constructor, PythonIndexer ended up not being injected properly...


public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactory checkFactory, NoSonarFilter noSonarFilter,
@Nullable PythonCustomRuleRepository[] customRuleRepositories, @Nullable PythonIndexer indexer, @Nullable AnalysisWarnings analysisWarnings) {
@Nullable PythonCustomRuleRepository[] customRuleRepositories, @Nullable PythonIndexer indexer, @Nullable AnalysisWarningsWrapper analysisWarnings) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe we can remove @Nullable annotation from analysisWarning parameter and on the corresponding field given that we always provide it.
Hence we might be able to remove the nullability check at line 117

this.noSonarFilter = noSonarFilter;
this.indexer = indexer;
this.analysisWarnings = analysisWarnings;
LOG.info("CONSTRUCTOR CALLED: WARNING, RULE REPOSITORY AND INDEXER");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you forgot to remove this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Woops...Thanks! 😅

public PythonSensor(FileLinesContextFactory fileLinesContextFactory, CheckFactory checkFactory, NoSonarFilter noSonarFilter,
PythonCustomRuleRepository[] customRuleRepositories, AnalysisWarnings analysisWarnings) {
this(fileLinesContextFactory, checkFactory, noSonarFilter, customRuleRepositories, null, analysisWarnings);
PythonIndexer indexer, AnalysisWarningsWrapper analysisWarnings) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's be consistent about indentation; either we align with the parameters at the precedent line, or we uses two-space indentation everywhere (even on other constructors)

InputFile modFile = createInputFile("mod.py");
PythonIndexer pythonIndexer = pythonIndexer(Arrays.asList(mainFile, modFile));
sensor(CUSTOM_RULES, pythonIndexer, null).execute(context);
sensor(null, pythonIndexer, analysisWarning).execute(context);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why did you change CUSTOM_RULES -> null ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to have a unit test with a PythonIndexer and without a PythonCustomRuleRepository to reflect the new constructor.

@sonarsource-next
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@guillaume-dequenne guillaume-dequenne merged commit 30629fb into master Nov 15, 2021
@guillaume-dequenne guillaume-dequenne deleted the SONARPY-898 branch November 15, 2021 14:11
hashicorp-vault-sonar-prod bot pushed a commit that referenced this pull request Mar 24, 2026
…nnotated (#1002)

Co-authored-by: Vibe Bot <[email protected]>
GitOrigin-RevId: cbb9c9f4c9648b2e541e997c467235569a1f7301
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