<commit_before>#!/usr/bin/env node
'use strict';
var argv = require('yargs')
  .alias('s', 'style')
  .alias('l', 'size')
  .alias('t', 'type')
  .alias('r', 'root')
  .alias('w', 'whitespace')
  .alias('m', 'maxline')
  .argv,
  fs = require('fs');
  var str;

if (argv.type && argv.size && argv.style) {
  str = '\n' +
  '\n[*.'+argv.type+']' +
  '\nident-size = ' + argv.size +
  '\nident-style = ' + argv.style +
  '';
};

if(argv.whitespace){
  str += ''+
  '\ntrim_trailing_whitespace = ' + argv.whitespace +
  '';
}

if(argv.maxline){
  str += ''+
  '\nmax_line_length = ' + argv.maxline +
  '';
}

fs.readFile('.editorconfig', function (err, data) {
  if(err){
    fs.exists('.editorconfig', function () {
      if(!argv.root){
        fs.writeFileSync('.editorconfig', '# editorconfig.org');
      }
      if(argv.root){
        fs.writeFileSync('.editorconfig', '# editorconfig.org\n root = true');
      }
    });
  }

  fs.appendFile('.editorconfig', str, function (err) {
    if (err) throw console.log(err);

    console.log('.editorconfig has generated with success! ✔');
  });
});<commit_msg>Add insert_final_newline and improve the code<commit_after>#!/usr/bin/env node
'use strict';
var fs = require('fs');
var chalk = require('chalk');
var argv = require('yargs')
  .alias('t', 'type')
  .alias('s', 'style')
  .alias('l', 'size')
  .alias('r', 'root')
  .alias('w', 'whitespace')
  .alias('m', 'maxline')
  .alias('n', 'newline')
  .argv;
var str;

var options = {
      fileType   : argv.type,
      indentSize : argv.size,
      indentStyle: argv.style,
      whitespace : argv.whitespace,
      maxline    : argv.maxline,
      newLine    : argv.newline,
      root       : argv.root
    };

//# Handling same cases
switch (options.fileType) {
  case 'python':
    options.fileType = 'py';
    break;
  case 'javascript':
    options.fileType = 'js';
    break;
  case 'ruby':
    options.fileType = 'rb';
    break;
  case 'python':
    options.fileType = 'py';
    break;
}

//# File type
if (options.fileType) {

  //# Handling if user set only type.
  if (options.indentSize || options.indentStyle || options.whitespace || options.maxline || options.newLine) {
    if (options.fileType === 'all' || options.fileType === true) {
      str = '\n' +
      '\n[*]' +
      '';
    }
    else if (options.fileType !== 'all') {
      str = '\n' +
      '\n[*.'+options.fileType+']' +
      '';
    }
  } else {
    console.log(chalk.red('Define someone option to your file!'));
    process.exit();
  }
} else {
  console.log(chalk.red('Define a type to the file with --type!'));
  process.exit();
}

//# Indent Size
if (options.indentSize) {
  str += '' +
  '\nindent_size = ' + options.indentSize +
  '';
}

//# Indent Style
if (options.indentStyle) {
  if (options.indentStyle === 'tab' || options.indentStyle === 'space') {
    str += ''+
    '\nindent_style = ' + options.indentStyle +
    '';
  } else if (options.indentStyle !== 'tab' || options.indentStyle !== 'space') {
    console.log(chalk.red('Style only accept space and tab!'));
    process.exit();
  }
}

//# Trim trailing whitespace
if (options.whitespace) {
  if (options.whitespace === 'false') {
      str += ''+
      '\ntrim_trailing_whitespace = false' +
      '';
  } else {
    str += ''+
    '\ntrim_trailing_whitespace = true'+
    '';
  }
}

//# Max-line
if (options.maxline) {
    str += ''+
    '\nmax_line_length = ' + options.maxline +
    '';
}

//# Insert new line
if (options.newLine) {
  if (options.newLine === 'false') {
      str += ''+
      '\ninsert_final_newline = false' +
      '';
  } else {
    str += ''+
    '\ninsert_final_newline = true'+
    '';
  }
}

//# Check if exist an .editorconfig file
fs.readFile('.editorconfig', function (err) {
  if (err) {
    fs.exists('.editorconfig', function () {

      //# If not exists we create one
      if (!argv.root) {
        fs.writeFileSync('.editorconfig', '# editorconfig.org');
      }
      if (options.root) {
        //# Add root to top of the file
        fs.writeFileSync('.editorconfig', '# editorconfig.org\n root = true');
      }
    });
  }

  fs.appendFile('.editorconfig', str, function (err) {
    if (err) throw console.log(err);

    console.log(chalk.green('.editorconfig has been generated with success! ✔'));
  });
});
{'fraction_non_alphanumeric': 0.19832791453785414, 'fraction_numerical': 0.0, 'mean_word_length': 2.6780529461998293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837724', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1527, 'n_words': 316}