Exemplo n.º 1
0
 def test_escape_path_argument_unsupported(self):
     _type = "INVALID"
     self.assertEqual(
         escape_path_argument("/home/usr/a-file", _type),
         "/home/usr/a-file")
     self.assertEqual(
         escape_path_argument("/home/us r/a-file with spaces.bla", _type),
         "/home/us r/a-file with spaces.bla")
     self.assertEqual(
         escape_path_argument("|home|us r|a*dir with spaces|x|", _type),
         "|home|us r|a*dir with spaces|x|")
     self.assertEqual(
         escape_path_argument("system|a|b|c?d", _type),
         "system|a|b|c?d")
Exemplo n.º 2
0
 def construct_testscript_command(scriptname):
     return " ".join(
         escape_path_argument(s) for s in (
             sys.executable,
             os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "run_shell_command_testfiles",
                          scriptname)))
Exemplo n.º 3
0
    def test_config_file_generator(self):
        self.uut.executable = "echo"
        self.uut.arguments = "-c {config_file}"

        self.assertEqual(
            self.uut._create_command(config_file="configfile").strip(),
            "echo -c " + escape_path_argument("configfile"))
Exemplo n.º 4
0
    def run(self,
            filename,
            file,
            pylint_disable: typed_list(str)=None,
            pylint_enable: typed_list(str)=None,
            pylint_cli_options: str="",
            pylint_rcfile: str=""):
        '''
        Checks the code with pylint. This will run pylint over each file
        separately.

        :param pylint_disable:     Disable the message, report, category or
                                   checker with the given id(s).
        :param pylint_enable:      Enable the message, report, category or
                                   checker with the given id(s).
        :param pylint_cli_options: Any command line options you wish to be
                                   passed to pylint.
        :param pylint_rcfile:      The rcfile for PyLint.
        '''
        self.arguments = ('--reports=n --persistent=n '
                          '--msg-template="{{line}}.{{column}}|{{C}}: '
                          '{{msg_id}} - {{msg}}"')
        if pylint_disable:
            self.arguments += " --disable=" + ",".join(pylint_disable)
        if pylint_enable:
            self.arguments += " --enable=" + ",".join(pylint_enable)
        if pylint_cli_options:
            self.arguments += " " + pylint_cli_options
        if pylint_rcfile:
            self.arguments += " --rcfile=" + escape_path_argument(pylint_rcfile)
        else:
            self.arguments += " --rcfile=" + os.devnull
        self.arguments += " {filename}"

        return self.lint(filename)
Exemplo n.º 5
0
    def run(self,
            filename,
            file,
            pylint_disable: typed_list(str)=None,
            pylint_enable: typed_list(str)=None,
            pylint_cli_options: str="",
            pylint_rcfile: str=""):
        '''
        Checks the code with pylint. This will run pylint over each file
        separately.

        :param pylint_disable:     Disable the message, report, category or
                                   checker with the given id(s).
        :param pylint_enable:      Enable the message, report, category or
                                   checker with the given id(s).
        :param pylint_cli_options: Any command line options you wish to be
                                   passed to pylint.
        :param pylint_rcfile:      The rcfile for PyLint.
        '''
        if pylint_disable:
            self.arguments += " --disable=" + ",".join(pylint_disable)
        if pylint_enable:
            self.arguments += " --enable=" + ",".join(pylint_enable)
        if pylint_cli_options:
            self.arguments += " " + pylint_cli_options
        if pylint_rcfile:
            self.arguments += " --rcfile=" + escape_path_argument(pylint_rcfile)
        else:
            self.arguments += " --rcfile=" + os.devnull

        return self.lint(filename)
Exemplo n.º 6
0
    def run(self,
            filename,
            file,
            pylint_disable: typed_list(str)=None,
            pylint_enable: typed_list(str)=None,
            pylint_cli_options: str="",
            pylint_rcfile: str=""):
        '''
        Checks the code with pylint. This will run pylint over each file
        separately.

        :param pylint_disable:     Disable the message, report, category or
                                   checker with the given id(s).
        :param pylint_enable:      Enable the message, report, category or
                                   checker with the given id(s).
        :param pylint_cli_options: Any command line options you wish to be
                                   passed to pylint.
        :param pylint_rcfile:      The rcfile for PyLint.
        '''
        self.arguments = ('--reports=n --persistent=n '
                          '--msg-template="{{line}}.{{column}}|{{C}}: '
                          '{{msg_id}} - {{msg}}"')
        if pylint_disable:
            self.arguments += " --disable=" + ",".join(pylint_disable)
        if pylint_enable:
            self.arguments += " --enable=" + ",".join(pylint_enable)
        if pylint_cli_options:
            self.arguments += " " + pylint_cli_options
        if pylint_rcfile:
            self.arguments += " --rcfile=" + escape_path_argument(pylint_rcfile)
        else:
            self.arguments += " --rcfile=" + os.devnull
        self.arguments += " {filename}"

        return self.lint(filename)
Exemplo n.º 7
0
    def lint(self, filename):
        """
        Takes a file and lints it using the linter variables defined apriori.

        :param filename: The name of the file to execute.
        """
        command = (self.executable + ' ' + self.arguments + ' '
                   + escape_path_argument(filename))
        stderr_file = tempfile.TemporaryFile()
        stdout_file = tempfile.TemporaryFile()
        process = subprocess.Popen(
            command,
            shell=True,
            stdout=stdout_file,
            stderr=stderr_file,
            universal_newlines=True)
        process.wait()
        if self.use_stderr:
            stderr_file.seek(0)
            output = stderr_file.read().decode(sys.stdout.encoding,
                                               errors="replace")
        else:
            stdout_file.seek(0)
            output = stdout_file.read().decode(sys.stdout.encoding,
                                               errors="replace")
        stdout_file.close()
        stderr_file.close()
        return self.process_output(output, filename)
