Skip to content

Code cleanup#31

Merged
jschyma merged 5 commits into
jschyma:masterfrom
tndev:code_cleanup
Apr 24, 2017
Merged

Code cleanup#31
jschyma merged 5 commits into
jschyma:masterfrom
tndev:code_cleanup

Conversation

@tndev

@tndev tndev commented Apr 23, 2017

Copy link
Copy Markdown
Contributor

I have finished my first pass on the code targeting the issue #30.

The changes in commit 5f2f550 were done using this script:

'use strict'
const Promise = require('bluebird')
const glob = Promise.promisify(require('glob'))
const fs = Promise.promisifyAll(require('fs'))
const standard = Promise.promisifyAll(require('standard'))
// get all js files
Promise.all([
  ['index.js'],
  glob('test/*.js'),
  glob('lib/*.js'),
  glob('examples/*.js'),
  glob('dev/*.js')
])
// concat indicidual arrays into one arra
.then(files => Array.prototype.concat.apply([], files))
.each(file => {
  console.log('updating ' + file)

  return fs.readFileAsync(file)
  // replace \r\n with \n
  .then(fileContant => fileContant.toString().replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n'))
  .then(lines => lines.join('\n'))
  // write updated content back to file
  .then(updatedContent => fs.writeFileAsync(file, updatedContent))
})

I replaced all \r\n and \n to be consistent through all files.

The changes in commit 02ebddc were done using this script:

'use strict'
const Promise = require('bluebird')
const glob = Promise.promisify(require('glob'))
const fs = Promise.promisifyAll(require('fs'))
const standard = Promise.promisifyAll(require('standard'))
// get all js files
Promise.all([
  ['index.js'],
  glob('test/*.js'),
  glob('lib/*.js'),
  glob('examples/*.js'),
  glob('dev/*.js')
])
// concat indicidual arrays into one arra
.then(files => Array.prototype.concat.apply([], files))
.each(file => {
  console.log('updating ' + file)

  return fs.readFileAsync(file)
  // replace the tabs at the beginning of a file with one space
  .then(fileContant => fileContant.toString().replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n'))
  .map(line => line.replace(/^\s+/, ''))
  .then(lines => lines.join('\n'))
  // apply feross/standard coding style
  .then(updatedContent => standard.lintTextAsync(updatedContent, {fix: true}))
  // return the transformed content or the original source
  .then(updateResult => updateResult.results[0].output || updateResult.results[0].source)
  // write updated content back to file
  .then(updatedContent => fs.writeFileAsync(file, updatedContent))
})

I included those scripts so that you can use them to validate those two commits, because nearly every code of line was changed.

In the commit 5f87fc8 I reverted some comments to make them readable again.

The standard command does not correct every code intending error so this changes are done in 54352b5.

The last commit just adds some newline to improve readability.

I will continue with splitting the code into smaller chunks as soon as you were able to review and include these commits.

@jschyma jschyma left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks fine.

@jschyma jschyma merged commit 8699cdd into jschyma:master Apr 24, 2017
@tndev tndev deleted the code_cleanup branch April 24, 2017 17:48
@tndev tndev mentioned this pull request Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants