lint
This commit is contained in:
parent
fd4284f5a2
commit
8c5fd9ec25
10 changed files with 248 additions and 286 deletions
|
|
@ -22,7 +22,7 @@ function run(input, output) {
|
|||
var declaration = /^\s*(?:var|let|const|function)[\t ]+([\w_$]+)/gm
|
||||
var include = /(?:((?:var|let|const|,|)[\t ]*)([\w_$\.]+)(\s*=\s*))?require\(([^\)]+)\)(\s*[`\.\(\[])?/gm
|
||||
var uuid = 0
|
||||
function process(filepath, data) {
|
||||
var process = function(filepath, data) {
|
||||
data.replace(declaration, function(match, binding) {bindings[binding] = 0})
|
||||
|
||||
return data.replace(include, function(match, def, variable, eq, dep, rest) {
|
||||
|
|
@ -38,7 +38,7 @@ function run(input, output) {
|
|||
})
|
||||
}
|
||||
|
||||
function resolve(filepath, filename) {
|
||||
var resolve = function(filepath, filename) {
|
||||
if (filename[0] !== ".") {
|
||||
// resolve as npm dependency
|
||||
var packagePath = "./node_modules/" + filename + "/package.json"
|
||||
|
|
@ -52,7 +52,7 @@ function run(input, output) {
|
|||
}
|
||||
}
|
||||
|
||||
function exportCode(filename, filepath, def, variable, eq, rest, uuid) {
|
||||
var exportCode = function(filename, filepath, def, variable, eq, rest, uuid) {
|
||||
var code = read(filepath)
|
||||
// if there's a syntax error, report w/ proper stack trace
|
||||
try {new Function(code)} catch (e) {
|
||||
|
|
@ -63,7 +63,7 @@ function run(input, output) {
|
|||
|
||||
// disambiguate collisions
|
||||
var ignored = {}
|
||||
code.replace(include, function(match, def, variable, eq, dep, rest) {
|
||||
code.replace(include, function(match, def, variable, eq, dep) {
|
||||
var filename = new Function("return " + dep).call()
|
||||
var binding = modules[resolve(filepath, filename)]
|
||||
if (binding != null) ignored[binding] = true
|
||||
|
|
@ -119,7 +119,7 @@ function run(input, output) {
|
|||
module.exports = function(input, output, options) {
|
||||
run(input, output)
|
||||
if (options && options.watch) {
|
||||
fs.watch(process.cwd(), {recursive: true}, function(file, type) {
|
||||
fs.watch(process.cwd(), {recursive: true}, function(file) {
|
||||
if (typeof file === "string" && path.resolve(output) !== path.resolve(file)) run(input, output)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function ensureCodeIsHighlightable(file, data) {
|
|||
block = block.slice(3, -3)
|
||||
if (block.indexOf("javascript") !== 0) {
|
||||
try {if (new Function(block)) console.log(file + " - javascript block missing language tag after triple backtick\n\n" + block + "\n\n---\n\n")}
|
||||
catch (e) {}
|
||||
catch (e) {/*not a js block, ignore*/}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ function ensureCodeIsRunnable(file, data) {
|
|||
try {
|
||||
new Function("console,fetch,module,require", code).call(this, silentConsole, fetch, {exports: {}}, function(dep) {
|
||||
if (dep.indexOf("./mycomponent") === 0) return {view: function() {}}
|
||||
if (dep === "mithril") return m
|
||||
if (dep === "mithril") return global.m
|
||||
})
|
||||
}
|
||||
catch (e) {console.log(file + " - javascript code cannot run\n\n" + e.stack + "\n\n" + code + "\n\n---\n\n")}
|
||||
|
|
@ -93,7 +93,7 @@ global.document = window.document
|
|||
global.m = require("../index")
|
||||
|
||||
//run
|
||||
traverseDirectory("./docs", function(pathname, stat, children) {
|
||||
traverseDirectory("./docs", function(pathname) {
|
||||
if (pathname.indexOf(".md") > -1 && pathname.indexOf("migration") < 0) {
|
||||
fs.readFile(pathname, "utf8", function(err, data) {
|
||||
if (err) console.log(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue