From 50c8c85c652274d1d50dfb3acd068cbd0c682db7 Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 07:06:37 -0600 Subject: [PATCH 1/6] Add color output. Add basic syntax error fault location. Check license against the list. Add line numbers if not a PR. Cleanup unused code. Allow travis triggered builds on travis_test branch. --- .travis.yml | 8 +- tests/test.js | 241 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 207 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f71e275..3801e5d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,16 +2,19 @@ language: node_js node_js: - "node" - +cache: + npm: false + before_install: - rvm install 2.6.2 - gem install awesome_bot + - cd tests && npm install chalk && cd .. before_script: script: - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then git diff origin/master -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md; fi || (exit 0)' - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then node tests/test.js temp.md; else node tests/test.js README.md; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then node tests/test.js -r README.md -d temp.md; else node tests/test.js -r README.md; fi' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ -f temp.md ]; then awesome_bot temp.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; else (exit 0); fi else awesome_bot README.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; fi' notifications: @@ -20,4 +23,5 @@ notifications: branches: only: - master + - travis_test diff --git a/tests/test.js b/tests/test.js index 879e4fdd..42c4fbf2 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,22 +1,48 @@ -// Accepts input of any filename, ie. node test.js README.md +// USAGE: +// node test.js -r README.md (Checks whole file) +// node test.js -r README.md -d temp.md (Checks just the diff) const fs = require('fs'); +//let colors = require('colors/safe'); +const chalk = require('chalk'); +let licenses = new Set(); +let pr = false; +let readme; +let diff; -let log = '{\n'; -let issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n'; -let fails = '' -const file = fs.readFileSync(process.argv[2], 'utf8'); // Reads argv into var file +//Parse the command options and set the pr var +function parseArgs(args) { + if ( args.indexOf('-r', 2) > 0 ) { + readme = fs.readFileSync(args[args.indexOf('-r', 2)+1], 'utf8') + } + if (args.indexOf('-d', 2) > 0) { + pr = true; + diff = fs.readFileSync(args[args.indexOf('-d', 2)+1], 'utf8'); + } + if ( pr === true) { + console.log(chalk.blue(`Running on PR. README.md: ${args[args.indexOf('-r', 2)+1]} diff: ${args[args.indexOf('-d', 2)+1]}`)) + } +} -function entryFilter(md) { // Function to find lines with entries +// Function to find lines with entries +function entryFilter(md) { const linepatt = /^\s{0,2}-\s\[.*`/; return linepatt.test(md); } -function split(text) { // Function to split lines into array +// Function to find lines with licenses +function licenseFilter(md) { + const linepatt = /^- `.*` - .*/; + return linepatt.test(md) +} + +// Function to split lines into array +function split(text) { return text.split(/\r?\n/); } -function findPattern(text) { // All entries should match this pattern. If matches pattern returns true. +// All entries should match this pattern. If matches pattern returns true. +function findPattern(text) { const patt = /^\s{0,2}-\s\[.*?\]\(.*?\) (`⚠` )?- .{0,249}?\.( \(\[(Demo|Source Code|Clients)\]\([^)]*\)(, \[(Source Code|Clients)\]\([^)]*\))?(, \[(Source Code|Clients)\]\([^)]*\))*\))? \`.*?\` \`.*?\`$/; if (patt.test(text) === true) { return true; @@ -24,47 +50,182 @@ function findPattern(text) { // All entries should match this pattern. If match return false; } -function entryErrorCheck(md) { - const namepatt = /^\s{0,2}-\s\[(.*?)\]/; // regex pattern to find name of entryArray - const entries = split(md); // Inserts each line into the entries array +// Parses SPDX identifiers from list of licenses +function parseLicense(md) { + const patt = /^- `(.*)` - .*/ + return patt.exec(md)[1] +} + +//Tests '- [Name](http://homepage/)' +function testMainLink(text) { + let testA = /(^ {0,2}- \[.*?\]\(.*\))(?=.?-? ?\w)/; + const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; + if (testA.test(text) === false) { + let a1 = testA1.exec(text)[2]; + return chalk.red.underline(text.replace(a1, '')) + } + return chalk.green(testA.exec(text)[1]) +} + +//Tests '`⚠` - Short description, less than 250 characters.' +function testDescription(text) { + const testB = /( - .*\. )(?:(\(?\[?|\`))/; + const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; + const testB2 = /((\(\[|\`).*$)/; + if (testB.test(text) === false) { + let b1 = testA1.exec(text)[1]; + let b2 = testB2.exec(text)[1]; + return chalk.red.underline(text.replace(b1, '').replace(b2, '')) + } + return chalk.green(testB.exec(text)[1]) +} + +//If present, tests '([Demo](http://url.to/demo), [Source Code](http://url.of/source/code), [Clients](https://url.to/list/of/related/clients-or-apps))' +function testSrcDemCli(text) { + let testC = text.search(/\(\[|\)\,|\)\)/); + let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)]*\)(, \[(Source Code|Clients)\]\([^)]*\))?(, \[(Source Code|Clients)\]\([^)]*\))*\))(?= \`?)/; + const testD1 = /(^.*\.)(?= )/; + const testD2 = /(\`.*\` \`.*\`$)/; + if ((testC > -1) && (testD.test(text) === false)) { + let d1 = testD1.exec(text)[1]; + let d2 = testD2.exec(text)[1]; + return chalk.red.underline(text.replace(d1+' ', '').replace(d2, '')) +} else if (testC > -1) { + return chalk.green(testD.exec(text)[1]) +} +return "" +} + +// Tests '`License` `Language`' +function testLangLic(text) { + const testD2 = /(\`.*\` \`.*\`$)/; + let testE = testD2.test(text); + const testE1 = /(^[^`]*)/; + if (testE === false) { + let e1 = testE1.exec(text)[1]; + return chalk.red.underline(text.replace(e1, '')) + } + return chalk.green(testD2.exec(text)[1]) +} + +//Runs all the syntax tests... +function findError(text) { + let res + res = testMainLink(text) + res += testDescription(text) + res += testSrcDemCli(text) + res += testLangLic(text) + return res + `\n` +} +//Check if license is in the list of licenses. +function testLicense(md) { + const regex = /.*\`(.*)\` \`.*\`$/; + return licenses.has(regex.exec(md)[1]) +} + +//Parses name from entry +function parseName(md) { + const regex = /^\W*(.*?)\W/ + return regex.exec(md)[1] +} + +function entryErrorCheck() { + const lines = split(readme); // Inserts each line into the entries array let totalFail = 0; let totalPass = 0; let total = 0; - const entryArray = []; - if (entries[0] === "") { - console.log("0 Entries") + let failed = []; + let entries = []; + let diffEntries = []; + + if (lines[0] === "") { + console.log(chalk.red("0 Entries Found")) process.exit(0) } - for (let i = 0, len = entries.length; i < len; i += 1) { // Loop to create array of objects - entryArray[i] = new Object; - entryArray[i].raw = entries[i]; - if (entryFilter(entries[i]) === true) { // filter out lines that don't start with * [) - total += 1; - entryArray[i].name = namepatt.exec(entries[i])[1]; // Parses name of entry - entryArray[i].pass = findPattern(entries[i]); // Tests against known patterns - if (entryArray[i].pass === true) { // If entry passes increment totalPass counter - totalPass += 1; - } else { - console.log(`${entryArray[i].name} Failed.`); // If entry fails increment totalFail counter and append error to issuelog - // entryArray[i].error = findError(entries[i]) //WIP - totalFail += 1; - issuelog += `${entryArray[i].name} | ${entries[i]} \\n`; - fails += `${entries[i]} \n\n`; + for (let i = 0; i < lines.length; i ++) { // Loop through array of lines + if (entryFilter(lines[i]) === true) { // filter out lines that don't start with * [) + e = {}; + e.raw = lines[i]; + e.line = i + entries.push(e); + } else if (licenseFilter(lines[i]) === true) { + licenses.add(parseLicense(lines[i])) + } + } + + if (pr === true) { + console.log(chalk.cyan("Only testing the diff from the PR.")) + const diffLines = split(diff); // Inserts each line of diff into an array + for (let l of diffLines) { + if (entryFilter(l) === true) { // filter out lines that don't start with * [) + e = {}; + e.raw = l; + diffEntries.push(e); + } else if (licenseFilter(l) === true) { + licenses.add(parseLicense(l)) } } + total = diffEntries.length + for (let e of diffEntries) { + e.pass = true + e.name = parseName(e.raw) + if (!findPattern(e.raw)) { + e.highlight = findError(e.raw); + e.pass = false; + console.log(`${e.highlight}`) + } + e.licenseTest = testLicense(e.raw); + if (e.licenseTest === false) { + e.pass = false; + console.log(chalk.yellow(`${e.name}'s license is not on License list.`)) + } + if (e.pass) { + totalPass++ + } else { + totalFail++ + } + } + } else { + console.log(chalk.cyan("Testing entire README.md")) + total = entries.length + for (let e of entries) { + e.pass = true + e.name = parseName(e.raw) + if (!findPattern(e.raw)) { + e.highlight = findError(e.raw); + e.pass = false; + console.log(`${chalk.yellow(e.line)} ${e.highlight}`) + } + e.licenseTest = testLicense(e.raw); + if (e.licenseTest === false) { + e.pass = false; + console.log(chalk.yellow(`${e.line} ${e.name}'s license is not on License list.`)) + } + if (e.pass) { + totalPass++ + } else { + totalFail++ + } + } } - if (totalFail > 0) { // Logs # passed & failed to console, and failures to syntaxcheck.json - console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total}\n-----------------------------`); - console.log(fails) - log += ` "error": true,\n "title": "Found ${totalFail} entries with syntax error(s).",\n`; - fs.writeFileSync('syntaxcheck.json', `${log} ${issuelog} "\n}`); + + + if (totalFail > 0) { + console.log(chalk.blue(`\n-----------------------------\n`)) + console.log(chalk.green("The portion of the entry with an error ") + chalk.underline.red("will be underlined and RED") + `\n`) + console.log(chalk.blue(`\n-----------------------------\n`)) + console.log(chalk.red(`${totalFail} Failed, `) + chalk.green(`${totalPass} Passed, `) + chalk.blue(`of ${total}`)) + console.log(chalk.blue(`\n-----------------------------\n`)) process.exit(1); - } else { // Logs # of entries passed to console and error: false to syntaxcheck.json - console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total} \n`); - log += ' "error": false\n}'; - fs.writeFileSync('syntaxcheck.json', log); - process.exit(0); + } else { + console.log(chalk.blue(`\n-----------------------------\n`)) + console.log(chalk.green(`${totalPass} Passed of ${total}`)) + console.log(chalk.blue(`\n-----------------------------\n`)) + process.exit(0) } + + } -entryErrorCheck(file); +parseArgs(process.argv) +entryErrorCheck(); From e1997787667a88abbab8aca6b4882b1347b8c41b Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 13:15:06 -0600 Subject: [PATCH 2/6] Change color output. Refactor code. --- tests/test.js | 62 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/tests/test.js b/tests/test.js index 42c4fbf2..9c2fd0a1 100644 --- a/tests/test.js +++ b/tests/test.js @@ -3,7 +3,6 @@ // node test.js -r README.md -d temp.md (Checks just the diff) const fs = require('fs'); -//let colors = require('colors/safe'); const chalk = require('chalk'); let licenses = new Set(); let pr = false; @@ -60,9 +59,9 @@ function parseLicense(md) { function testMainLink(text) { let testA = /(^ {0,2}- \[.*?\]\(.*\))(?=.?-? ?\w)/; const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; - if (testA.test(text) === false) { + if (!testA.test(text)) { let a1 = testA1.exec(text)[2]; - return chalk.red.underline(text.replace(a1, '')) + return chalk.red(text.replace(a1, '')) } return chalk.green(testA.exec(text)[1]) } @@ -72,10 +71,10 @@ function testDescription(text) { const testB = /( - .*\. )(?:(\(?\[?|\`))/; const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; const testB2 = /((\(\[|\`).*$)/; - if (testB.test(text) === false) { + if (!testB.test(text)) { let b1 = testA1.exec(text)[1]; let b2 = testB2.exec(text)[1]; - return chalk.red.underline(text.replace(b1, '').replace(b2, '')) + return chalk.red(text.replace(b1, '').replace(b2, '')) } return chalk.green(testB.exec(text)[1]) } @@ -86,10 +85,11 @@ function testSrcDemCli(text) { let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)]*\)(, \[(Source Code|Clients)\]\([^)]*\))?(, \[(Source Code|Clients)\]\([^)]*\))*\))(?= \`?)/; const testD1 = /(^.*\.)(?= )/; const testD2 = /(\`.*\` \`.*\`$)/; - if ((testC > -1) && (testD.test(text) === false)) { + if ((testC > -1) && (!testD.test(text))) { let d1 = testD1.exec(text)[1]; let d2 = testD2.exec(text)[1]; - return chalk.red.underline(text.replace(d1+' ', '').replace(d2, '')) + + return chalk.red(text.replace(d1+' ', '').replace(d2, '')) } else if (testC > -1) { return chalk.green(testD.exec(text)[1]) } @@ -101,9 +101,9 @@ function testLangLic(text) { const testD2 = /(\`.*\` \`.*\`$)/; let testE = testD2.test(text); const testE1 = /(^[^`]*)/; - if (testE === false) { + if (!testE) { let e1 = testE1.exec(text)[1]; - return chalk.red.underline(text.replace(e1, '')) + return chalk.red(text.replace(e1, '')) } return chalk.green(testD2.exec(text)[1]) } @@ -117,12 +117,24 @@ function findError(text) { res += testLangLic(text) return res + `\n` } + //Check if license is in the list of licenses. function testLicense(md) { + let pass = true; + let lFailed = [] + let lPassed = [] const regex = /.*\`(.*)\` \`.*\`$/; - return licenses.has(regex.exec(md)[1]) + for (l of regex.exec(md)[1].split("/")) { + if (!licenses.has(l)) { + pass = false; + lPassed.push(l) + } + lFailed.push(l) + } + return [pass, lFailed, lPassed] } + //Parses name from entry function parseName(md) { const regex = /^\W*(.*?)\W/ @@ -134,12 +146,11 @@ function entryErrorCheck() { let totalFail = 0; let totalPass = 0; let total = 0; - let failed = []; let entries = []; let diffEntries = []; if (lines[0] === "") { - console.log(chalk.red("0 Entries Found")) + console.log(chalk.red("0 Entries Found, check your commandline arguments")) process.exit(0) } for (let i = 0; i < lines.length; i ++) { // Loop through array of lines @@ -154,7 +165,7 @@ function entryErrorCheck() { } if (pr === true) { - console.log(chalk.cyan("Only testing the diff from the PR.")) + console.log(chalk.cyan("Only testing the diff from the PR.\n")) const diffLines = split(diff); // Inserts each line of diff into an array for (let l of diffLines) { if (entryFilter(l) === true) { // filter out lines that don't start with * [) @@ -165,6 +176,10 @@ function entryErrorCheck() { licenses.add(parseLicense(l)) } } + if (diffEntries.length === 0) { + console.log("No entries changed in README.md, Exiting...") + process.exit(0) + } total = diffEntries.length for (let e of diffEntries) { e.pass = true @@ -175,9 +190,9 @@ function entryErrorCheck() { console.log(`${e.highlight}`) } e.licenseTest = testLicense(e.raw); - if (e.licenseTest === false) { + if (!e.licenseTest) { e.pass = false; - console.log(chalk.yellow(`${e.name}'s license is not on License list.`)) + console.log(chalk.red(`${e.name}'s license is not on License list.`)) } if (e.pass) { totalPass++ @@ -186,7 +201,7 @@ function entryErrorCheck() { } } } else { - console.log(chalk.cyan("Testing entire README.md")) + console.log(chalk.cyan("Testing entire README.md\n")) total = entries.length for (let e of entries) { e.pass = true @@ -194,25 +209,22 @@ function entryErrorCheck() { if (!findPattern(e.raw)) { e.highlight = findError(e.raw); e.pass = false; - console.log(`${chalk.yellow(e.line)} ${e.highlight}`) + console.log(`${chalk.yellow(e.line + ": ")}${e.highlight}`); + syntax = e.highlight; } e.licenseTest = testLicense(e.raw); - if (e.licenseTest === false) { + if (!e.licenseTest[0]) { e.pass = false; - console.log(chalk.yellow(`${e.line} ${e.name}'s license is not on License list.`)) + console.log(chalk.yellow(e.line + ": ") + `${e.name}'s license ${chalk.red(`'${e.licenseTest[1]}'`)} is not on the License list.\n`) } if (e.pass) { totalPass++ } else { totalFail++ } - } + } } - - if (totalFail > 0) { - console.log(chalk.blue(`\n-----------------------------\n`)) - console.log(chalk.green("The portion of the entry with an error ") + chalk.underline.red("will be underlined and RED") + `\n`) console.log(chalk.blue(`\n-----------------------------\n`)) console.log(chalk.red(`${totalFail} Failed, `) + chalk.green(`${totalPass} Passed, `) + chalk.blue(`of ${total}`)) console.log(chalk.blue(`\n-----------------------------\n`)) @@ -223,8 +235,6 @@ function entryErrorCheck() { console.log(chalk.blue(`\n-----------------------------\n`)) process.exit(0) } - - } parseArgs(process.argv) From 1fee3d0b6cd3f2f0cfb37b4caf80360749c9c97e Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 13:16:02 -0600 Subject: [PATCH 3/6] check links in non-free.md with awesome_bot --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3801e5d4..49cb36a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_script: script: - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then git diff origin/master -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md; fi || (exit 0)' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then node tests/test.js -r README.md -d temp.md; else node tests/test.js -r README.md; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ -f temp.md ]; then awesome_bot temp.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; else (exit 0); fi else awesome_bot README.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ -f temp.md ]; then awesome_bot temp.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; else (exit 0); fi else awesome_bot README.md,non-free.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; fi' notifications: email: false From 09afc024ff82e1d31ba1b2b1501602cd27b63b2c Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 13:31:35 -0600 Subject: [PATCH 4/6] Fix travis error. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 49cb36a2..828806b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,9 @@ before_script: script: - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then git diff origin/master -U0 README.md | grep -Pos "(?<=^\+).*" >> temp.md; fi || (exit 0)' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then node tests/test.js -r README.md -d temp.md; else node tests/test.js -r README.md; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ -f temp.md ]; then awesome_bot temp.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; else (exit 0); fi else awesome_bot README.md,non-free.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then if [ -f temp.md ]; then awesome_bot temp.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; else (exit 0); fi else awesome_bot *.md --allow-redirect --skip-save-results --allow 202 --white-list airsonic.github.io/docs/apps; fi' + notifications: email: false From 7dd218985094aec22795d6147fbd32066fd606be Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 13:45:29 -0600 Subject: [PATCH 5/6] Fix line numbers. --- tests/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.js b/tests/test.js index 9c2fd0a1..1bb1a361 100644 --- a/tests/test.js +++ b/tests/test.js @@ -157,7 +157,7 @@ function entryErrorCheck() { if (entryFilter(lines[i]) === true) { // filter out lines that don't start with * [) e = {}; e.raw = lines[i]; - e.line = i + e.line = i + 1 entries.push(e); } else if (licenseFilter(lines[i]) === true) { licenses.add(parseLicense(lines[i])) From a81bd71bb3ccf6fe5ec4911716396ac0f142187d Mon Sep 17 00:00:00 2001 From: n8225 Date: Sat, 8 Feb 2020 15:41:06 -0600 Subject: [PATCH 6/6] Fix bugs in tests. --- tests/test.js | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/test.js b/tests/test.js index 1bb1a361..9d2ef63c 100644 --- a/tests/test.js +++ b/tests/test.js @@ -42,7 +42,7 @@ function split(text) { // All entries should match this pattern. If matches pattern returns true. function findPattern(text) { - const patt = /^\s{0,2}-\s\[.*?\]\(.*?\) (`⚠` )?- .{0,249}?\.( \(\[(Demo|Source Code|Clients)\]\([^)]*\)(, \[(Source Code|Clients)\]\([^)]*\))?(, \[(Source Code|Clients)\]\([^)]*\))*\))? \`.*?\` \`.*?\`$/; + const patt = /^\s{0,2}-\s\[.*?\]\(.*?\) (`⚠` )?- .{0,249}?\.( \(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\))? \`.*?\` \`.*?\`$/; if (patt.test(text) === true) { return true; } @@ -55,10 +55,10 @@ function parseLicense(md) { return patt.exec(md)[1] } -//Tests '- [Name](http://homepage/)' +//Test '- [Name](http://homepage/)' function testMainLink(text) { let testA = /(^ {0,2}- \[.*?\]\(.*\))(?=.?-? ?\w)/; - const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; + const testA1 = /(- \W?\w*\W{0,2}.*?\)?)( .*$)/; if (!testA.test(text)) { let a1 = testA1.exec(text)[2]; return chalk.red(text.replace(a1, '')) @@ -66,10 +66,10 @@ function testMainLink(text) { return chalk.green(testA.exec(text)[1]) } -//Tests '`⚠` - Short description, less than 250 characters.' +//Test '`⚠` - Short description, less than 250 characters.' function testDescription(text) { const testB = /( - .*\. )(?:(\(?\[?|\`))/; - const testA1 = /(- \[.*?\]?\(?.*?\)?)( .*$)/; + const testA1 = /(- \W?\w*\W{0,2}.*?\)?)( .*$)/; const testB2 = /((\(\[|\`).*$)/; if (!testB.test(text)) { let b1 = testA1.exec(text)[1]; @@ -82,14 +82,13 @@ function testDescription(text) { //If present, tests '([Demo](http://url.to/demo), [Source Code](http://url.of/source/code), [Clients](https://url.to/list/of/related/clients-or-apps))' function testSrcDemCli(text) { let testC = text.search(/\(\[|\)\,|\)\)/); - let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)]*\)(, \[(Source Code|Clients)\]\([^)]*\))?(, \[(Source Code|Clients)\]\([^)]*\))*\))(?= \`?)/; - const testD1 = /(^.*\.)(?= )/; + let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\))(?= \`?)/; + const testD1 = /(^- \W[a-zA-Z0-9-_ ]*\W{0,2}http[^\[]*)(?<= )/; const testD2 = /(\`.*\` \`.*\`$)/; if ((testC > -1) && (!testD.test(text))) { let d1 = testD1.exec(text)[1]; let d2 = testD2.exec(text)[1]; - - return chalk.red(text.replace(d1+' ', '').replace(d2, '')) + return chalk.red(text.replace(d1, '').replace(d2, '')) } else if (testC > -1) { return chalk.green(testD.exec(text)[1]) } @@ -123,14 +122,25 @@ function testLicense(md) { let pass = true; let lFailed = [] let lPassed = [] - const regex = /.*\`(.*)\` \`.*\`$/; - for (l of regex.exec(md)[1].split("/")) { - if (!licenses.has(l)) { - pass = false; - lPassed.push(l) + const regex = /.*\`(.*)\` .*$/; + try { + for (l of regex.exec(md)[1].split("/")) { + if (!licenses.has(l)) { + pass = false; + lPassed.push(l) + } + lFailed.push(l) } - lFailed.push(l) } + catch(err) { + console.log(chalk.yellow("Error in License syntax, license not checked against list.")) + return [false, "", ""] + } + + + + + return [pass, lFailed, lPassed] } @@ -187,7 +197,7 @@ function entryErrorCheck() { if (!findPattern(e.raw)) { e.highlight = findError(e.raw); e.pass = false; - console.log(`${e.highlight}`) + console.log(e.highlight) } e.licenseTest = testLicense(e.raw); if (!e.licenseTest) {