Replaced jsHint with eslint. Fixes #4.

This commit is contained in:
n1474335 2016-12-14 16:39:17 +00:00
parent e2e68dd876
commit af4644c9eb
48 changed files with 1741 additions and 1685 deletions

View file

@ -10,7 +10,7 @@
* @namespace
*/
var Code = {
/**
* @constant
* @default
@ -21,7 +21,7 @@ var Code = {
* @default
*/
LINE_NUMS: false,
/**
* Syntax highlighter operation.
*
@ -34,14 +34,14 @@ var Code = {
line_nums = args[1];
return "<code class='prettyprint'>" + prettyPrintOne(Utils.escape_html(input), language, line_nums) + "</code>";
},
/**
* @constant
* @default
*/
BEAUTIFY_INDENT: "\\t",
/**
* XML Beautify operation.
*
@ -53,8 +53,8 @@ var Code = {
var indent_str = args[0];
return vkbeautify.xml(input, indent_str);
},
/**
* JSON Beautify operation.
*
@ -67,8 +67,8 @@ var Code = {
if (!input) return "";
return vkbeautify.json(input, indent_str);
},
/**
* CSS Beautify operation.
*
@ -80,8 +80,8 @@ var Code = {
var indent_str = args[0];
return vkbeautify.css(input, indent_str);
},
/**
* SQL Beautify operation.
*
@ -93,14 +93,14 @@ var Code = {
var indent_str = args[0];
return vkbeautify.sql(input, indent_str);
},
/**
* @constant
* @default
*/
PRESERVE_COMMENTS: false,
/**
* XML Minify operation.
*
@ -112,8 +112,8 @@ var Code = {
var preserve_comments = args[0];
return vkbeautify.xmlmin(input, preserve_comments);
},
/**
* JSON Minify operation.
*
@ -125,8 +125,8 @@ var Code = {
if (!input) return "";
return vkbeautify.jsonmin(input);
},
/**
* CSS Minify operation.
*
@ -138,8 +138,8 @@ var Code = {
var preserve_comments = args[0];
return vkbeautify.cssmin(input, preserve_comments);
},
/**
* SQL Minify operation.
*
@ -150,8 +150,8 @@ var Code = {
run_sql_minify: function(input, args) {
return vkbeautify.sqlmin(input);
},
/**
* Generic Code Beautify operation.
*
@ -160,10 +160,10 @@ var Code = {
* I'm not proud of this code, but seriously, try writing a generic lexer and parser that
* correctly generates an AST for multiple different languages. I have tried, and I can tell
* you it's pretty much impossible.
*
*
* This basically works. That'll have to be good enough. It's not meant to produce working code,
* just slightly more readable code.
*
*
* Things that don't work:
* - For loop formatting
* - Do-While loop formatting
@ -180,66 +180,66 @@ var Code = {
t = 0,
preserved_tokens = [],
m;
// Remove strings
var sstrings = /'([^'\\]|\\.)*'/g;
while (!!(m = sstrings.exec(code))) {
while ((m = sstrings.exec(code))) {
code = preserve_token(code, m, t++);
sstrings.lastIndex = m.index;
}
var dstrings = /"([^"\\]|\\.)*"/g;
while (!!(m = dstrings.exec(code))) {
while ((m = dstrings.exec(code))) {
code = preserve_token(code, m, t++);
dstrings.lastIndex = m.index;
}
// Remove comments
var scomments = /\/\/[^\n\r]*/g;
while (!!(m = scomments.exec(code))) {
while ((m = scomments.exec(code))) {
code = preserve_token(code, m, t++);
scomments.lastIndex = m.index;
}
var mcomments = /\/\*[\s\S]*?\*\//gm;
while (!!(m = mcomments.exec(code))) {
while ((m = mcomments.exec(code))) {
code = preserve_token(code, m, t++);
mcomments.lastIndex = m.index;
}
var hcomments = /(^|\n)#[^\n\r#]+/g;
while (!!(m = hcomments.exec(code))) {
while ((m = hcomments.exec(code))) {
code = preserve_token(code, m, t++);
hcomments.lastIndex = m.index;
}
// Remove regexes
var regexes = /\/.*?[^\\]\/[gim]{0,3}/gi;
while (!!(m = regexes.exec(code))) {
while ((m = regexes.exec(code))) {
code = preserve_token(code, m, t++);
regexes.lastIndex = m.index;
}
// Create newlines after ;
code = code.replace(/;/g, ";\n");
// Create newlines after { and around }
code = code.replace(/{/g, "{\n");
code = code.replace(/}/g, "\n}\n");
// Remove carriage returns
code = code.replace(/\r/g, "");
// Remove all indentation
code = code.replace(/^\s+/g, "");
code = code.replace(/\n\s+/g, "\n");
// Remove trailing spaces
code = code.replace(/\s*$/g, "");
// Remove newlines before {
code = code.replace(/\n{/g, "{");
// Indent
var i = 0,
level = 0;
@ -250,10 +250,10 @@ var Code = {
break;
case "\n":
if (i+1 >= code.length) break;
if (code[i+1] == "}") level--;
if (code[i+1] === "}") level--;
var indent = (level >= 0) ? Array(level*4+1).join(" ") : "";
code = code.substring(0, i+1) + indent + code.substring(i+1);
if (level > 0) i += level*4;
break;
@ -272,30 +272,30 @@ var Code = {
code = code.replace(/\s*,\s*/g, ", ");
code = code.replace(/\s*{/g, " {");
code = code.replace(/}\n/g, "}\n\n");
// Just... don't look at this
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3");
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3");
code = code.replace(/else\s*\n([^{])/gim, "else\n $1");
code = code.replace(/else\s+([^{])/gim, "else $1");
// Remove strategic spaces
code = code.replace(/\s+;/g, ";");
code = code.replace(/\{\s+\}/g, "{}");
code = code.replace(/\[\s+\]/g, "[]");
code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
// Replace preserved tokens
var ptokens = /###preserved_token(\d+)###/g;
while (!!(m = ptokens.exec(code))) {
var ti = parseInt(m[1]);
while ((m = ptokens.exec(code))) {
var ti = parseInt(m[1], 10);
code = code.substring(0, m.index) + preserved_tokens[ti] + code.substring(m.index + m[0].length);
ptokens.lastIndex = m.index;
}
return code;
function preserve_token(str, match, t) {
preserved_tokens[t] = match[0];
return str.substring(0, match.index) +