From 398d7f7fe706b3b2680afa9907a7ab6623f6a3f5 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Sat, 10 Aug 2024 12:43:26 +0800 Subject: [PATCH] lint: useless ai generated comments --- core/modules/parsers/wikiparser/rules/dash.js | 3 +-- core/modules/parsers/wikiparser/rules/emphasis/bold.js | 8 +------- .../parsers/wikiparser/rules/emphasis/italic.js | 8 +------- .../parsers/wikiparser/rules/emphasis/strikethrough.js | 8 +------- .../parsers/wikiparser/rules/emphasis/subscript.js | 8 +------- .../parsers/wikiparser/rules/emphasis/superscript.js | 8 +------- .../parsers/wikiparser/rules/emphasis/underscore.js | 8 +------- core/modules/parsers/wikiparser/rules/entity.js | 1 - .../modules/parsers/wikiparser/rules/hardlinebreaks.js | 5 ++--- core/modules/parsers/wikiparser/rules/html.js | 10 +++++----- core/modules/parsers/wikiparser/rules/import.js | 3 +-- .../modules/parsers/wikiparser/rules/macrocallblock.js | 6 +++--- core/modules/parsers/wikiparser/rules/macrodef.js | 4 ---- core/modules/parsers/wikiparser/rules/parameters.js | 2 -- core/modules/parsers/wikiparser/rules/prettyextlink.js | 3 --- core/modules/parsers/wikiparser/rules/prettylink.js | 3 --- core/modules/parsers/wikiparser/rules/syslink.js | 4 +--- .../parsers/wikiparser/rules/transcludeblock.js | 2 -- core/modules/parsers/wikiparser/rules/typedblock.js | 2 +- core/modules/parsers/wikiparser/rules/wikilink.js | 1 - 20 files changed, 20 insertions(+), 77 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/dash.js b/core/modules/parsers/wikiparser/rules/dash.js index 60c82f0a7..4d06a54cd 100644 --- a/core/modules/parsers/wikiparser/rules/dash.js +++ b/core/modules/parsers/wikiparser/rules/dash.js @@ -38,8 +38,7 @@ exports.parse = function() { }; exports.serialize = function(tree) { - var dash = tree.entity === "–" ? "--" : "---"; - return dash; + return tree.entity === "–" ? "--" : "---"; }; })(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/bold.js b/core/modules/parsers/wikiparser/rules/emphasis/bold.js index 6294094ec..bcd55f556 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/bold.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/bold.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = "''"; - // Serialize the children of the bold element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += "''"; - // Return the complete serialized string - return serialized; + return "''" + serialize(tree.children) + "''"; }; })(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/italic.js b/core/modules/parsers/wikiparser/rules/emphasis/italic.js index f1070ddfb..88be5617a 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/italic.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/italic.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = "//"; - // Serialize the children of the italic element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += "//"; - // Return the complete serialized string - return serialized; + return "//" + serialize(tree.children) + "//"; }; })(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js b/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js index ccd511c42..d42ac62b3 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = "~~"; - // Serialize the children of the strikethrough element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += "~~"; - // Return the complete serialized string - return serialized; + return "~~" + serialize(tree.children) + "~~"; }; })(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/subscript.js b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js index d38d51222..b49598934 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/subscript.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = ",,"; - // Serialize the children of the subscript element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += ",,"; - // Return the complete serialized string - return serialized; + return ",," + serialize(tree.children) + ",,"; }; })(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/superscript.js b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js index 82a4b78d6..a843aec5d 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/superscript.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = "^^"; - // Serialize the children of the superscript element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += "^^"; - // Return the complete serialized string - return serialized; + return "^^" + serialize(tree.children) + "^^"; }; })(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/underscore.js b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js index b07f32fc2..4d223185a 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/underscore.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js @@ -48,13 +48,7 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - var serialized = "__"; - // Serialize the children of the underscore element - serialized += serialize(tree.children); - // Close the serialized string with the closing delimiter - serialized += "__"; - // Return the complete serialized string - return serialized; + return "__" + serialize(tree.children) + "__"; }; })(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/entity.js b/core/modules/parsers/wikiparser/rules/entity.js index 7f15c8a95..10e288990 100644 --- a/core/modules/parsers/wikiparser/rules/entity.js +++ b/core/modules/parsers/wikiparser/rules/entity.js @@ -37,7 +37,6 @@ exports.parse = function() { return [{type: "entity", entity: this.match[0]}]; }; -// Serialize method for the entity rule exports.serialize = function(tree, serialize) { return tree.entity; }; diff --git a/core/modules/parsers/wikiparser/rules/hardlinebreaks.js b/core/modules/parsers/wikiparser/rules/hardlinebreaks.js index 9f26c3d95..ae290ef29 100644 --- a/core/modules/parsers/wikiparser/rules/hardlinebreaks.js +++ b/core/modules/parsers/wikiparser/rules/hardlinebreaks.js @@ -60,15 +60,14 @@ exports.parse = function() { }; exports.serialize = function(tree,serialize) { - // we get each of element on tree from `parse` one by one here. - var text = tree.tag === 'br' ? '\n' : tree.text; + var text = tree.tag === "br" ? "\n" : (tree.text || ""); if(tree.isRuleStart) { return '"""\n' + text; } if(tree.isRuleEnd) { return text + '"""'; } - return text; + return text + serialize(tree.children); }; })(); diff --git a/core/modules/parsers/wikiparser/rules/html.js b/core/modules/parsers/wikiparser/rules/html.js index 1e3f9865b..df52819e2 100644 --- a/core/modules/parsers/wikiparser/rules/html.js +++ b/core/modules/parsers/wikiparser/rules/html.js @@ -66,7 +66,7 @@ exports.parse = function() { } tag.end = this.parser.pos; tag.closeTagEnd = tag.end; - if(tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== '>') { + if(tag.closeTagEnd === tag.openTagEnd || this.parser.source[tag.closeTagEnd - 1] !== ">") { tag.closeTagStart = tag.end; } else { tag.closeTagStart = tag.closeTagEnd - 2; @@ -74,11 +74,11 @@ exports.parse = function() { if(!Number.isSafeInteger(closeTagMinPos)) closeTagMinPos = tag.openTagEnd; while(tag.closeTagStart >= closeTagMinPos) { var char = this.parser.source[tag.closeTagStart]; - if(char === '>') { + if(char === ">") { tag.closeTagStart = -1; break; } - if(char === '<') break; + if(char === "<") break; tag.closeTagStart -= 1; } if(tag.closeTagStart < closeTagMinPos) { @@ -199,9 +199,9 @@ exports.serialize = function(tree, serialize) { var tag = tree.tag; var attributes = Object.keys(tree.attributes).map(function(key) { return key + '="' + tree.attributes[key].value + '"'; - }).join(''); + }).join(""); // Children - var children = tree.children ? serialize(tree.children) : ''; + var children = tree.children ? serialize(tree.children) : ""; // Self-closing tag if(tree.isSelfClosing) { return "<" + tag + (attributes ? " " + attributes : "") + " />"; diff --git a/core/modules/parsers/wikiparser/rules/import.js b/core/modules/parsers/wikiparser/rules/import.js index 2142f7a58..3cfcad5d7 100644 --- a/core/modules/parsers/wikiparser/rules/import.js +++ b/core/modules/parsers/wikiparser/rules/import.js @@ -52,9 +52,8 @@ exports.parse = function() { }; exports.serialize = function(tree,serialize) { - // Filter attribute var filter = tree.attributes.filter.value; - // Construct the serialized string with children that is actually the sibling below the pragma. + // Sibling below the pragma become children, so we append the serialized children to the end.. return "\\import " + filter + "\n" + serialize(tree.children); }; diff --git a/core/modules/parsers/wikiparser/rules/macrocallblock.js b/core/modules/parsers/wikiparser/rules/macrocallblock.js index 923484bae..1572cce63 100644 --- a/core/modules/parsers/wikiparser/rules/macrocallblock.js +++ b/core/modules/parsers/wikiparser/rules/macrocallblock.js @@ -57,16 +57,16 @@ exports.parse = function() { Serialize a macro call node to wikitext */ exports.serialize = function (node) { - // Start with macro opener var result = "<<"; + // Macro name if(node.attributes && node.attributes["$variable"]) { - result += node.attributes["$variable"].value; // Add macro name + result += node.attributes["$variable"].value; } // Append ordered arguments if any if(node.orderedAttributes) { node.orderedAttributes.forEach(function (attr) { if(attr.name !== "$variable") { - result += " " + '"' + attr.value + '"'; // Add each additional value + result += " " + '"' + attr.value + '"'; } }); } diff --git a/core/modules/parsers/wikiparser/rules/macrodef.js b/core/modules/parsers/wikiparser/rules/macrodef.js index 9dec07682..be000eab0 100644 --- a/core/modules/parsers/wikiparser/rules/macrodef.js +++ b/core/modules/parsers/wikiparser/rules/macrodef.js @@ -90,15 +90,11 @@ exports.parse = function() { }; exports.serialize = function(tree,serialize) { - // Macro name var name = tree.attributes.name.value; - // Parameters var params = tree.params.map(function(param) { return param.name + (param.default ? ":" + param.default : ""); }).join(","); - // Definition text var definition = tree.attributes.value.value; - // Construct the serialized string return "\\define " + name + "(" + params + ")\n" + definition + "\n\\end\n\n" + serialize(tree.children); }; diff --git a/core/modules/parsers/wikiparser/rules/parameters.js b/core/modules/parsers/wikiparser/rules/parameters.js index 6be51c24b..a214164ca 100644 --- a/core/modules/parsers/wikiparser/rules/parameters.js +++ b/core/modules/parsers/wikiparser/rules/parameters.js @@ -58,11 +58,9 @@ exports.parse = function() { }; exports.serialize = function(tree,serialize) { - // Parameters var params = tree.orderedAttributes.map(function(param) { return param.name + (param.value ? ":" + param.value : ""); }).join(","); - // Construct the serialized string return "\\parameters(" + params + ")\n\n" + serialize(tree.children); }; diff --git a/core/modules/parsers/wikiparser/rules/prettyextlink.js b/core/modules/parsers/wikiparser/rules/prettyextlink.js index e2cc48a7e..f56ee8fe0 100644 --- a/core/modules/parsers/wikiparser/rules/prettyextlink.js +++ b/core/modules/parsers/wikiparser/rules/prettyextlink.js @@ -118,11 +118,8 @@ exports.parseLink = function(source,pos) { }; exports.serialize = function(tree) { - // Tooltip text var tooltip = tree.children[0].text; - // URL var url = tree.attributes.href.value; - // Construct the serialized string return "[ext[" + (tooltip !== url ? tooltip + "|" : "") + url + "]]"; }; diff --git a/core/modules/parsers/wikiparser/rules/prettylink.js b/core/modules/parsers/wikiparser/rules/prettylink.js index 74a275e42..0b798a5dc 100644 --- a/core/modules/parsers/wikiparser/rules/prettylink.js +++ b/core/modules/parsers/wikiparser/rules/prettylink.js @@ -68,11 +68,8 @@ exports.parse = function() { }; exports.serialize = function(tree) { - // Link text var text = tree.children[0].text; - // Link target var target = tree.attributes.to ? tree.attributes.to.value : tree.attributes.href.value; - // Construct the serialized string return "[[" + text + (text !== target ? "|" + target : "") + "]]"; }; diff --git a/core/modules/parsers/wikiparser/rules/syslink.js b/core/modules/parsers/wikiparser/rules/syslink.js index 0839e9087..e5387e5ee 100644 --- a/core/modules/parsers/wikiparser/rules/syslink.js +++ b/core/modules/parsers/wikiparser/rules/syslink.js @@ -53,11 +53,9 @@ exports.parse = function() { exports.serialize = function(tree, serialize) { // Check if the link is suppressed var isSuppressed = tree.children[0].text.substr(0,1) === "~"; - var serialized = isSuppressed ? "~" : ""; - // Append the link value + // Append the link text serialized += tree.attributes.to.value; - // Return the complete serialized string return serialized; }; diff --git a/core/modules/parsers/wikiparser/rules/transcludeblock.js b/core/modules/parsers/wikiparser/rules/transcludeblock.js index 88519e84d..319726f0a 100644 --- a/core/modules/parsers/wikiparser/rules/transcludeblock.js +++ b/core/modules/parsers/wikiparser/rules/transcludeblock.js @@ -130,9 +130,7 @@ exports.serialize = function(tree, serialize) { } else if(tree.type === "transclude") { handleTransclude(tree); } - // Close the result string result += "}}\n\n"; - // Return the complete result string return result; }; diff --git a/core/modules/parsers/wikiparser/rules/typedblock.js b/core/modules/parsers/wikiparser/rules/typedblock.js index 68d534830..38985daaa 100644 --- a/core/modules/parsers/wikiparser/rules/typedblock.js +++ b/core/modules/parsers/wikiparser/rules/typedblock.js @@ -78,6 +78,7 @@ exports.parse = function() { container = $tw.fakeDocument.createElement("div"); widgetNode.render(container,null); var renderResult = renderType === "text/html" ? container.innerHTML : container.textContent; + // Use void node to carry important info for typedblock return [{ type: "void", children: [{ @@ -99,7 +100,6 @@ exports.parse = function() { exports.serialize = function (tree, serialize) { if(tree.type === "void") { - // Directly process the tree's text content return "$$$" + tree.parseType + (tree.renderType ? " > " + tree.renderType : "") + "\n" + tree.text + "\n$$$\n\n"; } return ""; diff --git a/core/modules/parsers/wikiparser/rules/wikilink.js b/core/modules/parsers/wikiparser/rules/wikilink.js index 6a59d395f..d5e1a48ec 100644 --- a/core/modules/parsers/wikiparser/rules/wikilink.js +++ b/core/modules/parsers/wikiparser/rules/wikilink.js @@ -66,7 +66,6 @@ exports.parse = function() { }; exports.serialize = function(tree, serialize) { - // Check if the link is suppressed var isSuppressed = tree.children[0].text.substr(0,1) === $tw.config.textPrimitives.unWikiLink; var serialized = isSuppressed ? $tw.config.textPrimitives.unWikiLink : "";