Exemplo n.º 8
0
 def test_escape_path_argument_cmd(self):
     _type = "cmd"
     self.assertEqual(
         escape_path_argument("C:\\Windows\\has-a-weird-shell.txt", _type),
         "\"C:\\Windows\\has-a-weird-shell.txt\"")
     self.assertEqual(
         escape_path_argument("C:\\Windows\\lolrofl\\dirs\\", _type),
         "\"C:\\Windows\\lolrofl\\dirs\\\"")
     self.assertEqual(
         escape_path_argument("X:\\Users\\Maito Gai\\fi le.exe", _type),
         "\"X:\\Users\\Maito Gai\\fi le.exe\"")
     self.assertEqual(
         escape_path_argument("X:\\Users\\Mai to Gai\\director y\\",
                              _type),
         "\"X:\\Users\\Mai to Gai\\director y\\\"")
     self.assertEqual(
         escape_path_argument("X:\\Users\\Maito Gai\\\"seven-gates\".y",
                              _type),
         "\"X:\\Users\\Maito Gai\\^\"seven-gates^\".y\"")
     self.assertEqual(
         escape_path_argument("System32\\my-custom relative tool\\",
                              _type),
         "\"System32\\my-custom relative tool\\\"")
     self.assertEqual(
         escape_path_argument("System32\\illegal\" name \"\".curd", _type),
         "\"System32\\illegal^\" name ^\"^\".curd\"")
Exemplo n.º 9
0
    def run(self,
            filename,
            file,
            tslint_config: path="",
            rules_dir: path=""):
        '''
        Checks the code with ``tslint`` on each file separately.

        :param tslint_config: Path to configuration file.
        :param rules_dir:     Rules directory
        '''
        self.arguments = "--format json"
        if tslint_config:
            self.arguments += (" --config " +
                               escape_path_argument(tslint_config))
        if rules_dir:
            self.arguments += (" --rules-dir " +
                               escape_path_argument(rules_dir))
        self.arguments += " {filename}"
        return self.lint(filename, file)
Exemplo n.º 10
0
    def run(self, filename, file, jshint_config: str = ""):
        """
        Checks the code with jshint. This will run jshint over each file
        separately.

        :param jshint_config: The location of the jshintrc config file.
        """
        self.arguments = "--verbose {filename}"
        if jshint_config:
            self.arguments += " --config " + escape_path_argument(jshint_config)

        return self.lint(filename)
Exemplo n.º 11
0
 def test_escape_path_argument_sh(self):
     _type = "sh"
     self.assertEqual(
         escape_path_argument("/home/usr/a-file", _type),
         "/home/usr/a-file")
     self.assertEqual(
         escape_path_argument("/home/usr/a-dir/", _type),
         "/home/usr/a-dir/")
     self.assertEqual(
         escape_path_argument("/home/us r/a-file with spaces.bla",
                              _type),
         "'/home/us r/a-file with spaces.bla'")
     self.assertEqual(
         escape_path_argument("/home/us r/a-dir with spaces/x/",
                              _type),
         "'/home/us r/a-dir with spaces/x/'")
     self.assertEqual(
         escape_path_argument(
             "relative something/with cherries and/pickles.delicious",
             _type),
         "'relative something/with cherries and/pickles.delicious'")
Exemplo n.º 12
0
    def run(self, filename, file, cmakelint_config: path=""):
        '''
        Checks the code with ``cmakelint``.

        :param cmakelint_config: The location of the cmakelintrc config file.
        '''
        self.arguments = ""
        if cmakelint_config:
            self.arguments += (' --config=' +
                               escape_path_argument(cmakelint_config))

        self.arguments += ' {filename}'
        return self.lint(filename)
Exemplo n.º 13
0
    def run(self, filename, file, perlcritic_profile: str = ""):
        '''
        Checks the code with perlcritic. This will run perlcritic over
        each of the files seperately

        :param perlcritic_profile: Location of the perlcriticrc config file.
        '''
        self.arguments = '--no-color --verbose "%l|%c|%s|%p|%m (%e)"'
        if perlcritic_profile:
            self.arguments += (" --profile " +
                               escape_path_argument(perlcritic_profile))
        self.arguments += " {filename}"
        return self.lint(filename)
Exemplo n.º 14
0
    def run(self, filename, file, cmakelint_config: path = ""):
        '''
        Checks the code with ``cmakelint``.

        :param cmakelint_config: The location of the cmakelintrc config file.
        '''
        self.arguments = ""
        if cmakelint_config:
            self.arguments += (' --config=' +
                               escape_path_argument(cmakelint_config))

        self.arguments += ' {filename}'
        return self.lint(filename)
Exemplo n.º 15
0
    def run(self, filename, file, eslint_config: str=""):
        '''
        Checks the code with eslint. This will run eslint over each of the files
        seperately.

        :param eslint_config: The location of the .eslintrc config file.
        '''
        self.arguments = '--no-ignore --no-color -f=json --stdin'
        if eslint_config:
            self.arguments += (" --config "
                               + escape_path_argument(eslint_config))

        return self.lint(filename, file)
Exemplo n.º 16
0
    def run(self, filename, file, eslint_config: str = ""):
        '''
        Checks the code with eslint. This will run eslint over each of the files
        seperately.

        :param eslint_config: The location of the .eslintrc config file.
        '''
        self.arguments = '--no-ignore --no-color -f=json --stdin'
        if eslint_config:
            self.arguments += (" --config " +
                               escape_path_argument(eslint_config))

        return self.lint(filename, file)
Exemplo n.º 17
0
    def test_escape_path_argument_linux_and_darwin(self):
        osnames = ("Linux", "Darwin")

        for osname in osnames:
            self.assertEqual(
                escape_path_argument("/home/usr/a-file", osname),
                "/home/usr/a-file")
            self.assertEqual(
                escape_path_argument("/home/usr/a-dir/", osname),
                "/home/usr/a-dir/")
            self.assertEqual(
                escape_path_argument("/home/us r/a-file with spaces.bla",
                                     osname),
                "/home/us\\ r/a-file\\ with\\ spaces.bla")
            self.assertEqual(
                escape_path_argument("/home/us r/a-dir with spaces/x/",
                                     osname),
                "/home/us\\ r/a-dir\\ with\\ spaces/x/")
            self.assertEqual(
                escape_path_argument(
                    "relative something/with cherries and/pickles.delicious",
                    osname),
                "relative\\ something/with\\ cherries\\ and/pickles.delicious")
