From a776768506979110e5de5a9531042d3c8716ceb3 Mon Sep 17 00:00:00 2001 From: Elena Vilchik Date: Fri, 27 Dec 2019 13:37:21 +0100 Subject: Analyze CSS in Vue Single File Components --- .../src/main/java/org/sonar/css/plugin/CssRuleSensor.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sonar-css-plugin/src/main/java') 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..9b2241c 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 @@ -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