jschyma / open_fints_js_client

FinTS/HBCI Javascript Client
Apache License 2.0
134 stars 44 forks source link

Code cleanup #31

Closed tndev closed 7 years ago

tndev commented 7 years ago

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

The changes in commit 5f2f550fd840b33333a07ee50394c385c2409f32 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 02ebddc4f68b9713de228e28058ecdb903a19b08 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 5f87fc87620682ad146cb2a8a636a1ba1291f13d 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 54352b5a0ec971e4b70d466f27361a640fa230ff.

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.