[gnome-code-assistance] sh: Use shellcheck to check shellscripts, if available



commit 3829c52a4220e11b95b7f96b12229ab0dc32eeb5
Author: Elad Alfassa <elad fedoraproject org>
Date:   Thu Aug 25 16:51:43 2016 +0300

    sh: Use shellcheck to check shellscripts, if available

 backends/sh/__init__.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/backends/sh/__init__.py b/backends/sh/__init__.py
index 32c844d..1266af9 100644
--- a/backends/sh/__init__.py
+++ b/backends/sh/__init__.py
@@ -1,5 +1,6 @@
 # gnome code assistance sh backend
 # Copyright (C) 2013  Paolo Borelli <pborelli gnome org>
+# Copyright (C) 2016  Elad Alfassa <elad fedoraproject org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -51,6 +52,28 @@ class Service(transport.Service):
         except Error as e:
             pass
 
+        try:
+            p = subprocess.Popen(['shellcheck', '-f', 'gcc', doc.data_path],
+                                 stdout=subprocess.PIPE)
+            for line in iter(p.stdout.readline, ''):
+                if not line:
+                    break
+                line = line.decode()
+                result = re.search(':(\d*):(\d*): (\w*):(.*)', line).groups()
+                loc = types.SourceLocation(line=result[0], column=result[1])
+                if result[2] == 'error':
+                    severity = types.Diagnostic.Severity.ERROR
+                elif result[2] == 'warning':
+                    severity = types.Diagnostic.Severity.WARNING
+                else:
+                    severity = types.Diagnostic.Severity.INFO
+                doc.diagnostics.append(types.Diagnostic(severity=severity,
+                                                        locations=[loc.to_range()],
+                                                        message=result[3]))
+        except FileNotFoundError:
+            # shellcheck is not installed. Do nothing.
+            pass
+
     def dispose(self, doc):
         pass
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]