diff options
| author | Elena Vilchik | 2019-12-27 15:34:39 +0100 |
|---|---|---|
| committer | GitHub | 2019-12-27 15:34:39 +0100 |
| commit | 2bbe2243f0a393dd3c9884dca5560f583a843f88 (patch) | |
| tree | d32c3c13efa2d4fc2540ff33a16982a020156fc2 /sonar-css-plugin | |
| parent | 0c7fadc03cca985bfc5fbae3a29f29cc71866bac (diff) | |
| download | sonar-css-2bbe2243f0a393dd3c9884dca5560f583a843f88.tar.bz2 | |
Analyze CSS in Vue Single File Components (#232)
Diffstat (limited to 'sonar-css-plugin')
4 files changed, 22 insertions, 10 deletions
diff --git a/sonar-css-plugin/pom.xml b/sonar-css-plugin/pom.xml index c79869e..b8576c9 100644 --- a/sonar-css-plugin/pom.xml +++ b/sonar-css-plugin/pom.xml @@ -135,8 +135,8 @@ <configuration> <rules> <requireFilesSize> - <minsize>6800000</minsize> - <maxsize>9000000</maxsize> + <minsize>8000000</minsize> + <maxsize>9500000</maxsize> <files> <file>${project.build.directory}/${project.build.finalName}.jar</file> </files> diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java index db961df..326c94f 100644 --- a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java @@ -88,7 +88,7 @@ public class CssRuleSensor implements Sensor { List<InputFile> inputFiles = getInputFiles(context); if (inputFiles.isEmpty()) { - LOG.info("No CSS, PHP or HTML files are found in the project. CSS analysis is skipped."); + LOG.info("No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped."); return; } @@ -142,8 +142,8 @@ public class CssRuleSensor implements Sensor { LOG.info(e.toString()); } catch (Exception e) { - // we can end up here in the following cases: file analysis request sending, or response parsing, server is not answering - // or some unpredicted state + // we can end up here in the following cases: fail to send file analysis request, fail to parse the response, server is not answering + // or some other unpredicted state String msg = "Failure during CSS analysis, " + cssAnalyzerBridgeServer.getCommandInfo(); logErrorOrWarn(context, msg, e); throwFailFast(context, e); @@ -245,10 +245,18 @@ public class CssRuleSensor implements Sensor { private static List<InputFile> getInputFiles(SensorContext context) { FileSystem fileSystem = context.fileSystem(); + FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasType(InputFile.Type.MAIN), fileSystem.predicates().hasLanguages(CssLanguage.KEY, "php", "web")); - return StreamSupport.stream(fileSystem.inputFiles(mainFilePredicate).spliterator(), false) + + FilePredicate vueFilePredicate = fileSystem.predicates().and( + fileSystem.predicates().hasType(InputFile.Type.MAIN), + fileSystem.predicates().hasExtension("vue"), + // by default 'vue' extension is defined for JS language, but 'vue' files can contain TS code and thus language can be changed + fileSystem.predicates().hasLanguages("js", "ts")); + + return StreamSupport.stream(fileSystem.inputFiles(fileSystem.predicates().or(mainFilePredicate, vueFilePredicate)).spliterator(), false) .collect(Collectors.toList()); } diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java index 429722d..4a2fbd4 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java @@ -129,14 +129,15 @@ public class CssRuleSensorTest { DefaultInputFile fileCss = addInputFile("file.css"); DefaultInputFile fileHtml = addInputFile("file.web"); DefaultInputFile filePhp = addInputFile("file.php"); + DefaultInputFile fileVue = addInputFile("file.vue"); addInputFile("file.js"); sensor.execute(context); - assertThat(context.allIssues()).hasSize(3); + assertThat(context.allIssues()).hasSize(4); assertThat(context.allIssues()) .extracting("primaryLocation.component") - .containsOnly(fileCss, fileHtml, filePhp); + .containsOnly(fileCss, fileHtml, filePhp, fileVue); } @Test @@ -144,7 +145,7 @@ public class CssRuleSensorTest { sensor.execute(context); assertThat(context.allIssues()).hasSize(0); assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); - assertThat(logTester.logs(LoggerLevel.INFO)).contains("No CSS, PHP or HTML files are found in the project. CSS analysis is skipped."); + assertThat(logTester.logs(LoggerLevel.INFO)).contains("No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped."); } @Test @@ -322,8 +323,10 @@ public class CssRuleSensorTest { } private DefaultInputFile addInputFile(String relativePath) { + String extension = relativePath.split("\\.")[1]; + String language = extension.equals("vue") ? "js" : extension; DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath) - .setLanguage(relativePath.split("\\.")[1]) + .setLanguage(language) .setCharset(StandardCharsets.UTF_8) .setContents("some css content\n on 2 lines") .build(); diff --git a/sonar-css-plugin/src/test/resources/mock-start-server/startServer.js b/sonar-css-plugin/src/test/resources/mock-start-server/startServer.js index 87298a9..b224e48 100644 --- a/sonar-css-plugin/src/test/resources/mock-start-server/startServer.js +++ b/sonar-css-plugin/src/test/resources/mock-start-server/startServer.js @@ -24,6 +24,7 @@ const requestHandler = (request, response) => { case "file.css": case "file.web": case "file.php": + case "file.vue": case "file.js": // to test that we will not save this issue even if it's provided by response response.end(JSON.stringify([ {line: 2, rule: "block-no-empty", text: "Unexpected empty block"} |
