Codacy style update for library.js

This commit is contained in:
Angelos Chalaris
2018-08-02 11:33:11 +03:00
committed by GitHub
parent 8d83e8e86b
commit 205424cf03

View File

@ -11,46 +11,46 @@ const glossaryFiles = util.getFilesInDir('./glossary', true, ['keyword_database'
const fileTitles = []; const fileTitles = [];
const getGlossaryTermMarkdownBlock = (fileName) => { const getGlossaryTermMarkdownBlock = (fileName) => {
let fileContent = fs.readFileSync(fileName, 'utf8'); let fileContent = fs.readFileSync(fileName, 'utf8');
let title = fileContent.match(/###[^\n]*/)[0].replace('### ', '').trim(); let title = fileContent.match(/###[^\n]*/)[0].replace('### ', '').trim();
// let description = fileContent.replace(title, '').trim(); // let description = fileContent.replace(title, '').trim();
fileTitles.push(title); fileTitles.push(title);
return fileContent.trim() + "\n"; return fileContent.trim() + "\n";
}; };
const glossaryFilesContentReducer = (accumulator, currentFilename) => { const glossaryFilesContentReducer = (accumulator, currentFilename) => {
// handle first array item // handle first array item
if (accumulator === glossaryFiles[0]) { if (accumulator === glossaryFiles[0]) {
return getGlossaryTermMarkdownBlock(accumulator) + "\n" + getGlossaryTermMarkdownBlock(currentFilename); return getGlossaryTermMarkdownBlock(accumulator) + "\n" + getGlossaryTermMarkdownBlock(currentFilename);
} }
return accumulator + "\n" + getGlossaryTermMarkdownBlock(currentFilename); return accumulator + "\n" + getGlossaryTermMarkdownBlock(currentFilename);
}; };
const getTermLinkMarkdownBlock = (termTitle) => { const getTermLinkMarkdownBlock = (termTitle) => {
let anchor = util.getMarkDownAnchor(termTitle); let anchor = util.getMarkDownAnchor(termTitle);
return `* [\`${termTitle}\`](#${anchor})` + "\n"; return `* [\`${termTitle}\`](#${anchor})` + "\n";
}; };
const glossaryTableOfContentsReducer = (accumulator, currentFile) => { const glossaryTableOfContentsReducer = (accumulator, currentFile) => {
if (accumulator === fileTitles[0]) { if (accumulator === fileTitles[0]) {
return getTermLinkMarkdownBlock(accumulator) + getTermLinkMarkdownBlock(currentFile); return getTermLinkMarkdownBlock(accumulator) + getTermLinkMarkdownBlock(currentFile);
} }
return accumulator + getTermLinkMarkdownBlock(currentFile); return accumulator + getTermLinkMarkdownBlock(currentFile);
}; };
try { try {
const fileContents = glossaryFiles.reduce(glossaryFilesContentReducer); const fileContents = glossaryFiles.reduce(glossaryFilesContentReducer);
const TOC = "## Table of Contents\n\n" + fileTitles.reduce(glossaryTableOfContentsReducer); const TOC = "## Table of Contents\n\n" + fileTitles.reduce(glossaryTableOfContentsReducer);
const README = const README =
"# 30-seconds-of-code JavaScript Glossary\n\n" + "# 30-seconds-of-code JavaScript Glossary\n\n" +
TOC + TOC +
"\n\n" + "\n\n" +
fileContents; fileContents;
fs.writeFileSync('glossary/README.md', README); fs.writeFileSync('glossary/README.md', README);
} catch (err) { } catch (err) {
console.log(`${chalk.red('ERROR!')} During glossary README generation: ${err}`); console.log(`${chalk.red('ERROR!')} During glossary README generation: ${err}`);
process.exit(1); process.exit(1);
} }