Skip to content

Commit

Permalink
style: phpstan & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jul 3, 2018
1 parent 76281af commit 042d762
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/MariaDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function parsePage(url, cbSuccess) {
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let doc = { id: element.id };
doc.name = element.childNodes[0].textContent;
doc.name = element.childNodes[0].textContent.trim();
try {
// Parse ul > li
element.nextSibling.nextSibling.childNodes.forEach(liChild => {
Expand Down
17 changes: 15 additions & 2 deletions src/MySQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ function parsePage(url, cbSuccess) {
}

doc.id = element.parentElement.getElementsByTagName('a')[0].name;

const regexCli = /([-]{2})([0-9a-z-_]+)/i;
doc.name = element.parentElement.getElementsByTagName('code')[0].textContent.trim();
var cli = doc.name.match(regexCli);
if (cli) {
// cli format
doc.name = cli[2].replace(/-/g, '_'); //Try to clean format
}
var tbody = element.getElementsByTagName('tbody')[0];

var trs = tbody.getElementsByTagName('tr');
Expand All @@ -29,7 +35,14 @@ function parsePage(url, cbSuccess) {
doc.dynamic = value.textContent.toLowerCase().trim() === 'yes';
break;
case 'system variable':
doc.name = value.textContent.toLowerCase().trim();
var theName = value.textContent.toLowerCase().trim();
if (doc.name !== undefined) {
if (doc.name.match(regexCli)) {
doc.name = theName;
}
} else {
doc.name = theName;
}
break;
case 'scope':
doc.scope = value.textContent
Expand Down
26 changes: 11 additions & 15 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ const fs = require('fs');
* @param {function} arraySorter The sorter callback
*/
function sortObject(obj, arraySorter) {
if(typeof obj !== 'object')
return obj
if (typeof obj !== 'object') return obj;
if (Array.isArray(obj)) {
if (arraySorter) {
obj.sort(arraySorter);
}
for (var i = 0; i < obj.length; i++) {
obj[i] = sortObject(obj[i], arraySorter);
}
return obj;
if (arraySorter) {
obj.sort(arraySorter);
}
for (var i = 0; i < obj.length; i++) {
obj[i] = sortObject(obj[i], arraySorter);
}
return obj;
}
var temp = {};
var keys = [];
for(var key in obj)
keys.push(key);
for (var key in obj) keys.push(key);
keys.sort();
for(var index in keys)
temp[keys[index]] = sortObject(obj[keys[index]], arraySorter);
for (var index in keys) temp[keys[index]] = sortObject(obj[keys[index]], arraySorter);
return temp;
}
exports.writeJSON = function writeJSON(filename, data) {

fs.writeFile(filename, JSON.stringify(sortObject(data), null, 2)+"\n", function(err) {
fs.writeFile(filename, JSON.stringify(sortObject(data), null, 2) + '\n', function(err) {
if (err) {
return console.log(err);
}
Expand Down
25 changes: 13 additions & 12 deletions src/merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ function fixRange(stdClass &$current, stdClass &$cache): void
}

foreach ($data as $doc) {
if (isset($doc->name)) {
if (isset($variables[$doc->name]) === false) {
$identifier = $doc->name;
if (isset($identifier)) {
if (isset($variables[$identifier]) === false) {
if (isset($doc->ids) === false) {
$doc->ids = array();
}
$variables[$doc->name] = $doc;
$kbEntry = new stdClass();
$kbEntry->anchor = $doc->id;
$kbEntry->url = $fileData->url;
$doc->ids[] = $kbEntry;
$variables[$identifier] = $doc;
$kbEntry = new stdClass();
$kbEntry->anchor = $doc->id;
$kbEntry->url = $fileData->url;
$doc->ids[] = $kbEntry;
unset($doc->id);
} else {
if (isset($doc->ids) === false) {
Expand All @@ -116,11 +117,11 @@ function fixRange(stdClass &$current, stdClass &$cache): void
$kbEntry->url = $fileData->url;
$doc->ids[] = $kbEntry;
unset($doc->id);
//echo $doc->name." duplicate ! in ".str_replace($dataDir, "", $file).PHP_EOL;
//echo $identifier." duplicate ! in ".str_replace($dataDir, "", $file).PHP_EOL;
$newData = new stdClass();
foreach ((array) $doc as $key => $val) {
if (isset($variables[$doc->name]->$key)) {
$cacheValue = $variables[$doc->name]->$key;
if (isset($variables[$identifier]->$key)) {
$cacheValue = $variables[$identifier]->$key;
$docValue = $doc->$key;
if (( strtoupper(json_encode($cacheValue)) === strtoupper(json_encode($docValue)))
&& ( json_encode($cacheValue) !== json_encode($docValue))
Expand Down Expand Up @@ -308,7 +309,7 @@ function fixRange(stdClass &$current, stdClass &$cache): void
$cache = $cacheValue;
fixRange($current, $cache);
} else {
echo '[ERROR] conflict '.$key.' + '.$doc->name.' - '.json_encode($cacheValue).' - '.json_encode($docValue).PHP_EOL;
echo '[ERROR] conflict '.$key.' + '.$identifier.' - '.json_encode($cacheValue).' - '.json_encode($docValue).PHP_EOL;
}
} else {
$newData->$key = $val;
Expand All @@ -318,7 +319,7 @@ function fixRange(stdClass &$current, stdClass &$cache): void
}
}
//print_r($newData);
$variables[$doc->name] = $newData;
$variables[$identifier] = $newData;
}
}
}
Expand Down

0 comments on commit 042d762

Please sign in to comment.