Exemplo n.º 18
0
    def run(self,
            filename,
            file,
            pylint_disable: typed_list(str)=("fixme"),
            pylint_enable: typed_list(str)=None,
            pylint_cli_options: str=""):
        '''
        Checks the code with pylint. This will run pylint over each file
        separately.

        :param pylint_disable:     Disable the message, report, category or
                                   checker with the given id(s).
        :param pylint_enable:      Enable the message, report, category or
                                   checker with the given id(s).
        :param pylint_cli_options: Any command line options you wish to be
                                   passed to pylint.
        '''
        command = ('pylint -r n --msg-template="{line}|{category}|'
                   '{msg}. ({msg_id}, {symbol}, {obj})" '
                   + escape_path_argument(filename))
        if pylint_disable:
            command += " --disable=" + ",".join(pylint_disable)
        if pylint_enable:
            command += " --enable=" + ",".join(pylint_enable)
        if pylint_cli_options:
            command += " " + pylint_cli_options

        process = Popen(command,
                        shell=True,
                        stdout=PIPE,
                        stderr=PIPE,
                        universal_newlines=True)
        process.wait()
        current_lines = ""
        for line in process.stdout.readlines():
            if line.startswith("***"):
                continue

            if current_lines != "" and line.split("|", 1)[0].isdigit():
                yield self.parse_result(filename, current_lines)
                current_lines = ""

            current_lines += line

        if current_lines != "":
            yield self.parse_result(filename, current_lines)

        process.stdout.close()
        process.stderr.close()
Exemplo n.º 19
0
    def run(self,
            filename,
            file,
            perlcritic_profile: str=""):
        '''
        Checks the code with perlcritic. This will run perlcritic over
        each of the files seperately

        :param perlcritic_profile: Location of the perlcriticrc config file.
        '''
        self.arguments = '--no-color --verbose "%l|%c|%s|%p|%m (%e)"'
        if perlcritic_profile:
            self.arguments += (" --profile "
                               + escape_path_argument(perlcritic_profile))
        self.arguments += " {filename}"
        return self.lint(filename)
Exemplo n.º 20
0
    def run(self, filename, file,
            xml_schema: path="",
            xml_dtd: path_or_url=""):
        '''
        Checks the code with ``xmllint``.

        :param xml_schema: ``W3C XML Schema`` file used for validation.
        :param xml_dtd:    ``Document type Definition (DTD)`` file or
                           url used for validation.
        '''
        self.arguments = "{filename} "
        if xml_schema:
            self.arguments += " -schema " + escape_path_argument(xml_schema)
        if xml_dtd:
            self.arguments += " -dtdvalid " + xml_dtd
        return self.lint(filename, file)
Exemplo n.º 21
0
    def run(self,
            filename,
            file,
            perlcritic_config: str=""):
        '''
        Checks the code with perlcritic. This will run perlcritic over
        each of the files seperately

        :param perlcritic_config: Location of the perlcriticrc config file.
        '''

        if perlcritic_config:
            self.arguments += (" --config "
                               + escape_path_argument(perlcritic_config))

        return self.lint(filename)
Exemplo n.º 22
0
    def run(self, filename, file,
            xml_schema: path="",
            xml_dtd: path_or_url=""):
        '''
        Checks the code with ``xmllint``.

        :param xml_schema: ``W3C XML Schema`` file used for validation.
        :param xml_dtd:    ``Document type Definition (DTD)`` file or
                           url used for validation.
        '''
        self.arguments = "{filename} "
        if xml_schema:
            self.arguments += " -schema " + escape_path_argument(xml_schema)
        if xml_dtd:
            self.arguments += " -dtdvalid " + xml_dtd
        return self.lint(filename, file)
Exemplo n.º 23
0
    def run(self,
            filename,
            file,
            scalalint_config: str=""):
        '''
        Checks the code with `scalastyle` on each file separately.

        :param scalalint_config: Path to a custom configuration file.
        '''
        self.arguments = ' -jar ' + self.jar
        self.arguments += ' {filename}'
        scala_config_file = self.scalastyle_config_file
        if scalalint_config:
            scala_config_file = scalalint_config
        self.arguments += (' --config ' +
                           escape_path_argument(scala_config_file))
        return self.lint(filename)
Exemplo n.º 24
0
Arquivo: Lint.py Projeto: kipawa/coala
 def _create_command(self, **kwargs):
     command = self.executable + ' ' + self.arguments
     for key in ("filename", "config_file"):
         kwargs[key] = escape_path_argument(kwargs.get(key, "") or "")
     return command.format(**kwargs)
Exemplo n.º 25
0
    def test_escape_path_argument(self):
        osname = "Linux"
        self.assertEqual(escape_path_argument("/home/usr/a-file", osname),
                         "/home/usr/a-file")
        self.assertEqual(escape_path_argument("/home/usr/a-dir/", osname),
                         "/home/usr/a-dir/")
        self.assertEqual(
            escape_path_argument("/home/us r/a-file with spaces.bla", osname),
            "/home/us\\ r/a-file\\ with\\ spaces.bla")
        self.assertEqual(
            escape_path_argument("/home/us r/a-dir with spaces/x/", osname),
            "/home/us\\ r/a-dir\\ with\\ spaces/x/")
        self.assertEqual(
            escape_path_argument(
                "relative something/with cherries and/pickles.delicious",
                osname),
            "relative\\ something/with\\ cherries\\ and/pickles.delicious")

        osname = "Windows"
        self.assertEqual(
            escape_path_argument("C:\\Windows\\has-a-weird-shell.txt", osname),
            "\"C:\\Windows\\has-a-weird-shell.txt\"")
        self.assertEqual(
            escape_path_argument("C:\\Windows\\lolrofl\\dirs\\", osname),
            "\"C:\\Windows\\lolrofl\\dirs\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\fi le.exe", osname),
            "\"X:\\Users\\Maito Gai\\fi le.exe\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Mai to Gai\\director y\\",
                                 osname),
            "\"X:\\Users\\Mai to Gai\\director y\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\\"seven-gates\".y",
                                 osname),
            "\"X:\\Users\\Maito Gai\\^\"seven-gates^\".y\"")
        self.assertEqual(
            escape_path_argument("System32\\my-custom relative tool\\",
                                 osname),
            "\"System32\\my-custom relative tool\\\"")
        self.assertEqual(
            escape_path_argument("System32\\illegal\" name \"\".curd", osname),
            "\"System32\\illegal^\" name ^\"^\".curd\"")

        osname = "INVALID"
        self.assertEqual(escape_path_argument("/home/usr/a-file", osname),
                         "/home/usr/a-file")
        self.assertEqual(
            escape_path_argument("/home/us r/a-file with spaces.bla", osname),
            "/home/us r/a-file with spaces.bla")
        self.assertEqual(
            escape_path_argument("|home|us r|a*dir with spaces|x|", osname),
            "|home|us r|a*dir with spaces|x|")
        self.assertEqual(escape_path_argument("system|a|b|c?d", osname),
                         "system|a|b|c?d")
