diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S106.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S106.json index 009ddb4287..6b7458d00f 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S106.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S106.json @@ -326,6 +326,26 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/models/plugins/pagination.js": [ 180 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +35, +36, +38, +61, +63, +92, +93, +94, +136, +137, +138, +158, +159, +160, +205, +206, +207, +208 +], "javascript-test-sources:src/ecmascript6/Ghost/core/test/functional/base.js": [ 337 ], @@ -377,6 +397,12 @@ 17, 20 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +6, +10, +16, +36 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/js/rest-spread.js": [ 18, 22, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S109.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S109.json index 1ec4905dc2..667192756c 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S109.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S109.json @@ -92306,6 +92306,9 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/index.js": [ 93 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +147 +], "javascript-test-sources:src/ecmascript6/Ghost/core/test/functional/base.js": [ 154, 160, @@ -93644,6 +93647,12 @@ 12, 21 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +13, +13, +13, +13 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/8-iterators.js": [ 37 ], diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1117.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1117.json index 583c2b78eb..cf23689158 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1117.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1117.json @@ -1693,6 +1693,9 @@ 15, 23 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +174 +], "javascript-test-sources:src/ecmascript6/Ghost/core/test/functional/base.js": [ 179, 456, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1314.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1314.json new file mode 100644 index 0000000000..7e42265de0 --- /dev/null +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1314.json @@ -0,0 +1,5 @@ +{ +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +13 +] +} diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S139.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S139.json index f1dc142568..fda80404b8 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S139.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S139.json @@ -1032,6 +1032,13 @@ 13, 19 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +6, +10, +15, +16, +36 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/Gruntfile.js": [ 8 ], diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1441.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1441.json index 98e3711175..5d0966372e 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1441.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1441.json @@ -54737,6 +54737,15 @@ 20, 20 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +5, +5, +6, +10, +13, +24, +36 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/js/rest-spread.js": [ 22, 23, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1451.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1451.json index 537269be47..f08c88fb4b 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1451.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1451.json @@ -3968,6 +3968,9 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/sequence.js": [ 0 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +0 +], "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/validate-themes.js": [ 0 ], @@ -4484,6 +4487,9 @@ "javascript-test-sources:src/ecmascript6/ecmascript6-today/5-set.js": [ 0 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +0 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/Gruntfile.js": [ 0 ], diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1541.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1541.json index 107de33ead..ab6fce2210 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1541.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1541.json @@ -631,6 +631,9 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/downzero.js": [ 18 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +167 +], "javascript-test-sources:src/ecmascript6/expressionist.js/test/parser.spec.js": [ 66, 393 diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1774.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1774.json index 3659e41f23..5b8de735cd 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1774.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S1774.json @@ -1722,6 +1722,10 @@ 10, 14 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +5, +192 +], "javascript-test-sources:src/ecmascript6/Ghost/core/shared/ghost-url.js": [ 56, 57, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S2260.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S2260.json index 922778767f..6e05d05f03 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S2260.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S2260.json @@ -10,11 +10,5 @@ ], "javascript-test-sources:src/ace/tool/templates/theme.js": [ 32 -], -"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ -37 -], -"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ -13 ] } diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3504.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3504.json index adb57cfe44..6f65235205 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3504.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3504.json @@ -15865,6 +15865,15 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/sequence.js": [ 1 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +1, +30, +46, +76, +105, +146, +172 +], "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/validate-themes.js": [ 5, 17, @@ -17505,6 +17514,11 @@ "javascript-test-sources:src/ecmascript6/ecmascript6-today/5-set.js": [ 7 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +5, +15, +33 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/js/rest-spread.js": [ 1, 5, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3512.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3512.json index 3fd4ed4b1d..de021c914d 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3512.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3512.json @@ -1192,6 +1192,10 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/downzero.js": [ 14 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +36, +61 +], "javascript-test-sources:src/ecmascript6/Ghost/core/shared/ghost-url.js": [ 20 ], @@ -1338,6 +1342,12 @@ "javascript-test-sources:src/ecmascript6/ecmascript6-today/4-default-params.js": [ 4 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +6, +10, +16, +36 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/js/rest-spread.js": [ 25 ], diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3533.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3533.json index 8db1250f44..36f379cbc3 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3533.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3533.json @@ -4912,6 +4912,12 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/sequence.js": [ 1 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +1, +2, +3, +4 +], "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/validate-themes.js": [ 5, 6, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3723.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3723.json index 211d58746a..6c8a55a893 100644 --- a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3723.json +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S3723.json @@ -12811,6 +12811,10 @@ "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/read-directory.js": [ 38 ], +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +15, +212 +], "javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/validate-themes.js": [ 19, 33, @@ -14404,6 +14408,10 @@ 13, 31 ], +"javascript-test-sources:src/ecmascript6/ecmascript6-today/6-destructuring.js": [ +28, +29 +], "javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/Gruntfile.js": [ 8, 9, diff --git a/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S6657.json b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S6657.json new file mode 100644 index 0000000000..a43bae501d --- /dev/null +++ b/its/ruling/src/test/expected/js/javascript-test-sources/javascript-S6657.json @@ -0,0 +1,14 @@ +{ +"javascript-test-sources:src/ecmascript6/Ghost/core/server/utils/startup-check.js": [ +37, +38, +62, +64, +92, +94, +110, +112, +205, +208 +] +} diff --git a/its/ruling/src/test/expected/js/jshint/javascript-S2260.json b/its/ruling/src/test/expected/js/jshint/javascript-S2260.json index 7afe9b2961..62ecfa22b0 100644 --- a/its/ruling/src/test/expected/js/jshint/javascript-S2260.json +++ b/its/ruling/src/test/expected/js/jshint/javascript-S2260.json @@ -15,7 +15,7 @@ 2 ], "jshint:tests/unit/fixtures/es6-template-literal-tagged.js": [ -24 +23 ], "jshint:tests/unit/fixtures/es6-template-literal.js": [ 14 diff --git a/its/ruling/src/test/expected/js/mootools-core/javascript-S2260.json b/its/ruling/src/test/expected/js/mootools-core/javascript-S2260.json deleted file mode 100644 index 084ecb6c33..0000000000 --- a/its/ruling/src/test/expected/js/mootools-core/javascript-S2260.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -"mootools-core:Specs/Types/Number.js": [ -20 -] -} diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AbstractAnalysis.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AbstractAnalysis.java index 56ed03b356..d51a3820a7 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AbstractAnalysis.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AbstractAnalysis.java @@ -70,5 +70,9 @@ void initialize(SensorContext context, JsTsChecks checks, AnalysisMode analysisM this.analysisMode = analysisMode; } + protected boolean isJavaScript(InputFile file) { + return inputFileLanguage(file).equals(JavaScriptLanguage.KEY); + } + abstract void analyzeFiles(List inputFiles, List tsConfigs) throws IOException; } diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithProgram.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithProgram.java index e128a5f665..d154e8e432 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithProgram.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithProgram.java @@ -160,7 +160,11 @@ private void analyze(InputFile file, @Nullable TsProgram tsProgram) throws IOExc monitoring.startFile(file); var fileContent = contextUtils.shouldSendFileContent(file) ? file.contents() : null; var request = getJsAnalysisRequest(file, tsProgram, fileContent); - var response = bridgeServer.analyzeWithProgram(request); + + var response = isJavaScript(file) + ? bridgeServer.analyzeJavaScript(request) + : bridgeServer.analyzeTypeScript(request); + analysisProcessor.processResponse(context, checks, file, response); cacheStrategy.writeAnalysisToCache( CacheAnalysis.fromResponse(response.ucfgPaths, response.cpdTokens), diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithWatchProgram.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithWatchProgram.java index 4d65d1dffc..4d24360007 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithWatchProgram.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/AnalysisWithWatchProgram.java @@ -166,8 +166,4 @@ private void analyze(InputFile file, @Nullable TsConfigFile tsConfigFile) throws analysisProcessor.processCacheAnalysis(context, file, cacheAnalysis); } } - - private boolean isJavaScript(InputFile file) { - return inputFileLanguage(file).equals(JavaScriptLanguage.KEY); - } } diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServer.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServer.java index 1a1ce53acc..cc54868d10 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServer.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServer.java @@ -48,8 +48,6 @@ void initLinter( AnalysisResponse analyzeTypeScript(JsAnalysisRequest request) throws IOException; - AnalysisResponse analyzeWithProgram(JsAnalysisRequest request) throws IOException; - AnalysisResponse analyzeCss(CssAnalysisRequest request) throws IOException; AnalysisResponse analyzeYaml(JsAnalysisRequest request) throws IOException; diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServerImpl.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServerImpl.java index ac6619463e..1abb748559 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServerImpl.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/eslint/BridgeServerImpl.java @@ -347,11 +347,6 @@ public AnalysisResponse analyzeTypeScript(JsAnalysisRequest request) throws IOEx return response(request(json, "analyze-ts"), request.filePath); } - @Override - public AnalysisResponse analyzeWithProgram(JsAnalysisRequest request) throws IOException { - return response(request(GSON.toJson(request), "analyze-with-program"), request.filePath); - } - @Override public AnalysisResponse analyzeCss(CssAnalysisRequest request) throws IOException { String json = GSON.toJson(request); diff --git a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/EslintBridgeServerImplTest.java b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/EslintBridgeServerImplTest.java index a5602720ee..4651048bc8 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/EslintBridgeServerImplTest.java +++ b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/EslintBridgeServerImplTest.java @@ -298,7 +298,7 @@ void should_get_answer_from_server_for_program_based_requests() throws Exception programCreated.programId, DEFAULT_LINTER_ID ); - assertThat(bridgeServer.analyzeWithProgram(request).issues).isEmpty(); + assertThat(bridgeServer.analyzeTypeScript(request).issues).isEmpty(); assertThat(bridgeServer.deleteProgram(programCreated)).isTrue(); } diff --git a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JavaScriptEslintBasedSensorTest.java b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JavaScriptEslintBasedSensorTest.java index 812ab69c88..9158279817 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JavaScriptEslintBasedSensorTest.java +++ b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JavaScriptEslintBasedSensorTest.java @@ -130,7 +130,7 @@ public void setUp() throws Exception { tempFolder = new DefaultTempFolder(tempDir, true); when(bridgeServerMock.isAlive()).thenReturn(true); when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(new AnalysisResponse()); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(new AnalysisResponse()); when(bridgeServerMock.getCommandInfo()).thenReturn("bridgeServerMock command info"); when(bridgeServerMock.createTsConfigFile(any())) .thenReturn( @@ -172,7 +172,7 @@ void should_create_issues() throws Exception { "{\"line\":0,\"column\":1,\"ruleId\":\"file-header\",\"message\":\"File issue message\", \"secondaryLocations\": []}" + "]}" ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseIssues); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseIssues); var sensor = createSensor(); DefaultInputFile inputFile = createInputFile(context); @@ -221,7 +221,7 @@ void should_set_quickfixavailable() throws Exception { "}" + "]}" ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseIssues); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseIssues); var sensor = createSensor(); createInputFile(context); @@ -250,7 +250,7 @@ void should_set_quickfixavailable() throws Exception { @Test void should_report_secondary_issue_locations() throws Exception { - when(bridgeServerMock.analyzeWithProgram(any())) + when(bridgeServerMock.analyzeJavaScript(any())) .thenReturn( response( "{ issues: [{\"line\":1,\"column\":2,\"endLine\":3,\"endColumn\":4,\"ruleId\":\"no-all-duplicated-branches\",\"message\":\"Issue message\", " + @@ -291,7 +291,7 @@ void should_report_secondary_issue_locations() throws Exception { @Test void should_not_report_secondary_when_location_are_null() throws Exception { - when(bridgeServerMock.analyzeWithProgram(any())) + when(bridgeServerMock.analyzeJavaScript(any())) .thenReturn( response( "{ issues: [{\"line\":1,\"column\":3,\"endLine\":3,\"endColumn\":5,\"ruleId\":\"no-all-duplicated-branches\",\"message\":\"Issue message\", " + @@ -315,7 +315,7 @@ void should_not_report_secondary_when_location_are_null() throws Exception { @Test void should_report_cost() throws Exception { - when(bridgeServerMock.analyzeWithProgram(any())) + when(bridgeServerMock.analyzeJavaScript(any())) .thenReturn( response( "{ issues: [{\"line\":1,\"column\":2,\"endLine\":3,\"endColumn\":4,\"ruleId\":\"no-all-duplicated-branches\",\"message\":\"Issue message\", " + @@ -349,7 +349,7 @@ void should_save_metrics() throws Exception { AnalysisResponse responseMetrics = response( "{ metrics: {\"ncloc\":[1, 2, 3],\"commentLines\":[4, 5, 6],\"nosonarLines\":[7, 8, 9],\"executableLines\":[10, 11, 12],\"functions\":1,\"statements\":2,\"classes\":3,\"complexity\":4,\"cognitiveComplexity\":5} }" ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseMetrics); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseMetrics); var sensor = createSensor(); DefaultInputFile inputFile = createInputFile(context); @@ -391,7 +391,7 @@ void should_save_only_nosonar_metric_in_sonarlint() throws Exception { @Test void should_save_only_nosonar_metric_for_test() throws Exception { AnalysisResponse responseMetrics = response("{ metrics: {\"nosonarLines\":[7, 8, 9]} }"); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseMetrics); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseMetrics); var sensor = createSensor(); @@ -413,7 +413,7 @@ void should_save_highlights() throws Exception { AnalysisResponse responseCpdTokens = response( "{ highlights: [{\"location\": { \"startLine\":1,\"startCol\":0,\"endLine\":1,\"endCol\":4},\"textType\":\"KEYWORD\"},{\"location\": { \"startLine\":2,\"startCol\":1,\"endLine\":2,\"endCol\":5},\"textType\":\"CONSTANT\"}] }" ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseCpdTokens); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseCpdTokens); var sensor = createSensor(); DefaultInputFile inputFile = createInputFile(context); @@ -432,7 +432,7 @@ void should_save_highlights() throws Exception { @Test void should_save_cpd() throws Exception { AnalysisResponse responseCpdTokens = response(CacheTestUtils.CPD_TOKENS); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(responseCpdTokens); + when(bridgeServerMock.analyzeJavaScript(any())).thenReturn(responseCpdTokens); var sensor = createSensor(); DefaultInputFile inputFile = createInputFile(context); @@ -459,7 +459,7 @@ void should_catch_if_bridge_server_not_started() throws Exception { @Test void should_not_explode_if_no_response() throws Exception { - when(bridgeServerMock.analyzeWithProgram(any())).thenThrow(new IOException("error")); + when(bridgeServerMock.analyzeJavaScript(any())).thenThrow(new IOException("error")); var sensor = createSensor(); DefaultInputFile inputFile = createInputFile(context); sensor.execute(context); @@ -583,7 +583,7 @@ void stop_analysis_if_server_is_not_responding() throws Exception { @Test void should_raise_a_parsing_error() throws IOException { - when(bridgeServerMock.analyzeWithProgram(any())) + when(bridgeServerMock.analyzeJavaScript(any())) .thenReturn( new Gson() .fromJson( @@ -605,7 +605,7 @@ void should_raise_a_parsing_error() throws IOException { @Test void should_not_create_parsing_issue_when_no_rule() throws IOException { - when(bridgeServerMock.analyzeWithProgram(any())) + when(bridgeServerMock.analyzeJavaScript(any())) .thenReturn( new Gson() .fromJson( @@ -661,7 +661,7 @@ void should_send_content_on_sonarlint() throws Exception { createInputFile(ctx); createSensor().execute(ctx); - verify(bridgeServerMock).analyzeWithProgram(captor.capture()); + verify(bridgeServerMock).analyzeJavaScript(captor.capture()); assertThat(captor.getValue().fileContent).isNull(); } @@ -685,13 +685,13 @@ void should_send_content_when_not_utf8() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(JsAnalysisRequest.class); createSensor().execute(ctx); - verify(bridgeServerMock).analyzeWithProgram(captor.capture()); + verify(bridgeServerMock).analyzeJavaScript(captor.capture()); assertThat(captor.getValue().fileContent).isEqualTo(content); } @Test void should_fail_fast() throws Exception { - when(bridgeServerMock.analyzeWithProgram(any())).thenThrow(new IOException("error")); + when(bridgeServerMock.analyzeJavaScript(any())).thenThrow(new IOException("error")); var sensor = createSensor(); MapSettings settings = new MapSettings().setProperty("sonar.internal.analysis.failFast", true); context.setSettings(settings); diff --git a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JsTsSensorTest.java b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JsTsSensorTest.java index 3b5445d964..d1fdccd1eb 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JsTsSensorTest.java +++ b/sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/eslint/JsTsSensorTest.java @@ -328,11 +328,11 @@ void should_not_send_content() throws Exception { var inputFile = createInputFile(ctx); var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of()); when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse()); createTsConfigFile(); createSensor().execute(ctx); var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class); - verify(bridgeServerMock).analyzeWithProgram(captor.capture()); + verify(bridgeServerMock).analyzeTypeScript(captor.capture()); assertThat(captor.getValue().fileContent).isNull(); var deleteCaptor = ArgumentCaptor.forClass(TsProgram.class); @@ -444,11 +444,11 @@ void should_analyze_by_program_on_missing_extended_tsconfig() throws Exception { ) ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse()); ArgumentCaptor captor = ArgumentCaptor.forClass(JsAnalysisRequest.class); createSensor().execute(context); - verify(bridgeServerMock, times(1)).analyzeWithProgram(captor.capture()); + verify(bridgeServerMock, times(1)).analyzeTypeScript(captor.capture()); assertThat(captor.getAllValues()) .extracting(req -> req.filePath) .containsExactlyInAnyOrder(file1.absolutePath()); @@ -496,11 +496,11 @@ void should_analyze_by_program() throws Exception { ) ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse()); ArgumentCaptor captor = ArgumentCaptor.forClass(JsAnalysisRequest.class); createSensor().execute(context); - verify(bridgeServerMock, times(4)).analyzeWithProgram(captor.capture()); + verify(bridgeServerMock, times(4)).analyzeTypeScript(captor.capture()); assertThat(captor.getAllValues()) .extracting(req -> req.filePath) .containsExactlyInAnyOrder( @@ -547,7 +547,7 @@ void should_not_analyze_references_twice() throws Exception { ) ); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse()); ArgumentCaptor captorProgram = ArgumentCaptor.forClass( TsProgramRequest.class @@ -658,7 +658,7 @@ void should_stop_when_no_input_files() throws Exception { @Test void should_fail_fast() throws Exception { createTsConfigFile(); - when(bridgeServerMock.analyzeWithProgram(any())).thenThrow(new IOException("error")); + when(bridgeServerMock.analyzeTypeScript(any())).thenThrow(new IOException("error")); JsTsSensor sensor = createSensor(); MapSettings settings = new MapSettings().setProperty("sonar.internal.analysis.failFast", true); context.setSettings(settings); @@ -723,7 +723,7 @@ void log_debug_analyzed_filename_with_program() throws Exception { DefaultInputFile inputFile = createInputFile(context); var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of()); when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram); - when(bridgeServerMock.analyzeWithProgram(any())).thenReturn(new AnalysisResponse()); + when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse()); sensor.execute(context); assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Analyzing file: " + inputFile.uri());