[diffoscope] 01/01: Use js-beautify as JavaScript code beautifier for .js files

Emanuel Bronshtein e3amn2l-guest at moszumanska.debian.org
Sun Dec 18 22:55:08 CET 2016


This is an automated email from the git hooks/post-receive script.

e3amn2l-guest pushed a commit to branch master
in repository diffoscope.

commit 002f05444cc0a238d8e617b31dabef4111b4ecd2
Author: Emanuel Bronshtein <e3amn2l at gmx.com>
Date:   Sun Dec 18 23:52:51 2016 +0200

    Use js-beautify as JavaScript code beautifier for .js files
    
    JavaScript code can be minified (See #838984) or not well formatted.
---
 debian/control                       |  1 +
 diffoscope/comparators/__init__.py   |  1 +
 diffoscope/comparators/javascript.py | 42 ++++++++++++++++++++++++++++++++++++
 diffoscope/exc.py                    |  3 +++
 4 files changed, 47 insertions(+)

diff --git a/debian/control b/debian/control
index f71e028..724aef3 100644
--- a/debian/control
+++ b/debian/control
@@ -33,6 +33,7 @@ Build-Depends:
  pdftk <!nocheck>,
  poppler-utils <!nocheck>,
  python-argcomplete,
+ python-jsbeautifier <!nocheck>,
  python3-all,
  python3-debian <!nocheck>,
  python3-docutils,
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 479f39e..fe47ad1 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -49,6 +49,7 @@ COMPARATORS = (
     ('deb.DebDataTarFile',),
     ('elf.ElfSection',),
     ('ps.PsFile',),
+    ('javascript.JavaScriptFile',),
     ('json.JSONFile',),
     ('text.TextFile',),
     ('bzip2.Bzip2File',),
diff --git a/diffoscope/comparators/javascript.py b/diffoscope/comparators/javascript.py
new file mode 100644
index 0000000..18892f1
--- /dev/null
+++ b/diffoscope/comparators/javascript.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Emanuel Bronshtein <e3amn2l at gmx.com>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import re
+
+from diffoscope import tool_required
+from diffoscope.difference import Difference
+from diffoscope.comparators.utils import Command
+from diffoscope.comparators.binary import File
+
+
+class JavaScriptBeautify(Command):
+    @tool_required('js-beautify')
+    def cmdline(self):
+        return ['js-beautify', self.path]
+
+class JavaScriptFile(File):
+    RE_FILE_EXTENSION = re.compile(r'\.js$')
+
+    @staticmethod
+    def recognizes(file):
+        return JavaScriptFile.RE_FILE_EXTENSION.search(file.name)
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(JavaScriptBeautify, self.path, other.path)]
+
diff --git a/diffoscope/exc.py b/diffoscope/exc.py
index 1bf5749..d87ef76 100644
--- a/diffoscope/exc.py
+++ b/diffoscope/exc.py
@@ -95,6 +95,9 @@ class RequiredToolNotFound(Exception):
             'debian': 'default-jdk-headless | default-jdk | java-sdk',
             'arch': 'java-environment',
         },
+        'js-beautify': {
+            'debian': 'python-jsbeautifier',
+        },
         'llvm-bcanalyzer': {
             'debian': 'llvm',
             'arch': 'llvm',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list