Exemplo n.º 26
0
    def run(self,
            filename,
            file,
            prohibit_bitwise: bool = True,
            prohibit_prototype_overwrite: bool = True,
            force_braces: bool = True,
            prohibit_type_coercion: bool = True,
            future_hostile: bool = False,
            prohibit_typeof: bool = False,
            es3: bool = False,
            force_filter_forin: bool = True,
            allow_funcscope: bool = False,
            iterator: bool = False,
            prohibit_arg: bool = True,
            prohibit_comma: bool = False,
            prohibit_non_breaking_whitespace: bool = True,
            prohibit_new: bool = False,
            prohibit_undefined: bool = True,
            prohibit_groups: bool = False,
            prohibit_variable_statements: bool = False,
            allow_missing_semicol: bool = False,
            allow_debugger: bool = False,
            allow_assignment_comparisions: bool = False,
            allow_eval: bool = False,
            allow_global_strict: bool = False,
            allow_increment: bool = False,
            allow_proto: bool = False,
            allow_scripturls: bool = False,
            allow_singleton: bool = False,
            allow_this_stmt: bool = False,
            allow_with_stmt: bool = False,
            using_mozilla: bool = False,
            allow_noyield: bool = False,
            allow_eqnull: bool = False,
            allow_last_semicolon: bool = False,
            allow_func_in_loop: bool = False,
            allow_expr_in_assignments: bool = False,
            use_es6_syntax: bool = False,
            use_es3_array: bool = False,
            environment_mootools: bool = False,
            environment_couch: bool = False,
            environment_jasmine: bool = False,
            environment_jquery: bool = False,
            environment_node: bool = False,
            environment_qunit: bool = False,
            environment_rhino: bool = False,
            environment_shelljs: bool = False,
            environment_prototypejs: bool = False,
            environment_yui: bool = False,
            environment_mocha: bool = True,
            environment_module: bool = False,
            environment_wsh: bool = False,
            environment_worker: bool = False,
            environment_nonstandard: bool = False,
            environment_browser: bool = True,
            environment_browserify: bool = False,
            environment_devel: bool = True,
            environment_dojo: bool = False,
            environment_typed: bool = False,
            environment_phantom: bool = False,
            maxerr: int = 50,
            maxstatements: bool_or_int = False,
            maxdepth: bool_or_int = False,
            maxparams: bool_or_int = False,
            maxcomplexity: bool_or_int = False,
            shadow: bool_or_str = False,
            prohibit_unused: bool_or_str = True,
            allow_latedef: bool_or_str = False,
            es_version: int = 5,
            jshint_config: str = ""):
        '''
        Checks the code with jshint. This will run jshint over each file
        separately.

        :param prohibit_bitwise:                 This option prohibits the use
                                                 of bitwise operators.
        :param prohibit_prototype_overwrite:     This options prohibits
                                                 overwriting prototypes of
                                                 native objects such as
                                                 ``Array``.
        :param force_braces:                     This option requires you to
                                                 always put curly braces around
                                                 blocks in loops and
                                                 conditionals.
        :param prohibit_type_coercion:           This options prohibits the use
                                                 of ``==`` and ``!=`` in favor
                                                 of ``===`` and ``!==``.
        :param future_hostile:                   This option enables warnings
                                                 about the use of identifiers
                                                 which are defined in future
                                                 versions of JavaScript.
        :param prohibit_typeof:                  This option suppresses
                                                 warnings about invalid
                                                 ``typeof`` operator values.
        :param es3:                              This option tells JSHint that
                                                 your code needs to adhere to
                                                 ECMAScript 3 specification.
        :param force_filter_forin:               This option requires all
                                                 ``for in`` loops to filter
                                                 object's items.
        :param iterator:                         This option suppresses
                                                 warnings about the
                                                 ``__iterator__`` property.
        :param allow_funcscope:                  This option suppresses warnings
                                                 about declaring variables
                                                 inside of control structures
                                                 while accessing them later
                                                 from outside.
        :param prohibit_arg:                     This option prohibits the use
                                                 of ``arguments.caller`` and
                                                 ``arguments.callee``.
        :param prohibit_comma:                   This option prohibits the use
                                                 of the comma operator.
        :param prohibit_non_breaking_whitespace: This option warns about "non-
                                                 breaking whitespace
                                                 characters".
        :param prohibit_new:                     This option prohibits the use
                                                 of constructor functions for
                                                 side-effects.
        :param prohibit_undefined:               This option prohibits the use
                                                 of explicitly undeclared
                                                 variables.
        :param prohibit_groups:                  This option prohibits the use
                                                 of the grouping operator when
                                                 it is not strictly required.
        :param prohibit_variable_statements:     This option forbids the use of
                                                 VariableStatements.
        :param allow_missing_semicol:            This option suppresses
                                                 warnings about missing
                                                 semicolons.
        :param allow_debugger:                   This option suppresses
                                                 warnings about the
                                                 ``debugger`` statements.
        :param allow_assignment_comparisions:    This option suppresses
                                                 warnings about the use of
                                                 assignments in cases where
                                                 comparisons are expected.
        :param allow_eval:                       This options suppresses
                                                 warnings about the use of
                                                 ``eval`` function.
        :param allow_global_strict:              This option suppresses
                                                 warnings about the use of
                                                 global strict mode.
        :param allow_increment:                  This option suppresses
                                                 warnings about the use of
                                                 unary increment and decrement
                                                 operators.
        :param allow_proto:                      This option suppresses
                                                 warnings about the
                                                 ``__proto__`` property.
        :param allow_scripturls:                 This option suppresses
                                                 warnings about the use of
                                                 script-targeted URLs.
        :param allow_singleton:                  This option suppresses
                                                 warnings about constructions
                                                 like ``new function ()
                                                 { ... }`` and ``new Object;``
                                                 sometimes used to produce
                                                 singletons.
        :param allow_this_stmt:                  This option suppresses
                                                 warnings about possible strict
                                                 violations when the code is
                                                 running in strict mode and
                                                 ``this`` is used in a non-
                                                 constructor function.
        :param allow_with_stmt:                  This option suppresses
                                                 warnings about the use of the
                                                 ``with`` statement.
        :param using_mozilla:                    This options tells JSHint that
                                                 your code uses Mozilla
                                                 JavaScript extensions.
        :param allow_noyield:                    This option suppresses
                                                 warnings about generator
                                                 functions with no ``yield``
                                                 statement in them.
        :param allow_eqnull:                     This option suppresses
                                                 warnings about ``== null``
                                                 comparisons.
        :param allow_last_semicolon:             This option suppresses
                                                 warnings about missing
                                                 semicolons for the last
                                                 statement.
        :param allow_func_in_loop:               This option suppresses
                                                 warnings about functions
                                                 inside of loops.
        :param allow_expr_in_assignments:        This option suppresses
                                                 warnings about the use of
                                                 expressions where normally
                                                 assignments or function calls
                                                 are expected.
        :param use_es3_array:                    This option tells JSHintBear
                                                 ES3 array elision elements,
                                                 or empty elements are used.
        :param use_es3_array:                    This option tells JSHint
                                                 ECMAScript 6 specific syntax
                                                 is used.
        :param environment_mootools:             This option defines globals
                                                 exposed by the Mootools.
        :param environment_couch:                This option defines globals
                                                 exposed by CouchDB.
        :param environment_jasmine:              This option defines globals
                                                 exposed by Jasmine.
        :param environment_jquery:               This option defines globals
                                                 exposed by Jquery.
        :param environment_node:                 This option defines globals
                                                 exposed by Node.
        :param environment_qunit:                This option defines globals
                                                 exposed by Qunit.
        :param environment_rhino:                This option defines globals
                                                 exposed when the code is
                                                 running inside rhino runtime
                                                 environment.
        :param environment_shelljs:              This option defines globals
                                                 exposed by the ShellJS.
        :param environment_prototypejs:          This option defines globals
                                                 exposed by the Prototype.
        :param environment_yui:                  This option defines globals
                                                 exposed by the YUI JavaScript
                                                 Framework.
        :param environment_mocha:                This option defines globals
                                                 exposed by the "BDD" and "TDD"
                                                 UIs of the Mocha unit testing
                                                 framework.
        :param environment_module:               This option informs JSHintBear
                                                 that the input code describes
                                                 an ECMAScript 6 module.
        :param environment_wsh:                  This option defines globals
                                                 available when the code is
                                                 running as a script for the
                                                 Windows Script Host.
        :param environment_worker:               This option defines globals
                                                 available when the code is
                                                 running inside of a Web
                                                 Worker.
        :param environment_nonstandard:          This option defines non-
                                                 standard but widely adopted
                                                 globals such as ``escape`` and
                                                 ``unescape``.
        :param environment_browser:              This option defines globals
                                                 exposed by modern browsers.
        :param environment_browserify:           This option defines globals
                                                 available when using the
                                                 Browserify.
        :param environment_devel:                This option defines globals
                                                 that are usually used for
                                                 debugging: ``console``,
                                                 ``alert``, etc.
        :param environment_dojo:                 This option defines globals
                                                 exposed by the Dojo Toolkit.
        :param environment_typed:                This option defines globals
                                                 for typed array constructors.
        :param environment_phantom:              This option defines globals
                                                 available when your core is
                                                 running inside of the
                                                 PhantomJS runtime environment.
        :param maxerr:                           This options allows you to set
                                                 the maximum amount of warnings
                                                 JSHintBear will produce before
                                                 giving up. Default is 50.
        :param maxstatements:                    Maximum number of statements
                                                 allowed per function.
        :param maxdepth:                         This option lets you control
                                                 how nested do you want your
                                                 blocks to be.
        :param maxparams:                        Maximum number of formal
                                                 parameters allowed per
                                                 function.
        :param maxcomplexity:                    Maximum cyclomatic complexity
                                                 in the code.
        :param shadow:                           This option suppresses
                                                 warnings about variable
                                                 shadowing i.e. declaring a
                                                 variable that had been
                                                 already declared somewhere
                                                 in the outer scope.

                                                  - "inner" - check for
                                                     variables defined in the
                                                     same scope only
                                                  - "outer" - check for
                                                     variables defined in outer
                                                     scopes as well
                                                  - False - same as inner
                                                  - True  - allow variable
                                                    shadowing
        :param prohibit_unused:                  This option generates warnings
                                                 when variables are defined but
                                                 never used. This can be set to
                                                 ""vars"" to only check for
                                                 variables, not function
                                                 parameters,or ""strict"" to
                                                 check all variables and
                                                 parameters.
        :param allow_latedef:                    This option prohibits the use
                                                 of a variable before it was
                                                 defined.
                                                 Setting this option to
                                                 "nofunc" will allow
                                                 function declarations
                                                 to be ignored.
        :param es_version:                       This option is used to specify
                                                 the ECMAScript version to
                                                 which the code must adhere to.
        :param jshint_config:                    The location of the jshintrc
                                                 config file. If this option is
                                                 present all the above options
                                                 are not used. Instead the
                                                 .jshintrc file is used as the
                                                 configuration file.
        '''
        self.arguments = '--verbose {filename}'

        if jshint_config:
            self.config_options = None
            self.arguments += (" --config " +
                               escape_path_argument(jshint_config))
        else:
            options = {
                "bitwise": prohibit_bitwise,
                "freeze": prohibit_prototype_overwrite,
                "curly": force_braces,
                "eqeqeq": prohibit_type_coercion,
                "futurehostile": future_hostile,
                "notypeof": prohibit_typeof,
                "es3": es3,
                "forin": force_filter_forin,
                "funcscope": allow_funcscope,
                "iterator": iterator,
                "noarg": prohibit_arg,
                "nocomma": prohibit_comma,
                "nonbsp": prohibit_non_breaking_whitespace,
                "nonew": prohibit_new,
                "undef": prohibit_undefined,
                "singleGroups": prohibit_groups,
                "varstmt": prohibit_variable_statements,
                "asi": allow_missing_semicol,
                "debug": allow_debugger,
                "boss": allow_assignment_comparisions,
                "evil": allow_eval,
                "globalstrict": allow_global_strict,
                "plusplus": allow_increment,
                "proto": allow_proto,
                "scripturl": allow_scripturls,
                "supernew": allow_singleton,
                "validthis": allow_this_stmt,
                "withstmt": allow_with_stmt,
                "moz": using_mozilla,
                "noyield": allow_noyield,
                "eqnull": allow_eqnull,
                "lastsemic": allow_last_semicolon,
                "loopfunc": allow_func_in_loop,
                "expr": allow_expr_in_assignments,
                "esnext": use_es6_syntax,
                "elision": use_es3_array,
                "mootools": environment_mootools,
                "couch": environment_couch,
                "jasmine": environment_jasmine,
                "jquery": environment_jquery,
                "node": environment_node,
                "qunit": environment_qunit,
                "rhino": environment_rhino,
                "shelljs": environment_shelljs,
                "prototypejs": environment_prototypejs,
                "yui": environment_yui,
                "mocha": environment_mocha,
                "module": environment_module,
                "wsh": environment_wsh,
                "worker": environment_worker,
                "nonstandard": environment_nonstandard,
                "browser": environment_browser,
                "browserify": environment_browserify,
                "devel": environment_devel,
                "dojo": environment_dojo,
                "typed": environment_typed,
                "phantom": environment_phantom,
                "maxerr": maxerr,
                "maxcomplexity": maxcomplexity,
                "maxdepth": maxdepth,
                "maxparams": maxparams,
                "maxstatements": maxstatements,
                "shadow": shadow,
                "unused": prohibit_unused,
                "latedef": allow_latedef,
                "esversion": es_version
            }

            self.config_options = json.dumps(options)
            self.arguments += " --config {config_file}"

        return self.lint(filename)
Exemplo n.º 27
0
    def run(self,
            filename,
            file,
            prohibit_bitwise: bool=True,
            prohibit_prototype_overwrite: bool=True,
            force_braces: bool=True,
            prohibit_type_coercion: bool=True,
            future_hostile: bool=False,
            prohibit_typeof: bool=False,
            es3: bool=False,
            force_filter_forin: bool=True,
            allow_funcscope: bool=False,
            iterator: bool=False,
            prohibit_arg: bool=True,
            prohibit_comma: bool=False,
            prohibit_non_breaking_whitespace: bool=True,
            prohibit_new: bool=False,
            prohibit_undefined: bool=True,
            prohibit_groups: bool=False,
            prohibit_variable_statements: bool=False,
            allow_missing_semicol: bool=False,
            allow_debugger: bool=False,
            allow_assignment_comparisions: bool=False,
            allow_eval: bool=False,
            allow_global_strict: bool=False,
            allow_increment: bool=False,
            allow_proto: bool=False,
            allow_scripturls: bool=False,
            allow_singleton: bool=False,
            allow_this_stmt: bool=False,
            allow_with_stmt: bool=False,
            using_mozilla: bool=False,
            allow_noyield: bool=False,
            allow_eqnull: bool=False,
            allow_last_semicolon: bool=False,
            allow_func_in_loop: bool=False,
            allow_expr_in_assignments: bool=False,
            use_es6_syntax: bool=False,
            use_es3_array: bool=False,
            environment_mootools: bool=False,
            environment_couch: bool=False,
            environment_jasmine: bool=False,
            environment_jquery: bool=False,
            environment_node: bool=False,
            environment_qunit: bool=False,
            environment_rhino: bool=False,
            environment_shelljs: bool=False,
            environment_prototypejs: bool=False,
            environment_yui: bool=False,
            environment_mocha: bool=True,
            environment_module: bool=False,
            environment_wsh: bool=False,
            environment_worker: bool=False,
            environment_nonstandard: bool=False,
            environment_browser: bool=True,
            environment_browserify: bool=False,
            environment_devel: bool=True,
            environment_dojo: bool=False,
            environment_typed: bool=False,
            environment_phantom: bool=False,
            maxerr: int=50,
            maxstatements: bool_or_int=False,
            maxdepth: bool_or_int=False,
            maxparams: bool_or_int=False,
            maxcomplexity: bool_or_int=False,
            shadow: bool_or_str=False,
            prohibit_unused: bool_or_str=True,
            allow_latedef: bool_or_str=False,
            es_version: int=5,
            jshint_config: str=""):
        '''
        Checks the code with jshint. This will run jshint over each file
        separately.

        :param prohibit_bitwise:                 This option prohibits the use
                                                 of bitwise operators.
        :param prohibit_prototype_overwrite:     This options prohibits
                                                 overwriting prototypes of
                                                 native objects such as
                                                 ``Array``.
        :param force_braces:                     This option requires you to
                                                 always put curly braces around
                                                 blocks in loops and
                                                 conditionals.
        :param prohibit_type_coercion:           This options prohibits the use
                                                 of ``==`` and ``!=`` in favor
                                                 of ``===`` and ``!==``.
        :param future_hostile:                   This option enables warnings
                                                 about the use of identifiers
                                                 which are defined in future
                                                 versions of JavaScript.
        :param prohibit_typeof:                  This option suppresses
                                                 warnings about invalid
                                                 ``typeof`` operator values.
        :param es3:                              This option tells JSHint that
                                                 your code needs to adhere to
                                                 ECMAScript 3 specification.
        :param force_filter_forin:               This option requires all
                                                 ``for in`` loops to filter
                                                 object's items.
        :param iterator:                         This option suppresses
                                                 warnings about the
                                                 ``__iterator__`` property.
        :param allow_funcscope:                  This option suppresses warnings
                                                 about declaring variables
                                                 inside of control structures
                                                 while accessing them later
                                                 from outside.
        :param prohibit_arg:                     This option prohibits the use
                                                 of ``arguments.caller`` and
                                                 ``arguments.callee``.
        :param prohibit_comma:                   This option prohibits the use
                                                 of the comma operator.
        :param prohibit_non_breaking_whitespace: This option warns about "non-
                                                 breaking whitespace
                                                 characters".
        :param prohibit_new:                     This option prohibits the use
                                                 of constructor functions for
                                                 side-effects.
        :param prohibit_undefined:               This option prohibits the use
                                                 of explicitly undeclared
                                                 variables.
        :param prohibit_groups:                  This option prohibits the use
                                                 of the grouping operator when
                                                 it is not strictly required.
        :param prohibit_variable_statements:     This option forbids the use of
                                                 VariableStatements.
        :param allow_missing_semicol:            This option suppresses
                                                 warnings about missing
                                                 semicolons.
        :param allow_debugger:                   This option suppresses
                                                 warnings about the
                                                 ``debugger`` statements.
        :param allow_assignment_comparisions:    This option suppresses
                                                 warnings about the use of
                                                 assignments in cases where
                                                 comparisons are expected.
        :param allow_eval:                       This options suppresses
                                                 warnings about the use of
                                                 ``eval`` function.
        :param allow_global_strict:              This option suppresses
                                                 warnings about the use of
                                                 global strict mode.
        :param allow_increment:                  This option suppresses
                                                 warnings about the use of
                                                 unary increment and decrement
                                                 operators.
        :param allow_proto:                      This option suppresses
                                                 warnings about the
                                                 ``__proto__`` property.
        :param allow_scripturls:                 This option suppresses
                                                 warnings about the use of
                                                 script-targeted URLs.
        :param allow_singleton:                  This option suppresses
                                                 warnings about constructions
                                                 like ``new function ()
                                                 { ... }`` and ``new Object;``
                                                 sometimes used to produce
                                                 singletons.
        :param allow_this_stmt:                  This option suppresses
                                                 warnings about possible strict
                                                 violations when the code is
                                                 running in strict mode and
                                                 ``this`` is used in a non-
                                                 constructor function.
        :param allow_with_stmt:                  This option suppresses
                                                 warnings about the use of the
                                                 ``with`` statement.
        :param using_mozilla:                    This options tells JSHint that
                                                 your code uses Mozilla
                                                 JavaScript extensions.
        :param allow_noyield:                    This option suppresses
                                                 warnings about generator
                                                 functions with no ``yield``
                                                 statement in them.
        :param allow_eqnull:                     This option suppresses
                                                 warnings about ``== null``
                                                 comparisons.
        :param allow_last_semicolon:             This option suppresses
                                                 warnings about missing
                                                 semicolons for the last
                                                 statement.
        :param allow_func_in_loop:               This option suppresses
                                                 warnings about functions
                                                 inside of loops.
        :param allow_expr_in_assignments:        This option suppresses
                                                 warnings about the use of
                                                 expressions where normally
                                                 assignments or function calls
                                                 are expected.
        :param use_es3_array:                    This option tells JSHintBear
                                                 ES3 array elision elements,
                                                 or empty elements are used.
        :param use_es3_array:                    This option tells JSHint
                                                 ECMAScript 6 specific syntax
                                                 is used.
        :param environment_mootools:             This option defines globals
                                                 exposed by the Mootools.
        :param environment_couch:                This option defines globals
                                                 exposed by CouchDB.
        :param environment_jasmine:              This option defines globals
                                                 exposed by Jasmine.
        :param environment_jquery:               This option defines globals
                                                 exposed by Jquery.
        :param environment_node:                 This option defines globals
                                                 exposed by Node.
        :param environment_qunit:                This option defines globals
                                                 exposed by Qunit.
        :param environment_rhino:                This option defines globals
                                                 exposed when the code is
                                                 running inside rhino runtime
                                                 environment.
        :param environment_shelljs:              This option defines globals
                                                 exposed by the ShellJS.
        :param environment_prototypejs:          This option defines globals
                                                 exposed by the Prototype.
        :param environment_yui:                  This option defines globals
                                                 exposed by the YUI JavaScript
                                                 Framework.
        :param environment_mocha:                This option defines globals
                                                 exposed by the "BDD" and "TDD"
                                                 UIs of the Mocha unit testing
                                                 framework.
        :param environment_module:               This option informs JSHintBear
                                                 that the input code describes
                                                 an ECMAScript 6 module.
        :param environment_wsh:                  This option defines globals
                                                 available when the code is
                                                 running as a script for the
                                                 Windows Script Host.
        :param environment_worker:               This option defines globals
                                                 available when the code is
                                                 running inside of a Web
                                                 Worker.
        :param environment_nonstandard:          This option defines non-
                                                 standard but widely adopted
                                                 globals such as ``escape`` and
                                                 ``unescape``.
        :param environment_browser:              This option defines globals
                                                 exposed by modern browsers.
        :param environment_browserify:           This option defines globals
                                                 available when using the
                                                 Browserify.
        :param environment_devel:                This option defines globals
                                                 that are usually used for
                                                 debugging: ``console``,
                                                 ``alert``, etc.
        :param environment_dojo:                 This option defines globals
                                                 exposed by the Dojo Toolkit.
        :param environment_typed:                This option defines globals
                                                 for typed array constructors.
        :param environment_phantom:              This option defines globals
                                                 available when your core is
                                                 running inside of the
                                                 PhantomJS runtime environment.
        :param maxerr:                           This options allows you to set
                                                 the maximum amount of warnings
                                                 JSHintBear will produce before
                                                 giving up. Default is 50.
        :param maxstatements:                    Maximum number of statements
                                                 allowed per function.
        :param maxdepth:                         This option lets you control
                                                 how nested do you want your
                                                 blocks to be.
        :param maxparams:                        Maximum number of formal
                                                 parameters allowed per
                                                 function.
        :param maxcomplexity:                    Maximum cyclomatic complexity
                                                 in the code.
        :param shadow:                           This option suppresses
                                                 warnings about variable
                                                 shadowing i.e. declaring a
                                                 variable that had been
                                                 already declared somewhere
                                                 in the outer scope.

                                                  - "inner" - check for
                                                     variables defined in the
                                                     same scope only
                                                  - "outer" - check for
                                                     variables defined in outer
                                                     scopes as well
                                                  - False - same as inner
                                                  - True  - allow variable
                                                    shadowing
        :param prohibit_unused:                  This option generates warnings
                                                 when variables are defined but
                                                 never used. This can be set to
                                                 ""vars"" to only check for
                                                 variables, not function
                                                 parameters,or ""strict"" to
                                                 check all variables and
                                                 parameters.
        :param allow_latedef:                    This option prohibits the use
                                                 of a variable before it was
                                                 defined.
                                                 Setting this option to
                                                 "nofunc" will allow
                                                 function declarations
                                                 to be ignored.
        :param es_version:                       This option is used to specify
                                                 the ECMAScript version to
                                                 which the code must adhere to.
        :param jshint_config:                    The location of the jshintrc
                                                 config file. If this option is
                                                 present all the above options
                                                 are not used. Instead the
                                                 .jshintrc file is used as the
                                                 configuration file.
        '''
        self.arguments = '--verbose {filename}'

        if jshint_config:
            self.config_options = None
            self.arguments += (" --config "
                               + escape_path_argument(jshint_config))
        else:
            options = {
                "bitwise": prohibit_bitwise,
                "freeze": prohibit_prototype_overwrite,
                "curly": force_braces,
                "eqeqeq": prohibit_type_coercion,
                "futurehostile": future_hostile,
                "notypeof": prohibit_typeof,
                "es3": es3,
                "forin": force_filter_forin,
                "funcscope": allow_funcscope,
                "iterator": iterator,
                "noarg": prohibit_arg,
                "nocomma": prohibit_comma,
                "nonbsp": prohibit_non_breaking_whitespace,
                "nonew": prohibit_new,
                "undef": prohibit_undefined,
                "singleGroups": prohibit_groups,
                "varstmt": prohibit_variable_statements,
                "asi": allow_missing_semicol,
                "debug": allow_debugger,
                "boss": allow_assignment_comparisions,
                "evil": allow_eval,
                "globalstrict": allow_global_strict,
                "plusplus": allow_increment,
                "proto": allow_proto,
                "scripturl": allow_scripturls,
                "supernew": allow_singleton,
                "validthis": allow_this_stmt,
                "withstmt": allow_with_stmt,
                "moz": using_mozilla,
                "noyield": allow_noyield,
                "eqnull": allow_eqnull,
                "lastsemic": allow_last_semicolon,
                "loopfunc": allow_func_in_loop,
                "expr": allow_expr_in_assignments,
                "esnext": use_es6_syntax,
                "elision": use_es3_array,
                "mootools": environment_mootools,
                "couch": environment_couch,
                "jasmine": environment_jasmine,
                "jquery": environment_jquery,
                "node": environment_node,
                "qunit": environment_qunit,
                "rhino": environment_rhino,
                "shelljs": environment_shelljs,
                "prototypejs": environment_prototypejs,
                "yui": environment_yui,
                "mocha": environment_mocha,
                "module": environment_module,
                "wsh": environment_wsh,
                "worker": environment_worker,
                "nonstandard": environment_nonstandard,
                "browser": environment_browser,
                "browserify": environment_browserify,
                "devel": environment_devel,
                "dojo": environment_dojo,
                "typed": environment_typed,
                "phantom": environment_phantom,
                "maxerr": maxerr,
                "maxcomplexity": maxcomplexity,
                "maxdepth": maxdepth,
                "maxparams": maxparams,
                "maxstatements": maxstatements,
                "shadow": shadow,
                "unused": prohibit_unused,
                "latedef": allow_latedef,
                "esversion": es_version}

            self.config_options = json.dumps(options)
            self.arguments += " --config {config_file}"

        return self.lint(filename)
