-
Notifications
You must be signed in to change notification settings - Fork 104
SONARPY-898 Avoid failing on older SonarLint #1002
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,6 @@ | |
| import org.sonar.api.measures.CoreMetrics; | ||
| import org.sonar.api.measures.FileLinesContext; | ||
| import org.sonar.api.measures.FileLinesContextFactory; | ||
| import org.sonar.api.notifications.AnalysisWarnings; | ||
| import org.sonar.api.rule.RuleKey; | ||
| import org.sonar.api.utils.Version; | ||
| import org.sonar.api.utils.log.LogTester; | ||
|
|
@@ -73,6 +72,7 @@ | |
| import org.sonar.plugins.python.indexer.PythonIndexer; | ||
| import org.sonar.plugins.python.indexer.SonarLintPythonIndexer; | ||
| import org.sonar.plugins.python.indexer.TestModuleFileSystem; | ||
| import org.sonar.plugins.python.warnings.AnalysisWarningsWrapper; | ||
| import org.sonar.python.checks.CheckList; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
@@ -131,7 +131,7 @@ public void scanFile(PythonVisitorContext visitorContext) { | |
|
|
||
| private ActiveRules activeRules; | ||
|
|
||
| private final AnalysisWarnings analysisWarning = mock(AnalysisWarnings.class); | ||
| private final AnalysisWarningsWrapper analysisWarning = mock(AnalysisWarningsWrapper.class); | ||
|
|
||
| @org.junit.Rule | ||
| public LogTester logTester = new LogTester(); | ||
|
|
@@ -319,7 +319,7 @@ public void cross_files_issues_only_one_file_analyzed() { | |
| // "mod.py" created but not added to context | ||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you change CUSTOM_RULES -> null ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to have a unit test with a |
||
| assertThat(context.allIssues()).hasSize(1); | ||
| Issue issue = context.allIssues().iterator().next(); | ||
| assertThat(issue.primaryLocation().inputComponent()).isEqualTo(mainFile); | ||
|
|
@@ -341,7 +341,7 @@ public void no_indexer_when_project_too_large_sonarlint() { | |
|
|
||
| InputFile mainFile = inputFile("main.py"); | ||
| PythonIndexer pythonIndexer = pythonIndexer(Collections.singletonList(mainFile)); | ||
| sensor(CUSTOM_RULES, pythonIndexer, null).execute(context); | ||
| sensor(CUSTOM_RULES, pythonIndexer, analysisWarning).execute(context); | ||
| assertThat(context.allIssues()).isEmpty(); | ||
| assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Project symbol table deactivated due to project size (total number of lines is 4, maximum for indexing is 1)"); | ||
| assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Update \"sonar.python.sonarlint.indexing.maxlines\" to set a different limit."); | ||
|
|
@@ -358,7 +358,7 @@ public void loop_in_class_hierarchy() { | |
| InputFile mainFile = inputFile("modA.py"); | ||
| InputFile modFile = inputFile("modB.py"); | ||
| PythonIndexer pythonIndexer = pythonIndexer(Arrays.asList(mainFile, modFile)); | ||
| sensor(null, pythonIndexer, null).execute(context); | ||
| sensor(null, pythonIndexer, analysisWarning).execute(context); | ||
|
|
||
| assertThat(context.allIssues()).hasSize(1); | ||
| } | ||
|
|
@@ -494,7 +494,7 @@ public void cancelled_analysis() { | |
| InputFile inputFile = inputFile(FILE_1); | ||
| activeRules = (new ActiveRulesBuilder()).build(); | ||
| context.setCancelled(true); | ||
| sensor(null, null, null).execute(context); | ||
| sensor(null, null, analysisWarning).execute(context); | ||
| assertThat(context.measure(inputFile.key(), CoreMetrics.NCLOC)).isNull(); | ||
| assertThat(context.allAnalysisErrors()).isEmpty(); | ||
| } | ||
|
|
@@ -562,20 +562,20 @@ private PythonSensor sensor() { | |
| return sensor(CUSTOM_RULES, null, analysisWarning); | ||
| } | ||
|
|
||
| private PythonSensor sensor(@Nullable PythonCustomRuleRepository[] customRuleRepositories, @Nullable PythonIndexer indexer, @Nullable AnalysisWarnings analysisWarnings) { | ||
| private PythonSensor sensor(@Nullable PythonCustomRuleRepository[] customRuleRepositories, @Nullable PythonIndexer indexer, AnalysisWarningsWrapper analysisWarnings) { | ||
| FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); | ||
| FileLinesContext fileLinesContext = mock(FileLinesContext.class); | ||
| when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(fileLinesContext); | ||
| CheckFactory checkFactory = new CheckFactory(activeRules); | ||
| if (indexer == null && customRuleRepositories == null) { | ||
| return new PythonSensor(fileLinesContextFactory, checkFactory, mock(NoSonarFilter.class), analysisWarnings); | ||
| } | ||
| if (indexer != null && customRuleRepositories == null) { | ||
| return new PythonSensor(fileLinesContextFactory, checkFactory, mock(NoSonarFilter.class), indexer); | ||
| } | ||
| if (indexer == null) { | ||
| return new PythonSensor(fileLinesContextFactory, checkFactory, mock(NoSonarFilter.class), customRuleRepositories, analysisWarnings); | ||
| } | ||
| if (customRuleRepositories == null) { | ||
| return new PythonSensor(fileLinesContextFactory, checkFactory, mock(NoSonarFilter.class), indexer, analysisWarnings); | ||
| } | ||
| return new PythonSensor(fileLinesContextFactory, checkFactory, mock(NoSonarFilter.class), customRuleRepositories, indexer, analysisWarnings); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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,
PythonIndexerended up not being injected properly...