function Reporter(lines, ruleset, allow, ignore) {
"use strict";
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
/**
* Lines with specific rule messages to leave out of the report.
* @property allow
* @type Object
*/
this.allow = allow;
if (!this.allow) {
this.allow = {};
}
/**
* Linesets not to include in the report.
* @property ignore
* @type [][]
*/
this.ignore = ignore;
if (!this.ignore) {
this.ignore = [];
}
}
n/a
_testCase_jslintAndPrintConditional_default = function (opt, onError) {
/*
* this function will test jslintAndPrintConditional's default handling-behavior
*/
local.testMock([
[
local.jslint, {
errMsg: ""
}
]
], function (onError) {
// test no csslint handling-behavior
local.jslintAndPrintConditional("no csslint", "empty.css");
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
// test csslint passed handling-behavior
local.jslintAndPrintConditional(
"/*csslint*/\nbody { display: block; }",
"passed.css",
"force"
);
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
// test no jslint handling-behavior
local.jslintAndPrintConditional("no jslint", "empty.js");
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
// test jslint passed handling-behavior
local.jslintAndPrintConditional(
"/*jslint node: true*/\nconsole.log(\"aa\");",
"passed.js",
"force"
);
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
onError(null, opt);
// test no shlint handling-behavior
local.jslintAndPrintConditional("no shlint", "empty.sh");
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
// test shlint passed handling-behavior
local.jslintAndPrintConditional((
"# jslint utility2:true\n"
+ "shAa () {\n"
+ " node -e \"\n"
+ "local = {};\n"
+ "local.aa = function () {\n"
+ " return;\n"
+ "};\n"
+ " \"\n"
+ "}\n"
), "passed.sh", "force");
// handle err
local.assertOrThrow(!local.jslint.errMsg, local.jslint.errMsg);
}, onError);
}
n/a
assertOrThrow = function (passed, msg) {
/*
* this function will throw err.<msg> if <passed> is falsy
*/
if (passed) {
return;
}
throw (
(
msg
&& typeof msg.message === "string"
&& typeof msg.stack === "string"
)
// if msg is err, then leave as is
? msg
: new Error(
typeof msg === "string"
// if msg is a string, then leave as is
? msg
// else JSON.stringify msg
: JSON.stringify(msg, undefined, 4)
)
);
}
...
argList: local.coalesce(commandList[ii][1], "").trim(),
command: [
key
],
description: commandList[ii][2]
};
} catch (ignore) {
local.assertOrThrow(undefined, new Error(
"cliRun - cannot parse comment in COMMAND "
+ key
+ ":\nnew RegExp("
+ JSON.stringify(opt.rgxComment.source)
+ ").exec(" + JSON.stringify(str).replace((
/\\\\/g
), "\u0000").replace((
...
cliRun = function (opt) {
/*
* this function will run cli with given <opt>
*/
local.cliDict._eval = local.cliDict._eval || function () {
/*
* <code>
* will eval <code>
*/
globalThis.local = local;
local.vm.runInThisContext(process.argv[3]);
};
local.cliDict._help = local.cliDict._help || function () {
/*
*
* will print help
*/
let commandList;
let file;
let packageJson;
let str;
let strDict;
commandList = [
{
argList: "<arg2> ...",
description: "usage:",
command: [
"<arg1>"
]
}, {
argList: "'console.log(\"hello world\")'",
description: "example:",
command: [
"--eval"
]
}
];
file = __filename.replace((
/.*\//
), "");
opt = Object.assign({}, opt);
packageJson = require("./package.json");
// validate comment
opt.rgxComment = opt.rgxComment || (
/\)\u0020\{\n(?:|\u0020{4})\/\*\n(?:\u0020|\u0020{5})\*((?:\u0020<[^>]*?>|\u0020\.\.\.)*?)\n(?:\u0020|\u0020{5})\*\u0020
(will\u0020.*?\S)\n(?:\u0020|\u0020{5})\*\/\n(?:\u0020{4}|\u0020{8})\S/
);
strDict = {};
Object.keys(local.cliDict).sort().forEach(function (key, ii) {
if (key[0] === "_" && key !== "_default") {
return;
}
str = String(local.cliDict[key]);
if (key === "_default") {
key = "";
}
strDict[str] = strDict[str] || (ii + 2);
ii = strDict[str];
if (commandList[ii]) {
commandList[ii].command.push(key);
return;
}
try {
commandList[ii] = opt.rgxComment.exec(str);
commandList[ii] = {
argList: local.coalesce(commandList[ii][1], "").trim(),
command: [
key
],
description: commandList[ii][2]
};
} catch (ignore) {
local.assertOrThrow(undefined, new Error(
"cliRun - cannot parse comment in COMMAND "
+ key
+ ":\nnew RegExp("
+ JSON.stringify(opt.rgxComment.source)
+ ").exec(" + JSON.stringify(str).replace((
/\\\\/g
), "\u0000").replace((
/\\n/g
), "\\n\\\n").replace((
/\u0000/g
), "\\\\") + ");"
));
}
});
str = "";
str += packageJson.name + " (" + packageJson.version + ")\n\n";
str += commandList.filter(function (elem) {
return elem;
}).map(function (elem, ii) {
elem.command = elem.command.filter(function (elem) {
return elem;
});
switch (ii) {
case 0:
case 1:
elem.argList = [
elem.argList
];
break;
default:
elem.argList = elem.argList.split(" ");
elem.description = (
"# COMMAND "
+ (elem.command[0] || "<none>") + "\n# "
+ elem.description
);
}
return (
elem.description + "\n " + file
+ " &quo...
n/a
coalesce = function (...argList) {
/*
* this function will coalesce null, undefined, or "" in <argList>
*/
let arg;
let ii;
ii = 0;
while (ii < argList.length) {
arg = argList[ii];
if (arg !== null && arg !== undefined && arg !== "") {
break;
}
ii += 1;
}
return arg;
}
...
if (commandList[ii]) {
commandList[ii].command.push(key);
return;
}
try {
commandList[ii] = opt.rgxComment.exec(str);
commandList[ii] = {
argList: local.coalesce(commandList[ii][1], "").trim(),
command: [
key
],
description: commandList[ii][2]
};
} catch (ignore) {
local.assertOrThrow(undefined, new Error(
...
fsReadFileOrDefaultSync = function (pathname, type, dflt) {
/*
* this function will sync-read <pathname> with given <type> and <dflt>
*/
let fs;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
return dflt;
}
pathname = require("path").resolve(pathname);
// try to read pathname
try {
return (
type === "json"
? JSON.parse(fs.readFileSync(pathname, "utf8"))
: fs.readFileSync(pathname, type)
);
} catch (ignore) {
return dflt;
}
}
n/a
fsRmrfSync = function (pathname) {
/*
* this function will sync "rm -rf" <pathname>
*/
let child_process;
// do nothing if module does not exist
try {
child_process = require("child_process");
} catch (ignore) {
return;
}
pathname = require("path").resolve(pathname);
if (process.platform !== "win32") {
child_process.spawnSync("rm", [
"-rf", pathname
], {
stdio: [
"ignore", 1, 2
]
});
return;
}
try {
child_process.spawnSync("rd", [
"/s", "/q", pathname
], {
stdio: [
"ignore", 1, "ignore"
]
});
} catch (ignore) {}
}
n/a
fsWriteFileWithMkdirpSync = function (pathname, data, msg) {
/*
* this function will sync write <data> to <pathname> with "mkdir -p"
*/
let fs;
let success;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
return;
}
pathname = require("path").resolve(pathname);
// try to write pathname
try {
fs.writeFileSync(pathname, data);
success = true;
} catch (ignore) {
// mkdir -p
fs.mkdirSync(require("path").dirname(pathname), {
recursive: true
});
// re-write pathname
fs.writeFileSync(pathname, data);
success = true;
}
if (success && msg) {
console.error(msg.replace("{{pathname}}", pathname));
}
return success;
}
n/a
identity = function (val) {
/*
* this function will return <val>
*/
return val;
}
...
local.cliDict.help = local.cliDict.help || local.cliDict._help;
local.cliDict._interactive = local.cliDict._interactive || function () {
/*
*
* will start interactive-mode
*/
globalThis.local = local;
local.identity(local.replStart || require("repl").start)({
useGlobal: true
});
};
local.cliDict["--interactive"] = (
local.cliDict["--interactive"]
|| local.cliDict._interactive
);
...
jslintAndPrint = function (code = "", file = "undefined", opt = {}) {
/*
* this function will jslint/csslint <code> and print any errors to stderr
*/
let ii;
let tmp;
if (!(opt && opt.gotoState)) {
local.jslintResult = {
gotoState: 0
};
}
opt = Object.assign(local.jslintResult, opt);
opt.gotoState += 1;
switch (opt.gotoState) {
// jslint - init
case 1:
// cleanup
opt.errList = [];
opt.errMsg = "";
// preserve lineno
if (opt.iiStart) {
opt.lineOffset |= 0;
ii = 0;
while (true) {
ii = code.indexOf("\n", ii);
if (ii === 0 || ii > opt.iiStart) {
break;
}
ii += 1;
opt.lineOffset += 1;
}
code = code.slice(opt.iiStart, opt.iiEnd || code.length);
}
switch (opt.fileType0) {
// de-embed-js - '\\n\\\n...\\n\\\n'
case ".\\n\\":
// rgx - remove \\n\\
code = code.replace((
/\\n\\$|\\(.)/gm
), function (ignore, match1) {
return match1 || "";
});
break;
// de-embed-js - '\n...\n'
case ".sh":
// rgx - convert '"'"' to '
code = code.replace((
/'"'"'/g
), "'");
break;
}
// init
opt = Object.assign(opt, {
".css": (
/^\/\*csslint\b|(^\/\*\u0020jslint\u0020utility2:true\u0020\*\/$)/m
),
".html": (
/^\/\*csslint\b|(^\/\*\u0020jslint\u0020utility2:true\u0020\*\/$)/m
),
".js": (
/^\/\*jslint\b|(^\/\*\u0020jslint\u0020utility2:true\u0020\*\/$)/m
),
".json": (
/^\s*?(?:\[|\{)/
),
".md": (
/(^\/\*\u0020jslint\u0020utility2:true\u0020\*\/$)/m
),
".sh": (
/(^#\u0020jslint\u0020utility2:true$)/m
),
code0: code,
fileType: (
/\.\w+?$|$/m
).exec(file)[0]
});
// jslint - .json
if (opt.fileType === ".js" && opt[".json"].test(code)) {
opt.fileType = ".json";
}
try {
opt.conditionalPassed = opt[opt.fileType].exec(code);
} catch (ignore) {}
opt.utility2 = (
opt.conditionalPassed && opt.conditionalPassed[1]
) || opt.autofix;
if (
opt.conditional
&& (!opt.conditionalPassed || opt.coverage)
) {
break;
}
opt.gotoState = 10;
break;
// jslint - autofix
case 11:
code = local.jslintAutofix(code, file, opt);
local.jslintResult = opt;
break;
// jslint - csslint and jslint
case 12:
// restore lineOffset
code = "\n".repeat(opt.lineOffset | 0) + code;
switch (opt.fileType) {
case ".css":
// csslint
Object.assign(opt, local.CSSLint.verify(code));
// init errList
opt.errList = opt.messages.map(function (err) {
err.column = err.col;
err.message = (
err.type + " - " + err.rule.id + " - " + err.message
+ "\n " + err.rule.desc
);
return err;
});
break;
case ".html":
case ".md":
case ".sh":
break;
default:
// jslint - .js...
...
local = window.utility2_jslint;\n\
local.domOnEventInputChange = function (evt) {\n\
switch (evt.type + "." + evt.target.id) {\n\
case "click.buttonJslintAutofix1":\n\
case "keyup.inputCsslint1":\n\
case "keyup.inputJslint1":\n\
// csslint #inputCsslint1\n\
local.jslintAndPrint(document.querySelector(\n\
"#inputCsslint1"\n\
).value, "inputCsslint1.css");\n\
document.querySelector(\n\
"#outputCsslint1"\n\
).value = local.jslintResult.errMsg.replace((\n\
/\\u001b\\[\\d*m/g\n\
), "").trim();\n\
...
jslintAndPrintDir = function (dir, opt, onError) {
/*
* this function will jslint files in shallow <dir>
*/
let onParallel;
onParallel = local.onParallel(onError);
local.fs.readdirSync(dir).forEach(function (file) {
let timeStart;
file = local.path.resolve(file);
switch ((
/\.\w+?$|$/m
).exec(file)[0]) {
case ".css":
case ".html":
case ".js":
case ".json":
case ".md":
case ".sh":
if ((
/\b(?:assets\.app\.js|lock|min|raw|rollup)\b/
).test(file)) {
return;
}
onParallel.cnt += 1;
// jslint file
local.fs.readFile(file, "utf8", function (err, data) {
// handle err
local.assertOrThrow(!err, err);
timeStart = Date.now();
local.jslintAndPrint(data, file, opt);
console.error(
"jslint - " + (Date.now() - timeStart) + "ms " + file
);
onParallel();
});
break;
}
});
}
n/a
jslintAutofix = function (code, file, opt) {
/*
* this function will jslint-autofix <code>
*/
let code0;
let code2;
let dataList;
let ignoreList;
let ii;
let rgx1;
let rgx2;
let tmp;
// autofix-all
if (opt.autofix) {
// autofix-all - normalize local-function
if (
globalThis.utility2
&& typeof globalThis.utility2.jslintAutofixLocalFunction
=== "function"
) {
code = globalThis.utility2.jslintAutofixLocalFunction(code, file);
}
// autofix-all - remove trailing-whitespace
code = code.replace((
/\u0020+$/gm
), "");
// autofix-all - remove leading-whitespace before )]}
code = code.replace((
/\n+?(\n\u0020*?[)\]}])/g
), "$1");
// autofix-all - normalize newlines to \n\n
code = code.replace((
/([^\n])\n{3}([^\n])/g
), "$1\n\n$2");
// autofix-all - normalize newlines to \n\n\n\n
code = code.replace((
/\n{5,}/g
), "\n\n\n\n");
// autofix-all - recurse <script>...</script>, <style>...</style>
code = code.replace((
/(^\/\*\u0020jslint\u0020utility2:true\u0020\*\/\\n\\\n(?:^.*?\\n\\\n)*?)(';$|<\/script>\\n\\$|<\/style>\\n\\$)/gm
), function (ignore, match1, match2, ii) {
return local.jslintAndPrint(
code,
file + (
match2.indexOf("style") > -1
? ".<style>.css"
: ".<script>.js"
),
Object.assign({}, opt, {
fileType0: ".\\n\\",
iiEnd: ii + match1.length,
iiStart: ii,
gotoState: 0
})
) + match2;
});
}
switch (opt.autofix && opt.fileType) {
case ".css":
break;
case ".html":
// autofix-html - recurse <script>...</script>, <style>...</style>
code = code.replace((
/^(\/\*\u0020jslint\u0020utility2:true\u0020\*\/\n[\S\s]*?\n)(<\/(?:script|style)>)$/gm
), function (ignore, match1, match2, ii) {
return local.jslintAndPrint(
code,
file + (
match2.indexOf("style") >= 0
? ".<style>.css"
: ".<script>.js"
),
Object.assign({}, opt, {
fileType0: opt.fileType,
iiEnd: ii + match1.length,
iiStart: ii,
gotoState: 0
})
) + match2;
});
break;
case ".js":
case ".json":
// autofix-js - demux code to [code, ignoreList]
ignoreList = [];
code = code.replace((
/^\u0020*?\/\*\u0020jslint\u0020ignore:start\u0020\*\/$[\S\s]*?^\/\*\u0020jslint\u0020ignore:end\u0020\*\/$/gm
), function (match0) {
ignoreList.push(match0);
return "/* jslint ignore:start:end */";
});
// autofix-js - escape non-ascii
code = code.replace((
/[^\n\r\t\u0020-\u007e]/g
), function (match0) {
return "\\u" + (
"0000"
+ match0.charCodeAt(0).toString(16)
).slice(-4);
});
// autofix-js - demux code2 to [code2, ignoreList]
code2 = "";
dataList = [];
ii = 0;
rgx1 = (
/\\.|\/\*|\*\/|\/\/!!|\/\/|["'\/`]|$/gm
);
// parse rgx
// https://github.com/douglascrockford/JSLint/blob/557afd32bcaa35480d31a86f02d3a8c06a4e5b5c/jslin...
n/a
jslintGetColumnLine = function (code, ii) {
/*
* this function will transform <code> and <ii> to {column, line, evidence}
*/
let column;
let evidence;
let line;
evidence = code.slice(0, ii).split("\n");
line = evidence.length - 1;
column = evidence[line].length;
evidence = evidence[line] + code.slice(ii, ii + 100).split("\n")[0];
return {
column,
evidence,
line
};
}
n/a
jslintUtility2 = function (code, ignore, opt) {
/*
* this function will jslint <code> with utiity2-specific rules
*/
let code2;
let err;
let indent;
let previous;
// jslintUtility2 - all
if (opt.utility2) {
code2 = code;
// ignore start to end
code2 = code2.replace((
/^\/\*\u0020jslint\u0020ignore:start\u0020\*\/$[\S\s]+?^\/\*\u0020jslint\u0020ignore:end\u0020\*\/$/gm
), function (match0) {
// preserve lineno
return match0.replace((
/.+/g
), "");
});
// lint whitespace
code2.replace((
/^\u0020+?(?:\*|\/\/!!)|^\u0020+|[\r\t]/gm
), function (match0, ii) {
switch (match0.slice(-1)) {
case " ":
if (match0.length % 4 === 0) {
return "";
}
err = {
message: "non 4-space indent"
};
break;
case "\r":
err = {
message: "unexpected \\r"
};
break;
case "\t":
err = {
message: "unexpected \\t"
};
break;
default:
return "";
}
Object.assign(err, local.jslintGetColumnLine(code2, ii));
opt.errList.push({
column: err.column + 1,
evidence: JSON.stringify(err.evidence),
line: err.line + 1,
message: err.message
});
return "";
});
}
switch (opt.utility2 && opt.fileType) {
// jslintUtility2 - .css
case ".css":
// ignore comment
code2 = code2.replace((
/^\u0020*?\/\*[\S\s]*?\*\/\u0020*?$/gm
), function (match0) {
// preserve lineno
return match0.replace((
/.+/g
), "");
});
code2.replace((
/\S\u0020{2}|\u0020,|^\S.*?[,;{}]./gm
), function (match0, ii) {
switch (match0.slice(-2)) {
case " ":
err = {
colOffset: 2,
message: "unexpected multi-whitespace"
};
break;
case " ,":
err = {
colOffset: 1,
message: "unexpected whitespace before comma"
};
break;
default:
err = {
colOffset: match0.length,
message: "unexpected multiline-statement"
};
}
Object.assign(err, local.jslintGetColumnLine(code2, ii));
opt.errList.push({
column: err.column + err.colOffset,
evidence: JSON.stringify(err.evidence),
line: err.line + 1,
message: err.message
});
return "";
});
// validate line-sorted - css-selector
previous = "";
code2 = code2.replace((
/^.|[#.>]|[,}]$|\u0020\{$|\b\w/gm
), function (match0) {
switch (match0) {
case " ":
return match0;
case " {":
return "\u0001" + match0;
case "#":
return "\u0002" + match0;
case ",":
return "\u0000" + match0;
case ".":
return "\u0001" + match0;
case ">":
return "\u0003" + match0;
case "}":
return match0;
default:...
n/a
jslint_export = function ( source = "", option_object = empty(), global_array = [] ) { // hack-jslint - init lines_extra line_ignore = undefined; lines = ( Array.isArray(source) ? source : source.split( /\n|\r\n?/ ) ); lines_extra = lines.map(function () { return {}; }); try { warnings = []; option = Object.assign(empty(), option_object); anon = "anonymous"; block_stack = []; declared_globals = empty(); directive_mode = true; directives = []; early_stop = true; exports = empty(); froms = []; fudge = ( option.fudge ? 1 : 0 ); functions = []; global = { id: "(global)", body: true, context: empty(), from: 0, level: 0, line: 0, live: [], loop: 0, switch: 0, thru: 0 }; blockage = global; functionage = global; json_mode = false; mega_mode = false; module_mode = false; next_token = global; property = empty(); shebang = false; stack = []; tenure = undefined; token = global; token_nr = 0; var_mode = undefined; populate(standard, declared_globals, false); populate(global_array, declared_globals, false); Object.keys(option).forEach(function (name) { if (option[name] === true) { const allowed = allowed_option[name]; if (Array.isArray(allowed)) { populate(allowed, declared_globals, false); } } }); tokenize(source); advance(); if (json_mode) { tree = json_value(); advance("(end)"); } else { // Because browsers encourage combining of script files, the first token might // be a semicolon to defend against a missing semicolon in the preceding file. if (option.browser) { if (next_token.id === ";") { advance(";"); } } else { // If we are not in a browser, then the file form of strict pragma may be used. if ( next_token.value === "use strict" ) { advance("(string)"); advance(";"); } } tree = statements(); advance("(end)"); functionage = global; walk_statement(tree); if (warnings.length === 0) { uninitialized_and_unused(); if (!option.white) { whitage(); } } } if (!option.browser) { directives.forEach(function (comment) { if (comment.directive === "global") { warn("missing_browser", comment); } }); } early_stop = false; } catch (e) { // hack-jslint - early_stop e.early_stop = true; e.column = e.column || -1; e.line = e.line || -1; if (e.name !== "JSLintError") { warnings.push(e); } } // hack-jslint - autofix warnings = warnings.filter(function (warning) { let indent; warning.source = warning.source || ""; warning.a = warning.a || warning.source.trim(); switch (option.autofix && warning.code) { // expected_a_at_b_c: "Expected '{a}' at column {b}, not column {c}.", case "expected_a_at_b_c": // autofix indent - increment indent = warning.b - warning.c; if (indent >= 0) { lines_extra[warning.line].source_autofixed = (...
n/a
jsonStringifyOrdered = function (obj, replacer, space) {
/*
* this function will JSON.stringify <obj>,
* with object-keys sorted and circular-references removed
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax
*/
let circularSet;
let stringify;
let tmp;
stringify = function (obj) {
/*
* this function will recursively JSON.stringify obj,
* with object-keys sorted and circular-references removed
*/
// if obj is not an object or function,
// then JSON.stringify as normal
if (!(
obj
&& typeof obj === "object"
&& typeof obj.toJSON !== "function"
)) {
return JSON.stringify(obj);
}
// ignore circular-reference
if (circularSet.has(obj)) {
return;
}
circularSet.add(obj);
// if obj is an array, then recurse items
if (Array.isArray(obj)) {
tmp = "[" + obj.map(function (obj) {
// recurse
tmp = stringify(obj);
return (
typeof tmp === "string"
? tmp
: "null"
);
}).join(",") + "]";
circularSet.delete(obj);
return tmp;
}
// if obj is not an array,
// then recurse its items with object-keys sorted
tmp = "{" + Object.keys(obj).sort().map(function (key) {
// recurse
tmp = stringify(obj[key]);
if (typeof tmp === "string") {
return JSON.stringify(key) + ":" + tmp;
}
}).filter(function (obj) {
return typeof obj === "string";
}).join(",") + "}";
circularSet.delete(obj);
return tmp;
};
circularSet = new Set();
return JSON.stringify((
(typeof obj === "object" && obj)
// recurse
? JSON.parse(stringify(obj))
: obj
), replacer, space);
}
n/a
nop = function () {
/*
* this function will do nothing
*/
return;
}
n/a
objectAssignDefault = function (tgt = {}, src = {}, depth = 0) {
/*
* this function will if items from <tgt> are null, undefined, or "",
* then overwrite them with items from <src>
*/
let recurse;
recurse = function (tgt, src, depth) {
Object.entries(src).forEach(function ([
key, bb
]) {
let aa;
aa = tgt[key];
if (aa === undefined || aa === null || aa === "") {
tgt[key] = bb;
return;
}
if (
depth !== 0
&& typeof aa === "object" && aa && !Array.isArray(aa)
&& typeof bb === "object" && bb && !Array.isArray(bb)
) {
recurse(aa, bb, depth - 1);
}
});
};
recurse(tgt, src, depth | 0);
return tgt;
}
...
}).join(" ").replace((
/\u001b\[\d*m/g
), "") + "\n";
// scroll textarea to bottom
elem.scrollTop = elem.scrollHeight;
};
});
local.objectAssignDefault(local, globalThis.domOnEventDelegateDict);
globalThis.domOnEventDelegateDict = local;
}());
// run node js-env code - init-test
(function () {
...
onErrorWithStack = function (onError) {
/*
* this function will wrap <onError> with wrapper preserving current-stack
*/
let onError2;
let stack;
stack = new Error().stack;
onError2 = function (err, data, meta) {
// append current-stack to err.stack
if (
err
&& typeof err.stack === "string"
&& err !== local.errorDefault
) {
err.stack += "\n" + stack;
}
onError(err, data, meta);
};
// debug onError
onError2.toString = function () {
return String(onError);
};
return onError2;
}
...
local.onParallel = function (onError, onEach, onRetry) {
/*
* this function will create a function that will
* 1. run async tasks in parallel
* 2. if cnt === 0 or err occurred, then call onError(err)
*/
let onParallel;
onError = local.onErrorWithStack(onError);
onEach = onEach || local.nop;
onRetry = onRetry || local.nop;
onParallel = function (err, data) {
if (onRetry(err, data)) {
return;
}
// decrement cnt
...
onParallel = function (onError, onEach, onRetry) {
/*
* this function will create a function that will
* 1. run async tasks in parallel
* 2. if cnt === 0 or err occurred, then call onError(err)
*/
let onParallel;
onError = local.onErrorWithStack(onError);
onEach = onEach || local.nop;
onRetry = onRetry || local.nop;
onParallel = function (err, data) {
if (onRetry(err, data)) {
return;
}
// decrement cnt
onParallel.cnt -= 1;
// validate cnt
if (!(onParallel.cnt >= 0 || err || onParallel.err)) {
err = new Error(
"invalid onParallel.cnt = " + onParallel.cnt
);
// ensure onError is run only once
} else if (onParallel.cnt < 0) {
return;
}
// handle err
if (err) {
onParallel.err = err;
// ensure cnt <= 0
onParallel.cnt = -Math.abs(onParallel.cnt);
}
// call onError when isDone
if (onParallel.cnt <= 0) {
onError(err, data);
return;
}
onEach();
};
// init cnt
onParallel.cnt = 0;
// return callback
return onParallel;
}
n/a
function Reporter(lines, ruleset, allow, ignore) {
"use strict";
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
/**
* Lines with specific rule messages to leave out of the report.
* @property allow
* @type Object
*/
this.allow = allow;
if (!this.allow) {
this.allow = {};
}
/**
* Linesets not to include in the report.
* @property ignore
* @type [][]
*/
this.ignore = ignore;
if (!this.ignore) {
this.ignore = [];
}
}
n/a
function(formatter) { // formatters.push(formatter); formatters[formatter.id] = formatter; }
n/a
function(rule) { rules.push(rule); rules[rule.id] = rule; }
n/a
function() { rules = []; }
n/a
function(results, filename, formatId, options) { var formatter = api.getFormatter(formatId), result = null; if (formatter) { result = formatter.startFormat(); result += formatter.formatResults(results, filename, options || {}); result += formatter.endFormat(); } return result; }
n/a
function(formatId) { return formatters[formatId]; }
n/a
function() { return [].concat(rules).sort(function(a, b) { return a.id > b.id ? 1 : 0; }); }
n/a
function() { var ruleset = {}, i = 0, len = rules.length; while (i < len) { ruleset[rules[i++].id] = 1; // by default, everything is a warning } return ruleset; }
n/a
function(formatId) { return formatters.hasOwnProperty(formatId); }
n/a
function(text, ruleset) { var i = 0, reporter, lines, allow = {}, ignore = [], report, parser = new parserlib.css.Parser({ starHack: true, ieFilters: true, underscoreHack: true, strict: false }); // normalize line endings lines = text.replace(/\n\r?/g, "$split$").split("$split$"); // find 'allow' comments CSSLint.Util.forEach(lines, function (line, lineno) { var allowLine = line && line.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i), allowRules = allowLine && allowLine[1], allowRuleset = {}; if (allowRules) { allowRules.toLowerCase().split(",").forEach(function(allowRule) { allowRuleset[allowRule.trim()] = true; }); if (Object.keys(allowRuleset).length > 0) { allow[lineno + 1] = allowRuleset; } } }); var ignoreStart = null, ignoreEnd = null; CSSLint.Util.forEach(lines, function (line, lineno) { // Keep oldest, "unclosest" ignore:start if (ignoreStart === null && line.match(/\/\*[ \t]*csslint[ \t]+ignore:start[ \t]*\*\//i)) { ignoreStart = lineno; } if (line.match(/\/\*[ \t]*csslint[ \t]+ignore:end[ \t]*\*\//i)) { ignoreEnd = lineno; } if (ignoreStart !== null && ignoreEnd !== null) { ignore.push([ignoreStart, ignoreEnd]); ignoreStart = ignoreEnd = null; } }); // Close remaining ignore block, if any if (ignoreStart !== null) { ignore.push([ignoreStart, lines.length]); } if (!ruleset) { ruleset = api.getRuleset(); } if (embeddedRuleset.test(text)) { // defensively copy so that caller's version does not get modified ruleset = clone(ruleset); ruleset = applyEmbeddedRuleset(text, ruleset); } reporter = new Reporter(lines, ruleset, allow, ignore); ruleset.errors = 2; // always report parsing errors as errors for (i in ruleset) { if (ruleset.hasOwnProperty(i) && ruleset[i]) { if (rules[i]) { rules[i].init(parser, reporter); } } } // capture most horrible error type try { parser.parse(text); } catch (ex) { reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {}); } report = { messages : reporter.messages, stats : reporter.stats, ruleset : reporter.ruleset, allow : reporter.allow, ignore : reporter.ignore }; // sort by line numbers, rollups at the bottom report.messages.sort(function (a, b) { if (a.rollup && !b.rollup) { return 1; } else if (!a.rollup && b.rollup) { return -1; } else { return a.line - b.line; } }); return report; }
n/a
function(values, func) { "use strict"; if (values.forEach) { return values.forEach(func); } else { for (var i=0, len=values.length; i < len; i++) { func(values[i], i, values); } } }
...
local.objectAssignDefault = function (tgt = {}, src = {}, depth = 0) {
/*
* this function will if items from <tgt> are null, undefined, or "",
* then overwrite them with items from <src>
*/
let recurse;
recurse = function (tgt, src, depth) {
Object.entries(src).forEach(function ([
key, bb
]) {
let aa;
aa = tgt[key];
if (aa === undefined || aa === null || aa === "") {
tgt[key] = bb;
return;
...
function(values, value) { "use strict"; if (values.indexOf) { return values.indexOf(value); } else { for (var i=0, len=values.length; i < len; i++) { if (values[i] === value) { return i; } } return -1; } }
...
":after": 1
};
Pseudos.ELEMENT = 1;
Pseudos.CLASS = 2;
Pseudos.isElement = function(pseudo) {
return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] ===
Pseudos.ELEMENT;
};
},{}],13:[function(require,module,exports){
"use strict";
module.exports = Selector;
var SyntaxUnit = require("../util/SyntaxUnit");
...
function(receiver, supplier) { "use strict"; var prop; for (prop in supplier) { if (supplier.hasOwnProperty(prop)) { receiver[prop] = supplier[prop]; } } return prop; }
n/a
function Reporter(lines, ruleset, allow, ignore) {
"use strict";
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
/**
* Lines with specific rule messages to leave out of the report.
* @property allow
* @type Object
*/
this.allow = allow;
if (!this.allow) {
this.allow = {};
}
/**
* Linesets not to include in the report.
* @property ignore
* @type [][]
*/
this.ignore = ignore;
if (!this.ignore) {
this.ignore = [];
}
}
n/a
function Reporter(lines, ruleset, allow, ignore) {
"use strict";
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
/**
* Lines with specific rule messages to leave out of the report.
* @property allow
* @type Object
*/
this.allow = allow;
if (!this.allow) {
this.allow = {};
}
/**
* Linesets not to include in the report.
* @property ignore
* @type [][]
*/
this.ignore = ignore;
if (!this.ignore) {
this.ignore = [];
}
}
n/a
function(message, line, col, rule) { "use strict"; this.messages.push({ type : "error", line : line, col : col, message : message, evidence: this.lines[line-1], rule : rule || {} }); }
...
recursive: true
});
// re-write pathname
fs.writeFileSync(pathname, data);
success = true;
}
if (success && msg) {
console.error(msg.replace("{{pathname}}", pathname));
}
return success;
};
local.identity = function (val) {
/*
* this function will return <val>
*/
...
function(message, line, col, rule) { "use strict"; this.messages.push({ type : "info", line : line, col : col, message : message, evidence: this.lines[line-1], rule : rule }); }
n/a
function(message, line, col, rule) { "use strict"; // Check if rule violation should be allowed if (this.allow.hasOwnProperty(line) && this.allow[line].hasOwnProperty(rule.id)) { return; } var ignore = false; CSSLint.Util.forEach(this.ignore, function (range) { if (range[0] <= line && line <= range[1]) { ignore = true; } }); if (ignore) { return; } this.messages.push({ type : this.ruleset[rule.id] === 2 ? "error" : "warning", line : line, col : col, message : message, evidence: this.lines[line-1], rule : rule }); }
n/a
function(message, rule) { "use strict"; this.messages.push({ type : "error", rollup : true, message : message, rule : rule }); }
n/a
function(message, rule) { "use strict"; this.messages.push({ type : "warning", rollup : true, message : message, rule : rule }); }
n/a
function(name, value) { "use strict"; this.stats[name] = value; }
n/a
function(message, line, col, rule) { "use strict"; this.report(message, line, col, rule); }
n/a
_default = function () {
/*
* <file1> <file2> ...
* will jslint <file1> <file2> ... and print errors to stderr
*/
// jslint files
process.argv.slice(2).forEach(function (file) {
if (file[0] === "-") {
return;
}
local.jslintAndPrint(
local.fs.readFileSync(local.path.resolve(file), "utf8"),
file,
{
autofix: process.argv.indexOf("--autofix") >= 0,
conditional: process.argv.indexOf("--conditional") >= 0
}
);
});
// if err occurred, then exit with non-zero code
process.exit(Boolean(local.jslintResult.errList.length));
}
...
local.cliDict._help();
return;
}
if (local.cliDict[process.argv[2]]) {
local.cliDict[process.argv[2]]();
return;
}
local.cliDict._default();
};
local.jsonStringifyOrdered = function (obj, replacer, space) {
/*
* this function will JSON.stringify <obj>,
* with object-keys sorted and circular-references removed
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax
...
dir = function () {
/*
* <dir>
* will jslint files in shallow <dir>
*/
local.jslintAndPrintDir(process.argv[3], {
autofix: process.argv.indexOf("--autofix") >= 0,
conditional: process.argv.indexOf("--conditional") >= 0
}, process.exit);
}
n/a