Exemplo n.º 28
0
    def test_escape_path_argument(self):
        osname = "Linux"
        self.assertEqual(
            escape_path_argument("/home/usr/a-file", osname),
            "/home/usr/a-file")
        self.assertEqual(
            escape_path_argument("/home/usr/a-dir/", osname),
            "/home/usr/a-dir/")
        self.assertEqual(
            escape_path_argument("/home/us r/a-file with spaces.bla", osname),
            "/home/us\\ r/a-file\\ with\\ spaces.bla")
        self.assertEqual(
            escape_path_argument("/home/us r/a-dir with spaces/x/", osname),
            "/home/us\\ r/a-dir\\ with\\ spaces/x/")
        self.assertEqual(
            escape_path_argument(
                "relative something/with cherries and/pickles.delicious",
                osname),
            "relative\\ something/with\\ cherries\\ and/pickles.delicious")

        osname = "Windows"
        self.assertEqual(
            escape_path_argument("C:\\Windows\\has-a-weird-shell.txt", osname),
            "\"C:\\Windows\\has-a-weird-shell.txt\"")
        self.assertEqual(
            escape_path_argument("C:\\Windows\\lolrofl\\dirs\\", osname),
            "\"C:\\Windows\\lolrofl\\dirs\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\fi le.exe", osname),
            "\"X:\\Users\\Maito Gai\\fi le.exe\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Mai to Gai\\director y\\",
                                 osname),
            "\"X:\\Users\\Mai to Gai\\director y\\\"")
        self.assertEqual(
            escape_path_argument("X:\\Users\\Maito Gai\\\"seven-gates\".y",
                                 osname),
            "\"X:\\Users\\Maito Gai\\^\"seven-gates^\".y\"")
        self.assertEqual(
            escape_path_argument("System32\\my-custom relative tool\\",
                                 osname),
            "\"System32\\my-custom relative tool\\\"")
        self.assertEqual(
            escape_path_argument("System32\\illegal\" name \"\".curd", osname),
            "\"System32\\illegal^\" name ^\"^\".curd\"")

        osname = "INVALID"
        self.assertEqual(
            escape_path_argument("/home/usr/a-file", osname),
            "/home/usr/a-file")
        self.assertEqual(
            escape_path_argument("/home/us r/a-file with spaces.bla", osname),
            "/home/us r/a-file with spaces.bla")
        self.assertEqual(
            escape_path_argument("|home|us r|a*dir with spaces|x|", osname),
            "|home|us r|a*dir with spaces|x|")
        self.assertEqual(
            escape_path_argument("system|a|b|c?d", osname),
            "system|a|b|c?d")
Exemplo n.º 29
0
 def _create_command(self, filename):
     command = self.executable + ' ' + self.arguments
     if not self.use_stdin:
         command += ' ' + escape_path_argument(filename)
     return command