From 2bbe2243f0a393dd3c9884dca5560f583a843f88 Mon Sep 17 00:00:00 2001 From: Elena Vilchik Date: Fri, 27 Dec 2019 15:34:39 +0100 Subject: Analyze CSS in Vue Single File Components (#232) --- .../main/java/org/sonar/css/plugin/CssRuleSensor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sonar-css-plugin/src/main/java/org') 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 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 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()); } -- cgit v1.2.3