Permalink
Browse files

Fixes linter errors

Removes semi-colons and unnecessary lets via `make-standard`. Also
pulls errors into `new Error` instead of throwing literals.
  • Loading branch information...
payne-chris-r
payne-chris-r committed May 8, 2017
1 parent 516ed99 commit e138f1fd5d2637f64b8938f587d238da89533f1d
Showing with 61 additions and 61 deletions.
  1. +8 −8 bin/copy-json.js
  2. +5 −5 bin/hey-yall.js
  3. +5 −5 bin/randomizer.js
  4. +16 −16 lib/copy-json.js
  5. +10 −10 lib/hey-yall.js
  6. +17 −17 lib/randomizer.js
@@ -1,13 +1,13 @@
'use strict';
'use strict'

const copyJson = require('../lib/copy-json.js');
const copyJson = require('../lib/copy-json.js')

const stdin = '/dev/stdin';
const stdout = '/dev/stdout';
const stdin = '/dev/stdin'
const stdout = '/dev/stdout'

let inFile = process.argv[2] === '-' ? stdin : process.argv[2];
let outFile = process.argv[3] ? process.argv[3] : stdout;
const inFile = process.argv[2] === '-' ? stdin : process.argv[2]
const outFile = process.argv[3] ? process.argv[3] : stdout

let outFileFlag = outFile === stdout ? 'a' : 'w';
const outFileFlag = outFile === stdout ? 'a' : 'w'

copyJson(inFile, outFile, outFileFlag);
copyJson(inFile, outFile, outFileFlag)
@@ -1,11 +1,11 @@
'use strict';
'use strict'

const heyYall = require('../lib/hey-yall.js');
const heyYall = require('../lib/hey-yall.js')

const inFile = process.argv[2];
const inFile = process.argv[2]

if (!inFile) {
throw('Script requires one argument, an input file.');
throw new Error('Script requires one argument, an input file.')
}

heyYall(inFile);
heyYall(inFile)
@@ -1,11 +1,11 @@
'use strict';
'use strict'

const randomizer = require('../lib/randomizer.js');
const randomizer = require('../lib/randomizer.js')

let inFile = process.argv[2];
const inFile = process.argv[2]

if (!inFile) {
throw('Script requires one argument, an input file');
throw new Error('Script requires one argument, an input file')
}

randomizer(inFile);
randomizer(inFile)
@@ -1,38 +1,38 @@
'use strict';
'use strict'

const fs = require('fs');
const fs = require('fs')

const copyJson = function (inFile, outFile, outFileFlag) {
fs.readFile(inFile, { encoding: 'utf8' }, (error, data) => {
let json, pojo;
let pojo
if (error) {
console.error(error.stack);
return;
console.error(error.stack)
return
}

// parse the data into JSON
try {
pojo = JSON.parse(data);
pojo = JSON.parse(data)
} catch (error) {
console.error(error.stack);
return;
console.error(error.stack)
return
}

// do something with the pojo

// make a string out of the pojo
json = JSON.stringify(pojo, null, 2);
const json = JSON.stringify(pojo, null, 2)

// save it
fs.writeFile(outFile, json, { flag: outFileFlag }, error => {
if (error) {
console.error(error.stack);
return;
console.error(error.stack)
return
}

console.error('\ncopied');
});
});
};
console.error('\ncopied')
})
})
}

module.exports = copyJson;
module.exports = copyJson
@@ -1,24 +1,24 @@
'use strict';
'use strict'

const fs = require('fs');
const fs = require('fs')

const heyYall = function (inFile) {
fs.readFile(inFile, { encoding: 'utf8' }, (error, content) => {
if (error) {
console.error(error);
console.error(error)
}

// 'Billy\nJames\nNick\n' --> ['Billy', 'James', 'Nick']

let lines = content.split('\n');
const lines = content.split('\n')

// clean up the array by removing the empty line
lines.pop();
lines.pop()

lines.forEach((line) => {
console.log(`Hello, ${line}!`);
});
});
};
console.log(`Hello, ${line}!`)
})
})
}

module.exports = heyYall;
module.exports = heyYall
@@ -1,28 +1,28 @@
'use strict';
const fs = require('fs');
'use strict'
const fs = require('fs')

const randomizer = function (inFile) {
fs.readFile(inFile, { encoding: 'utf8' }, (error, content) => {
//first thing is check error
// first thing is check error
if (error) {
console.error(error);
console.error(error)
}

let lines = content.split('\n');
const lines = content.split('\n')

//clean up the array
lines.pop();
// clean up the array
lines.pop()

let randomLines = lines.sort(function () {
const n = 0.5 - Math.random();
const randomSorter = n < 0 ? Math.floor(n) : Math.ceil(n);
return randomSorter;
});
const randomLines = lines.sort(function () {
const n = 0.5 - Math.random()
const randomSorter = n < 0 ? Math.floor(n) : Math.ceil(n)
return randomSorter
})

randomLines.forEach((line) => {
console.log(line);
});
});
};
console.log(line)
})
})
}

module.exports = randomizer;
module.exports = randomizer

0 comments on commit e138f1f

Please sign in to comment.