diff --git a/src/node-bunyan/tools/cutarelease.py b/src/node-bunyan/tools/cutarelease.py index 2cfeb983f..8ffbb6281 100755 --- a/src/node-bunyan/tools/cutarelease.py +++ b/src/node-bunyan/tools/cutarelease.py @@ -12,6 +12,7 @@ Conventions: - XXX """ +from __future__ import print_function __version_info__ = (1, 0, 7) __version__ = '.'.join(map(str, __version_info__)) @@ -111,7 +112,7 @@ def cutarelease(project_name, version_files, dry_run=False): "Are you sure you want cut a %s release?\n" "This will involved commits and a push." % version, default="no") - print "* * *" + print("* * *") if answer != "yes": log.info("user abort") return @@ -135,7 +136,7 @@ def cutarelease(project_name, version_files, dry_run=False): "The changelog '%s' top section doesn't have the expected\n" "'%s' marker. Has this been released already?" % (changes_path, nyr), default="yes") - print "* * *" + print("* * *") if answer != "no": log.info("abort") return @@ -165,7 +166,7 @@ def cutarelease(project_name, version_files, dry_run=False): # Optionally release. if exists("package.json"): answer = query_yes_no("\n* * *\nPublish to npm?", default="yes") - print "* * *" + print("* * *") if answer == "yes": if dry_run: log.info("skipping npm publish (dry-run)") @@ -173,7 +174,7 @@ def cutarelease(project_name, version_files, dry_run=False): run('npm publish') elif exists("setup.py"): answer = query_yes_no("\n* * *\nPublish to pypi?", default="yes") - print "* * *" + print("* * *") if answer == "yes": if dry_run: log.info("skipping pypi publish (dry-run)") diff --git a/tools/javascriptlint/javascriptlint/conf.py b/tools/javascriptlint/javascriptlint/conf.py index 66c31dd96..c094b367c 100644 --- a/tools/javascriptlint/javascriptlint/conf.py +++ b/tools/javascriptlint/javascriptlint/conf.py @@ -1,10 +1,12 @@ # vim: ts=4 sw=4 expandtab +from __future__ import absolute_import + import os import unittest -import fs -import util -import warnings +from . import fs +from . import util +from . import warnings def _getwarningsconf(): lines = [] @@ -113,7 +115,7 @@ class DeprecatedSetting(Setting): wants_parm = False value = None def load(self, enabled): - raise ConfError, 'This setting is deprecated.' + raise ConfError('This setting is deprecated.') class BooleanSetting(Setting): wants_parm = False @@ -128,7 +130,7 @@ def __init__(self, default): self.value = default def load(self, enabled, parm): if not enabled: - raise ConfError, 'Expected +.' + raise ConfError('Expected +.') self.value = parm class DeclareSetting(Setting): @@ -137,7 +139,7 @@ def __init__(self): self.value = [] def load(self, enabled, parm): if not enabled: - raise ConfError, 'Expected +.' + raise ConfError('Expected +.') self.value.append(parm) class ProcessSetting(Setting): @@ -156,11 +158,11 @@ class JSVersionSetting(Setting): value = util.JSVersion.default() def load(self, enabled, parm): if not enabled: - raise ConfError, 'Expected +.' + raise ConfError('Expected +.') self.value = util.JSVersion.fromtype(parm) if not self.value: - raise ConfError, 'Invalid JavaScript version: %s' % parm + raise ConfError('Invalid JavaScript version: %s' % parm) class Conf: def __init__(self): @@ -190,7 +192,7 @@ def loadfile(self, path): conf = fs.readfile(path) try: self.loadtext(conf, dir=os.path.dirname(path)) - except ConfError, error: + except ConfError as error: error.path = path raise @@ -199,7 +201,7 @@ def loadtext(self, conf, dir=None): for lineno in range(0, len(lines)): try: self.loadline(lines[lineno], dir) - except ConfError, error: + except ConfError as error: error.lineno = lineno raise @@ -220,7 +222,7 @@ def loadline(self, line, dir=None): elif line.startswith('-'): enabled = False else: - raise ConfError, 'Expected + or -.' + raise ConfError('Expected + or -.') line = line[1:] # Parse the key/parms @@ -235,7 +237,7 @@ def loadline(self, line, dir=None): if setting.wants_parm: args['parm'] = parm elif parm: - raise ConfError, 'The %s setting does not expect a parameter.' % name + raise ConfError('The %s setting does not expect a parameter.' % name) if setting.wants_dir: args['dir'] = dir setting.load(**args) diff --git a/tools/javascriptlint/javascriptlint/jsl.py b/tools/javascriptlint/javascriptlint/jsl.py index 4eee0b65b..e96c5ac31 100755 --- a/tools/javascriptlint/javascriptlint/jsl.py +++ b/tools/javascriptlint/javascriptlint/jsl.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # vim: ts=4 sw=4 expandtab +from __future__ import print_function +from __future__ import absolute_import import codecs import fnmatch import glob @@ -8,11 +10,11 @@ import unittest from optparse import OptionParser -import conf -import htmlparse -import jsparse -import lint -import util +from . import conf +from . import htmlparse +from . import jsparse +from . import lint +from . import util _lint_results = { 'warnings': 0, @@ -27,8 +29,8 @@ def _dump(paths): def _lint(paths, conf_, printpaths): def lint_error(path, line, col, errname, errdesc): _lint_results['warnings'] = _lint_results['warnings'] + 1 - print util.format_error(conf_['output-format'], path, line, col, - errname, errdesc) + print(util.format_error(conf_['output-format'], path, line, col, + errname, errdesc)) lint.lint_files(paths, lint_error, conf=conf_, printpaths=printpaths) def _resolve_paths(path, recurse): @@ -48,8 +50,8 @@ def _resolve_paths(path, recurse): def printlogo(): # TODO: Print version number. - print "JavaScript Lint" - print "Developed by Matthias Miller (http://www.JavaScriptLint.com)" + print("JavaScript Lint") + print("Developed by Matthias Miller (http://www.JavaScriptLint.com)") def _profile_enabled(func, *args, **kwargs): import tempfile @@ -104,7 +106,7 @@ def main(): sys.exit() if options.showdefaultconf: - print conf.DEFAULT_CONF + print(conf.DEFAULT_CONF) sys.exit() if options.printlogo: @@ -142,8 +144,8 @@ def main(): profile_func(_lint, paths, conf_, options.printlisting) if options.printsummary: - print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'], - _lint_results['warnings']) + print('\n%i error(s), %i warnings(s)' % (_lint_results['errors'], + _lint_results['warnings'])) if _lint_results['errors']: sys.exit(3) diff --git a/tools/javascriptlint/javascriptlint/jsparse.py b/tools/javascriptlint/javascriptlint/jsparse.py index eec82a477..2d00d844b 100644 --- a/tools/javascriptlint/javascriptlint/jsparse.py +++ b/tools/javascriptlint/javascriptlint/jsparse.py @@ -1,13 +1,15 @@ #!/usr/bin/env python # vim: ts=4 sw=4 expandtab """ Parses a script into nodes. """ +from __future__ import print_function +from __future__ import absolute_import import bisect import re import unittest -import spidermonkey -from spidermonkey import tok, op -from util import JSVersion +from . import spidermonkey +from .spidermonkey import tok, op +from .util import JSVersion _tok_names = dict(zip( [getattr(tok, prop) for prop in dir(tok)], @@ -253,27 +255,27 @@ def is_compilable_unit(script, jsversion): def _dump_node(node, depth=0): if node is None: - print ' '*depth, - print '(None)' - print + print(' '*depth, end=' ') + print('(None)') + print() else: - print ' '*depth, - print '%s, %s' % (_tok_names[node.kind], _op_names[node.opcode]) - print ' '*depth, - print '%s - %s' % (node.start_pos(), node.end_pos()) + print(' '*depth, end=' ') + print('%s, %s' % (_tok_names[node.kind], _op_names[node.opcode])) + print(' '*depth, end=' ') + print('%s - %s' % (node.start_pos(), node.end_pos())) if hasattr(node, 'atom'): - print ' '*depth, - print 'atom: %s' % node.atom + print(' '*depth, end=' ') + print('atom: %s' % node.atom) if node.no_semi: - print ' '*depth, - print '(no semicolon)' - print + print(' '*depth, end=' ') + print('(no semicolon)') + print() for node in node.kids: _dump_node(node, depth+1) def dump_tree(script): def error_callback(line, col, msg): - print '(%i, %i): %s', (line, col, msg) + print('(%i, %i): %s', (line, col, msg)) node = parse(script, None, error_callback) _dump_node(node) diff --git a/tools/javascriptlint/javascriptlint/lint.py b/tools/javascriptlint/javascriptlint/lint.py index f2967a43c..d6cc3b547 100644 --- a/tools/javascriptlint/javascriptlint/lint.py +++ b/tools/javascriptlint/javascriptlint/lint.py @@ -1,18 +1,20 @@ #!/usr/bin/env python # vim: ts=4 sw=4 expandtab +from __future__ import print_function +from __future__ import absolute_import import os.path import re -import conf -import fs -import htmlparse -import jsparse -import visitation -import warnings +from . import conf +from . import fs +from . import htmlparse +from . import jsparse +from . import visitation +from . import warnings import unittest -import util +from . import util -from spidermonkey import tok, op +from .spidermonkey import tok, op _newline_kinds = ( 'eof', 'comma', 'dot', 'semi', 'colon', 'lc', 'rc', 'lp', 'rb', 'assign', @@ -302,7 +304,7 @@ def _lint_error(*args): if normpath in lint_cache: return lint_cache[normpath] if printpaths: - print normpath + print(normpath) contents = fs.readfile(path) lint_cache[normpath] = _Script() @@ -524,7 +526,7 @@ def _report(pos, errname, errdesc, require_key): try: if not conf[errname]: return - except KeyError, err: + except KeyError as err: if require_key: raise @@ -568,7 +570,7 @@ def onpush(node): try: ret = visitor(node) assert ret is None, 'visitor should raise an exception, not return a value' - except warnings.LintWarning, warning: + except warnings.LintWarning as warning: # TODO: This is ugly hardcoding to improve the error positioning of # "missing_semicolon" errors. if visitor.warning in ('missing_semicolon', 'missing_semicolon_for_lambda'): diff --git a/tools/javascriptlint/javascriptlint/visitation.py b/tools/javascriptlint/javascriptlint/visitation.py index 573db1ce5..60a9f17d2 100644 --- a/tools/javascriptlint/javascriptlint/visitation.py +++ b/tools/javascriptlint/javascriptlint/visitation.py @@ -27,9 +27,9 @@ def make_visitors(visitors, klasses): # Intantiate an instance of each class for klass in klasses: if klass.__name__.lower() != klass.__name__: - raise ValueError, 'class names must be lowercase' + raise ValueError('class names must be lowercase') if not klass.__doc__: - raise ValueError, 'missing docstring on class %s' % klass.__name__ + raise ValueError('missing docstring on class %s' % klass.__name__) # Look for functions with the "_visit_nodes" property. visitor = klass() diff --git a/tools/javascriptlint/javascriptlint/warnings.py b/tools/javascriptlint/javascriptlint/warnings.py index 7f596e99c..24e2f8cfe 100644 --- a/tools/javascriptlint/javascriptlint/warnings.py +++ b/tools/javascriptlint/javascriptlint/warnings.py @@ -14,14 +14,16 @@ def warning_name(node): if questionable: raise LintWarning, node """ +from __future__ import absolute_import + import re import sys import types -import util -import visitation +from . import util +from . import visitation -from spidermonkey import tok, op +from .spidermonkey import tok, op _ALL_TOKENS = tuple(filter(lambda x: x != tok.EOF, tok.__dict__.values())) @@ -104,13 +106,13 @@ def format_error(errname, **errargs): try: errdesc = re.sub(r"{(\w+)}", lambda match: errargs[match.group(1)], errdesc) except (TypeError, KeyError): - raise KeyError, 'Invalid keyword in error: ' + errdesc + raise KeyError('Invalid keyword in error: ' + errdesc) return errdesc _visitors = [] def lookfor(*args): def decorate(fn): - fn.warning = fn.func_name.rstrip('_') + fn.warning = fn.__name__.rstrip('_') assert fn.warning in warnings, 'Missing warning description: %s' % fn.warning for arg in args: @@ -230,17 +232,17 @@ def break_to_none(node): def comparison_type_conv(node): for kid in node.kids: if kid.kind == tok.PRIMARY and kid.opcode in (op.NULL, op.TRUE, op.FALSE): - raise LintWarning, kid + raise LintWarning(kid) if kid.kind == tok.NUMBER and not kid.dval: - raise LintWarning, kid + raise LintWarning(kid) if kid.kind == tok.STRING and not kid.atom: - raise LintWarning, kid + raise LintWarning(kid) @lookfor(tok.DEFAULT) def default_not_at_end(node): siblings = node.parent.kids if node.node_index != len(siblings)-1: - raise LintWarning, siblings[node.node_index+1] + raise LintWarning(siblings[node.node_index+1]) @lookfor(tok.CASE) def duplicate_case_in_switch(node): @@ -253,7 +255,7 @@ def duplicate_case_in_switch(node): if sibling.kind == tok.CASE: sibling_value = sibling.kids[0] if node_value.is_equivalent(sibling_value, True): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.SWITCH) def missing_default_case(node): @@ -261,21 +263,21 @@ def missing_default_case(node): for case in cases.kids: if case.kind == tok.DEFAULT: return - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.WITH) def with_statement(node): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.EQOP,tok.RELOP) def useless_comparison(node): lvalue, rvalue = node.kids if lvalue.is_equivalent(rvalue): - raise LintWarning, node + raise LintWarning(node) @lookfor((tok.COLON, op.NAME)) def use_of_label(node): - raise LintWarning, node + raise LintWarning(node) @lookfor((tok.OBJECT, op.REGEXP)) def misplaced_regex(node): @@ -291,12 +293,12 @@ def misplaced_regex(node): return # Allow in /re/.property if node.parent.kind == tok.RETURN: return # Allow for return values - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.ASSIGN) def assign_to_function_call(node): if node.kids[0].kind == tok.LP: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.IF) def ambiguous_else_stmt(node): @@ -312,13 +314,13 @@ def ambiguous_else_stmt(node): return # Else is only ambiguous in the first branch of an if statement. if tmp.parent.kind == tok.IF and tmp.node_index == 1: - raise LintWarning, else_ + raise LintWarning(else_) tmp = tmp.parent @lookfor(tok.IF, tok.WHILE, tok.DO, tok.FOR, tok.WITH) def block_without_braces(node): if node.kids[1].kind != tok.LC: - raise LintWarning, node.kids[1] + raise LintWarning(node.kids[1]) _block_nodes = (tok.IF, tok.WHILE, tok.DO, tok.FOR, tok.WITH) @lookfor(*_block_nodes) @@ -331,7 +333,7 @@ def ambiguous_nested_stmt(node): # was inside a block statement without clarifying curlies. # (Otherwise, the node type would be tok.LC.) if node.parent.kind in _block_nodes: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.INC, tok.DEC) def inc_dec_within_stmt(node): @@ -347,7 +349,7 @@ def inc_dec_within_stmt(node): tmp.parent.parent.kind == tok.FOR: return - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.COMMA) def comma_separated_stmts(node): @@ -357,12 +359,12 @@ def comma_separated_stmts(node): # This is an array if node.parent.kind == tok.RB: return - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.SEMI) def empty_statement(node): if not node.kids[0]: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.LC) def empty_statement_(node): if node.kids: @@ -373,7 +375,7 @@ def empty_statement_(node): # Some empty blocks are meaningful. if node.parent.kind in (tok.CATCH, tok.CASE, tok.DEFAULT, tok.SWITCH, tok.FUNCTION): return - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.CASE, tok.DEFAULT) def missing_break(node): @@ -387,7 +389,7 @@ def missing_break(node): return if None in _get_exit_points(case_contents): # Show the warning on the *next* node. - raise LintWarning, node.parent.kids[node.node_index+1] + raise LintWarning(node.parent.kids[node.node_index+1]) @lookfor(tok.CASE, tok.DEFAULT) def missing_break_for_last_case(node): @@ -396,16 +398,16 @@ def missing_break_for_last_case(node): case_contents = node.kids[1] assert case_contents.kind == tok.LC if None in _get_exit_points(case_contents): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.INC) def multiple_plus_minus(node): if node.node_index == 0 and node.parent.kind == tok.PLUS: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.DEC) def multiple_plus_minus_(node): if node.node_index == 0 and node.parent.kind == tok.MINUS: - raise LintWarning, node + raise LintWarning(node) @lookfor((tok.NAME, op.SETNAME)) def useless_assign(node): @@ -415,7 +417,7 @@ def useless_assign(node): elif node.parent.kind == tok.VAR: value = node.kids[0] if value and value.kind == tok.NAME and node.atom == value.atom: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.BREAK, tok.CONTINUE, tok.RETURN, tok.THROW) def unreachable_code(node): @@ -426,12 +428,12 @@ def unreachable_code(node): for variable in sibling.kids: value, = variable.kids if value: - raise LintWarning, value + raise LintWarning(value) elif sibling.kind == tok.FUNCTION: # Functions are always declared. pass else: - raise LintWarning, sibling + raise LintWarning(sibling) @lookfor(tok.FOR) def unreachable_code_(node): @@ -441,68 +443,68 @@ def unreachable_code_(node): pre, condition, post = preamble.kids if post: if not None in _get_exit_points(code): - raise LintWarning, post + raise LintWarning(post) @lookfor(tok.DO) def unreachable_code__(node): # Warn if the do..while loop always exits. code, condition = node.kids if not None in _get_exit_points(code): - raise LintWarning, condition + raise LintWarning(condition) #TODO: @lookfor(tok.IF) def meaningless_block(node): condition, if_, else_ = node.kids if condition.kind == tok.PRIMARY and condition.opcode in (op.TRUE, op.FALSE, op.NULL): - raise LintWarning, condition + raise LintWarning(condition) #TODO: @lookfor(tok.WHILE) def meaningless_blocK_(node): condition = node.kids[0] if condition.kind == tok.PRIMARY and condition.opcode in (op.FALSE, op.NULL): - raise LintWarning, condition + raise LintWarning(condition) @lookfor(tok.LC) def meaningless_block__(node): if node.parent and node.parent.kind == tok.LC: - raise LintWarning, node + raise LintWarning(node) @lookfor((tok.UNARYOP, op.VOID)) def useless_void(node): - raise LintWarning, node + raise LintWarning(node) @lookfor((tok.LP, op.CALL)) def parseint_missing_radix(node): if node.kids[0].kind == tok.NAME and node.kids[0].atom == 'parseInt' and len(node.kids) <= 2: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.NUMBER) def leading_decimal_point(node): if node.atom.startswith('.'): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.NUMBER) def trailing_decimal_point(node): if node.parent.kind == tok.DOT: - raise LintWarning, node + raise LintWarning(node) if node.atom.endswith('.'): - raise LintWarning, node + raise LintWarning(node) _octal_regexp = re.compile('^0[0-9]') @lookfor(tok.NUMBER) def octal_number(node): if _octal_regexp.match(node.atom): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.RB) def trailing_comma_in_array(node): if node.end_comma: - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.STRING) def useless_quotes(node): if node.node_index == 0 and node.parent.kind == tok.COLON: # Only warn if the quotes could safely be removed. if util.isidentifier(node.atom): - raise LintWarning, node + raise LintWarning(node) @lookfor(tok.SEMI) def want_assign_or_call(node): @@ -524,7 +526,7 @@ def want_assign_or_call(node): grandchild = child.kids[0] if grandchild.kind == tok.FUNCTION: return - raise LintWarning, child + raise LintWarning(child) def _check_return_value(node): name = node.fn_name or '(anonymous function)' @@ -594,7 +596,7 @@ def duplicate_formal(node): def missing_semicolon(node): if node.no_semi: if not _get_assigned_lambda(node): - raise LintWarning, node + raise LintWarning(node) @lookfor(*_ALL_TOKENS) def missing_semicolon_for_lambda(node): @@ -603,7 +605,7 @@ def missing_semicolon_for_lambda(node): # statements, so use the position of the lambda instead. lambda_ = _get_assigned_lambda(node) if lambda_: - raise LintWarning, lambda_ + raise LintWarning(lambda_) @lookfor() def ambiguous_newline(node):