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 assertJsonEqual(aa, bb) {
/*
* this function will assert JSON.stringify(<aa>) === JSON.stringify(<bb>)
*/
aa = JSON.stringify(objectDeepCopyWithKeysSorted(aa));
bb = JSON.stringify(objectDeepCopyWithKeysSorted(bb));
if (aa !== bb) {
throw new Error(JSON.stringify(aa) + " !== " + JSON.stringify(bb));
}
}
...
"utility2.testRunMock.process.exit"
), resolve, {
once: true
});
})
]).then(function (errList) {
errList.forEach(function (err, ii) {
local.assertJsonEqual(Boolean(err) | 0, ii);
});
onError();
});
};
local.testCase_jslintAndPrint_coverage = function (opt, onError) {
/*
...
function assertOrThrow(passed, msg) {
/*
* this function will throw <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 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>
*/
let cliDict;
cliDict = local.cliDict;
cliDict._eval = cliDict._eval || function () {
/*
* <code>
* will eval <code>
*/
globalThis.local = local;
require("vm").runInThisContext(process.argv[3]);
};
cliDict._help = 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(cliDict).sort().forEach(function (key, ii) {
if (key[0] === "_" && key !== "_default") {
return;
}
str = String(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...
n/a
function coalesce(...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 !== undefined && arg !== null && arg !== "") {
return arg;
}
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(
...
function identity(val) {
/*
* this function will return <val>
*/
return val;
}
...
cliDict.help = cliDict.help || cliDict._help;
cliDict._interactive = cliDict._interactive || function () {
/*
*
* will start interactive-mode
*/
globalThis.local = local;
local.identity(local.replStart || require("repl").start)({
useGlobal: true
});
};
cliDict["--interactive"] = cliDict["--interactive"] || cliDict._interactive;
cliDict["-i"] = cliDict["-i"] || cliDict._interactive;
cliDict._version = cliDict._version || function () {
/*
...
jslint0 = 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; // hack-jslint - throw_error if (option.throw_error) { throw new Error(); } } 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 aa; let bb; let tmp; if (!lines_extra[warning.line]) { return true; } aa = lines_extra[warning.line].source; warning.a = warning.a || aa.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&quo...
...
(function () {
local.testCase_jslint0_coverage = function (opt, onError) {
/*
* this function will test jslintAndPrint's coverage handling-behavior
*/
// jslint self
if (!local.isBrowser) {
local.jslint0(require("fs").readFileSync(__filename, "utf8"
;));
local.jslint0(require("fs").readFileSync("lib.jslint.js", "utf8"));
local.jslint0(require("fs").readFileSync(
"lib.jslint.js",
"utf8"
).replace((
/[\S\s]*?\n\/\/\u0020jslint\.js/
), "").replace((
...
jslintAndPrint = function (code, file = "undefined", opt = {}) {
/*
* this function will jslint-autofix <code>
*/
return jslintRecurse(code, file, opt, {});
}
...
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 <dir>
*/
let errCnt;
errCnt = 0;
onError = onError || function (err) {
process.exit(Math.min((err && err.message) | 0, 127));
};
dir = require("path").resolve(dir) + require("path").sep;
require("fs").readdir(dir, function (err, fileList) {
local.onErrorThrow(err);
Promise.all(fileList.map(function (file) {
return new Promise(function (resolve) {
let timeStart;
timeStart = Date.now();
file = dir + 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)) {
resolve();
return;
}
// jslint file
require("fs").readFile(file, "utf8", function (err, data) {
if (err) {
return;
}
local.jslintAndPrint(data, file, opt);
errCnt += local.jslintResult.errList.length;
console.error(
"jslint - " + (Date.now() - timeStart) + "ms - "
+ file
);
resolve();
});
return;
}
resolve();
});
})).then(function () {
onError(errCnt && new Error(errCnt));
});
});
}
...
*/
if (local.isBrowser) {
onError(undefined, opt);
return;
}
Promise.all([
new Promise(function (resolve) {
local.jslintAndPrintDir(".", {
autofix: true,
conditional: true
}, resolve);
}),
new Promise(function (resolve) {
local.jslintAndPrintDir("jslintAndPrintDir", {
autofix: true,
...
function nop() {
/*
* this function will do nothing
*/
return;
}
n/a
function objectAssignDefault(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;
}());
/* istanbul ignore next */
// run node js-env code - init-test
(function () {
...
function objectDeepCopyWithKeysSorted(obj) {
/*
* this function will recursively deep-copy <obj> with keys sorted
*/
let sorted;
if (typeof obj !== "object" || !obj) {
return obj;
}
// recursively deep-copy list with child-keys sorted
if (Array.isArray(obj)) {
return obj.map(objectDeepCopyWithKeysSorted);
}
// recursively deep-copy obj with keys sorted
sorted = {};
Object.keys(obj).sort().forEach(function (key) {
sorted[key] = objectDeepCopyWithKeysSorted(obj[key]);
});
return sorted;
}
n/a
function onErrorThrow(err) {
/*
* this function will throw <err> if exists
*/
if (err) {
throw err;
}
}
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); } } }
...
}
// recursively deep-copy list with child-keys sorted
if (Array.isArray(obj)) {
return obj.map(objectDeepCopyWithKeysSorted);
}
// recursively deep-copy obj with keys sorted
sorted = {};
Object.keys(obj).sort().forEach(function (key) {
sorted[key] = objectDeepCopyWithKeysSorted(obj[key]);
});
return sorted;
}
function assertJsonEqual(aa, bb) {
/*
* this function will assert JSON.stringify(<aa>) === JSON.stringify(<bb>)
...
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 || {} }); }
...
window.domOnEventWindowOnloadTimeElapsed = Date.now() + 100;\n\
window.addEventListener("load", function () {\n\
setTimeout(function () {\n\
window.domOnEventWindowOnloadTimeElapsed = (\n\
Date.now()\n\
- window.domOnEventWindowOnloadTimeElapsed\n\
);\n\
console.error(\n\
"domOnEventWindowOnloadTimeElapsed = "\n\
+ window.domOnEventWindowOnloadTimeElapsed\n\
);\n\
}, 100);\n\
});\n\
}());\n\
\n\
...
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(
require("fs").readFileSync(require("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));
}
...
cliDict._help();
return;
}
if (cliDict[process.argv[2]]) {
cliDict[process.argv[2]]();
return;
}
cliDict._default();
};
}());
// run shared js-env code - function
(function () {
/* jslint ignore:start */
...
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
});
}
n/a