Created
August 2, 2016 21:15
-
-
Save ianjosephwilson/7c6c0a2c833e92b3a82c6d1c8e50286c to your computer and use it in GitHub Desktop.
Testing out the mini racer v8 interface with Douglas Crockford's jslint.js from http://www.jslint.com/.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Testing out the py mini racer v8 interface with Douglas Crockford's jslint.js from http://www.jslint.com/. | |
""" | |
import sys | |
from py_mini_racer import py_mini_racer | |
HTML_PAGE_FORMAT = """<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<h2>Errors</h2> | |
{error_str} | |
<h2>Functions</h2> | |
{function_str} | |
</body> | |
</html>""" | |
test_source = """ | |
/*global | |
console | |
*/ | |
function add1(v) { | |
"use strict"; | |
return v + 1; | |
} | |
console.log(add1(1)); | |
""" | |
def get_html_lint_report(js_source_str): | |
ctx = py_mini_racer.MiniRacer() | |
js_wrapper_str = """function getReport(source) { | |
var result = jslint(source, {browser: true}); | |
return { | |
error: REPORT.error(result), | |
function: REPORT.function(result) | |
}; | |
};""" | |
ctx.eval(open('JSLint/jslint.js', 'r').read()) | |
ctx.eval(open('JSLint/report.js', 'r').read()) | |
ctx.eval(js_wrapper_str) | |
result = ctx.call("getReport", js_source_str) | |
return HTML_PAGE_FORMAT.format(error_str=result['error'], function_str=result['function']) | |
def main(args): | |
if len(args) == 2: | |
js_source_str = open(args[1], 'r').read() | |
else: | |
js_source_str = test_source | |
print get_html_lint_report(js_source_str) | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment