Beispiel #1
0
def ensureClosureWrapper(nodes):
    if not nodes:
        return None, None
    if len(nodes) == 1:
        closure_statements = has_closure_wrapper(nodes[0])
        if closure_statements:
            return nodes[0], closure_statements
    new_tree = treegenerator.createFileTree_from_string("(function(){})();")
    closure_statements = selectNode(new_tree, wrapper_statements_path)
    for node in nodes:
        closure_statements.append(node)
    return new_tree, closure_statements
Beispiel #2
0
def do_lint(file_, popup):
    if popup:
        logger = util.PopupLogger()
    else:
        logger = util.TextMateLogger()

    logger.printHeader("qooxdoo JavaScript lint", "qooxdoo JavaScript lint")
    try:
        opts = lint.defaultOptions()
        opts.allowed_globals = ['qx', 'qxWeb', 'q']

        tree_ = treegenerator.createFileTree_from_string(
            codecs.open(file_, "r", "utf-8").read())
        tree_ = scopes.create_scopes(tree_)
        if not getattr(context, 'console', None):
            context.console = Log()
        if not getattr(context, 'jobconf', None):
            context.jobconf = ExtMap()
        context.jobconf.set("lint-check/warn-unknown-jsdoc-keys", True)
        lint.lint_check(tree_, "", opts)

    except treegenerator.SyntaxException, e:
        logger.log(file_, 0, 0, str(e))
Beispiel #3
0
def main(argv=None):

    # init Context module
    Context.console = Log()
    Context.jobconf = {}

    if argv is None:
        argv = sys.argv

    parser = OptionParser(
        description="Checks ECMAScript/JavaScript files for common errors.")
    parser.add_option(
        "--action",
        "-a",
        dest="actions",
        metavar="ACTION",
        choices=[
            "ALL", "undefined_variables", "unused_variables",
            "multidefined_variables", "maps", "blocks", "fields"
        ],
        action="append",
        default=[],
        help=
        """Performs the given checks on the input files. This parameter may be supplied multiple times.
Valid arguments are: "ALL" (default): Perform all checks
"undefined_variables": Look for identifier, which are referenced in the global scope. This action can find
misspelled identifier and missing 'var' statements. You can use the '-g' flag to add valid global identifiers.
  "unused_variables": Look for identifier, which are defined but never used.
  "multidefined_variables": Look for identifier, which are defined multiple times.
  "blocks" : Look for single statments in bodies of if's and loops that are not enclosed by braces.
  "fields" : Look for class attributes, checking definedness, privates and protected fields.
  "maps": Look for duplicate keys in map declarations. """)
    parser.add_option("-g",
                      dest="globals",
                      help="Add an allowed global identifier GLOBAL",
                      metavar="GLOBAL",
                      action="append",
                      default=[])

    (options, args) = parser.parse_args(argv)

    if len(args) == 1:
        parser.print_help()
        sys.exit(1)

    if options.globals:
        globals_ = options.globals
    else:
        globals_ = []

    checkAll = "ALL" in options.actions or len(options.actions) == 0

    # construct opts argument for lint_check
    keys_map ={  # map cli 'action' keys to lint.options
        "undefined_variables"    : ["ignore_undefined_globals"],
        "unused_variables"       : ["ignore_unused_variables", "ignore_unused_parameter"],
        "multidefined_variables" : ["ignore_multiple_vardecls"],
        "maps"   : ["ignore_multiple_mapkeys"],
        "blocks" : ["ignore_no_loop_block"],
        "fields" : ["ignore_reference_fields", "ignore_undeclared_privates"],
    }
    opts = lint.defaultOptions()
    opts.allowed_globals = options.globals
    for opt in (o for o in vars(opts) if o.startswith("ignore_")):
        if checkAll:
            setattr(opts, opt, False)
        else:
            for argopt in keys_map:
                if argopt in options.actions and opt in keys_map[argopt]:
                    setattr(opts, opt, False)
                    break
            else:
                setattr(opts, opt, True)

    for filename in args[1:]:
        tree_ = treegenerator.createFileTree_from_string(
            codecs.open(filename, "r", "utf-8").read())
        tree_ = scopes.create_scopes(tree_)
        lint.lint_check(tree_, filename, opts)

    return  ## TODO: rc
Beispiel #4
0
def main(argv=None):

    # init Context module
    Context.console = Log()
    Context.jobconf = {}

    if argv is None:
        argv = sys.argv

    parser = OptionParser(description="Checks ECMAScript/JavaScript files for common errors.")
    parser.add_option(
        "--action", "-a", dest="actions", metavar="ACTION",
        choices=["ALL", "undefined_variables", "unused_variables", "multidefined_variables", "maps", "blocks", "fields"], action="append", default=[],
        help="""Performs the given checks on the input files. This parameter may be supplied multiple times.
Valid arguments are: "ALL" (default): Perform all checks
"undefined_variables": Look for identifier, which are referenced in the global scope. This action can find
misspelled identifier and missing 'var' statements. You can use the '-g' flag to add valid global identifiers.
  "unused_variables": Look for identifier, which are defined but never used.
  "multidefined_variables": Look for identifier, which are defined multiple times.
  "blocks" : Look for single statments in bodies of if's and loops that are not enclosed by braces.
  "fields" : Look for class attributes, checking definedness, privates and protected fields.
  "maps": Look for duplicate keys in map declarations. """
    )
    parser.add_option(
        "-g", dest="globals", help="Add an allowed global identifier GLOBAL",
        metavar="GLOBAL", action="append", default=[]
    )

    (options, args) = parser.parse_args(argv)

    if len(args) == 1:
        parser.print_help()
        sys.exit(1)

    if options.globals:
        globals_ = options.globals
    else:
        globals_ = []

    checkAll = "ALL" in options.actions or len(options.actions) == 0

    # construct opts argument for lint_check
    keys_map ={  # map cli 'action' keys to lint.options
        "undefined_variables"    : ["ignore_undefined_globals"], 
        "unused_variables"       : ["ignore_unused_variables", "ignore_unused_parameter"],
        "multidefined_variables" : ["ignore_multiple_vardecls"], 
        "maps"   : ["ignore_multiple_mapkeys"], 
        "blocks" : ["ignore_no_loop_block"], 
        "fields" : ["ignore_reference_fields", "ignore_undeclared_privates"],
    }
    opts = lint.defaultOptions()
    opts.allowed_globals = options.globals
    for opt in (o for o in vars(opts) if o.startswith("ignore_")):
        if checkAll:
            setattr(opts, opt, False)
        else:
            for argopt in keys_map:
                if argopt in options.actions and opt in keys_map[argopt]:
                    setattr(opts, opt, False)
                    break
            else:
                setattr(opts, opt, True)


    for filename in args[1:]:
        tree_ = treegenerator.createFileTree_from_string(codecs.open(filename, "r", "utf-8").read())
        tree_ = scopes.create_scopes(tree_)
        lint.lint_check(tree_, filename, opts)

    return ## TODO: rc