コード例 #1
0
 def loadfile(self, path):
     path = os.path.abspath(path)
     conf = fs.readfile(path)
     try:
         self.loadtext(conf, dir=os.path.dirname(path))
     except ConfError, error:
         error.path = path
         raise
コード例 #2
0
ファイル: conf.py プロジェクト: melloc/javascriptlint
 def loadfile(self, path):
     path = os.path.abspath(path)
     conf = fs.readfile(path, 'utf-8')
     try:
         self.loadtext(conf, dir=os.path.dirname(path))
     except ConfError, error:
         error.path = path
         raise
コード例 #3
0
    def lint_file(path, kind, jsversion):
        def import_script(import_path, jsversion):
            # The user can specify paths using backslashes (such as when
            # linting Windows scripts on a posix environment.
            import_path = import_path.replace('\\', os.sep)
            import_path = os.path.join(os.path.dirname(path), import_path)
            return lint_file(import_path, 'js', jsversion)

        def _lint_error(*args):
            return lint_error(normpath, *args)

        normpath = fs.normpath(path)
        if normpath in lint_cache:
            return lint_cache[normpath]
        if printpaths:
            print normpath
        contents = fs.readfile(path)
        lint_cache[normpath] = _Script()

        script_parts = []
        if kind == 'js':
            script_parts.append((None, jsversion
                                 or conf['default-version'], contents))
        elif kind == 'html':
            assert jsversion is None
            for script in _findhtmlscripts(contents, conf['default-version']):
                # TODO: Warn about foreign languages.
                if not script['jsversion']:
                    continue

                if script['type'] == 'external':
                    other = import_script(script['src'], script['jsversion'])
                    lint_cache[normpath].importscript(other)
                elif script['type'] == 'inline':
                    script_parts.append((script['pos'], script['jsversion'],
                                         script['contents']))
                else:
                    assert False, 'Invalid internal script type %s' % \
                                  script['type']
        else:
            assert False, 'Unsupported file kind: %s' % kind

        _lint_script_parts(script_parts, lint_cache[normpath], _lint_error,
                           conf, import_script)
        return lint_cache[normpath]
コード例 #4
0
ファイル: lint.py プロジェクト: Licenser/smartos-live
    def lint_file(path, kind, jsversion):
        def import_script(import_path, jsversion):
            # The user can specify paths using backslashes (such as when
            # linting Windows scripts on a posix environment.
            import_path = import_path.replace('\\', os.sep)
            import_path = os.path.join(os.path.dirname(path), import_path)
            return lint_file(import_path, 'js', jsversion)
        def _lint_error(*args):
            return lint_error(normpath, *args)

        normpath = fs.normpath(path)
        if normpath in lint_cache:
            return lint_cache[normpath]
        if printpaths:
            print normpath
        contents = fs.readfile(path)
        lint_cache[normpath] = _Script()

        script_parts = []
        if kind == 'js':
            script_parts.append((None, jsversion or conf['default-version'], contents))
        elif kind == 'html':
            assert jsversion is None
            for script in _findhtmlscripts(contents, conf['default-version']):
                # TODO: Warn about foreign languages.
                if not script['jsversion']:
                    continue

                if script['type'] == 'external':
                    other = import_script(script['src'], script['jsversion'])
                    lint_cache[normpath].importscript(other)
                elif script['type'] == 'inline':
                    script_parts.append((script['pos'], script['jsversion'],
                                         script['contents']))
                else:
                    assert False, 'Invalid internal script type %s' % \
                                  script['type']
        else:
            assert False, 'Unsupported file kind: %s' % kind

        _lint_script_parts(script_parts, lint_cache[normpath], _lint_error, conf, import_script)
        return lint_cache[normpath]
コード例 #5
0
ファイル: lint.py プロジェクト: melloc/javascriptlint
    def lint_file(path, kind, jsversion, encoding):
        def import_script(import_path, jsversion):
            # The user can specify paths using backslashes (such as when
            # linting Windows scripts on a posix environment.
            import_path = import_path.replace('\\', os.sep)
            import_path = os.path.join(os.path.dirname(path), import_path)
            return lint_file(import_path, 'js', jsversion, encoding)
        def _lint_error(offset, errname, errdesc):
            pos = node_positions.from_offset(offset)
            return lint_error(normpath, pos.line, pos.col, errname, errdesc)

        normpath = fs.normpath(path)
        if normpath in lint_cache:
            return lint_cache[normpath]
        if printpaths:
            print normpath

        lint_cache[normpath] = _Script()
        try:
            contents = fs.readfile(path, encoding)
        except IOError, error:
            lint_error(normpath, 0, 0, 'io_error', unicode(error))
            return lint_cache[normpath]
コード例 #6
0
def _dump(paths):
    for path in paths:
        script = fs.readfile(path)
        jsparse.dump_tree(script)
コード例 #7
0
ファイル: jsl.py プロジェクト: joshmarshall/javascriptLint
def _dump(paths):
    for path in paths:
        script = fs.readfile(path)
        jsparse.dump_tree(script)
コード例 #8
0
ファイル: jsl.py プロジェクト: melloc/javascriptlint
def _dump(paths, encoding):
    for path in paths:
        script = fs.readfile(path, encoding)
        jsparse.dump_tree(script)