Updated linter, linted scripts

This commit is contained in:
Angelos Chalaris
2017-12-23 11:52:07 +02:00
parent 20347facda
commit 8caafdf1d9
5 changed files with 10 additions and 4 deletions

View File

@ -10,6 +10,7 @@ var snippetsPath = './snippets';
// Read files, lint each one individually and update // Read files, lint each one individually and update
try { try {
let snippetFilenames = fs.readdirSync(snippetsPath); let snippetFilenames = fs.readdirSync(snippetsPath);
let jobCounter = 0;
snippetFilenames.sort((a, b) => { snippetFilenames.sort((a, b) => {
a = a.toLowerCase(); a = a.toLowerCase();
b = b.toLowerCase(); b = b.toLowerCase();
@ -25,10 +26,14 @@ try {
// Synchronously read data from the snippet, get the code, write it to a temporary file // Synchronously read data from the snippet, get the code, write it to a temporary file
let snippetData = fs.readFileSync(path.join(snippetsPath,snippet),'utf8'); let snippetData = fs.readFileSync(path.join(snippetsPath,snippet),'utf8');
let originalCode = snippetData.slice(snippetData.indexOf('```js')+5,snippetData.lastIndexOf('```')); let originalCode = snippetData.slice(snippetData.indexOf('```js')+5,snippetData.lastIndexOf('```'));
while(jobCounter >= 20){
setTimeout(()=>{},5000);
}
fs.writeFileSync(`${snippet}.temp.js`,`${originalCode}`); fs.writeFileSync(`${snippet}.temp.js`,`${originalCode}`);
// Run semistandard asynchronously (only way this manages to run), get linted code // Run semistandard asynchronously (only way this manages to run), get linted code
// and write back to the original snippet file. Remove temporary file // and write back to the original snippet file. Remove temporary file
cp.exec(`semistandard "${snippet}.temp.js" --fix`,{},(error, stdOut, stdErr) => { cp.exec(`semistandard "${snippet}.temp.js" --fix`,{},(error, stdOut, stdErr) => {
jobCounter += 1;
let lintedCode = fs.readFileSync(`${snippet}.temp.js`,'utf8'); let lintedCode = fs.readFileSync(`${snippet}.temp.js`,'utf8');
fs.writeFile(path.join(snippetsPath,snippet), `${snippetData.slice(0, snippetData.indexOf('```js')+5)+lintedCode+'```\n'}`); fs.writeFile(path.join(snippetsPath,snippet), `${snippetData.slice(0, snippetData.indexOf('```js')+5)+lintedCode+'```\n'}`);
fs.unlink(`${snippet}.temp.js`); fs.unlink(`${snippet}.temp.js`);
@ -36,6 +41,7 @@ try {
console.log(`${chalk.green('SUCCESS!')} Linted snippet: ${snippet}`); console.log(`${chalk.green('SUCCESS!')} Linted snippet: ${snippet}`);
// Log the time taken for the file // Log the time taken for the file
console.timeEnd(`Linter (${snippet})`); console.timeEnd(`Linter (${snippet})`);
jobCounter -= 1;
}); });
} }
} }

View File

@ -11,4 +11,4 @@ Promise.resolve( [ 1, 2, 3 ] ).then( call('map', x => 2 * x ) ).then( console.lo
const map = call.bind(null, 'map') const map = call.bind(null, 'map')
Promise.resolve( [ 1, 2, 3 ] ).then( map( x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ] Promise.resolve( [ 1, 2, 3 ] ).then( map( x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ]
*/ */
``` ```

View File

@ -13,4 +13,4 @@ let p2 = Promise.resolve(2)
let p3 = new Promise((resolve) => setTimeout(resolve,2000,3)) let p3 = new Promise((resolve) => setTimeout(resolve,2000,3))
Pall(p1, p2, p3).then(console.log) Pall(p1, p2, p3).then(console.log)
*/ */
``` ```

View File

@ -15,4 +15,4 @@ mergePerson(b) // == b
b = {} b = {}
Object.assign(b, a) // == b Object.assign(b, a) // == b
*/ */
``` ```

View File

@ -11,4 +11,4 @@ const arrayMax = spreadOver(Math.max)
arrayMax([1,2,3]) // -> 3 arrayMax([1,2,3]) // -> 3
arrayMax([1,2,4]) // -> 4 arrayMax([1,2,4]) // -> 4
*/ */
``` ```