<commit_before>'use strict'

const
  helpers = require('./helpers'),
  path = require('path'),
  sh = require('shelljs'),
  compiler = global.compiler || require('riot-compiler'),
  constants = require('./const'),
  NO_FILE_FOUND = constants.NO_FILE_FOUND,
  PREPROCESSOR_NOT_REGISTERED = constants.PREPROCESSOR_NOT_REGISTERED

/**
 * Base class that will extended to handle all the cli tasks
 */
class Task {
  constructor(opt) {
    // Run only once
    /* istanbul ignore next */
    if (this.called) return
    this.called = true

    this.error = null

    // create a regex to figure out whether our user
    // wants to compile a single tag or some tags in a folder
    this.extRegex = new RegExp(`\\.${opt.ext || 'tag' }$`)

    // make sure the parsers object is always valid
    opt.parsers = helpers.extend(
      compiler.parsers,
      opt.parsers || {}
    )

    if (opt.compiler) {
      // validate the compiler options
      const err = this.validate(opt.compiler, opt.parsers)
      if (err) return this.handleError(err, opt.isCli)
    } else {
      // make sure to set always the compiler options
      opt.compiler = {}
    }

    if (!opt.stdin) {
      // Resolve to absolute paths
      opt.from = path.resolve(opt.from)
      // Check if the path exsists
      if (!sh.test('-e', opt.from)) return this.handleError(NO_FILE_FOUND, opt.isCli)
    } else if (opt.from) {
      helpers.log('Stdin will be used instead of the files/dirs specified.')
      delete opt.from
    }

    if (!opt.stdout) {
      // If no target dir, default to source dir
      const from = opt.from || ''
      opt.to = opt.to || (this.extRegex.test(from) ? path.dirname(from) : from)
      // Resolve to absolute paths
      opt.to = path.resolve(opt.to)
    } else if (opt.to) {
      helpers.log('Stdout will be used instead of the files/dirs specified.')
      delete opt.to
    }

    /**
     * Determine the input/output types
     * f: file
     * d: directory
     * s: stdin/stdout
     */<commit_msg>Avoids negative conditions<commit_after>'use strict'

const
  helpers = require('./helpers'),
  path = require('path'),
  sh = require('shelljs'),
  compiler = global.compiler || require('riot-compiler'),
  constants = require('./const'),
  NO_FILE_FOUND = constants.NO_FILE_FOUND,
  PREPROCESSOR_NOT_REGISTERED = constants.PREPROCESSOR_NOT_REGISTERED

/**
 * Base class that will extended to handle all the cli tasks
 */
class Task {
  constructor(opt) {
    // Run only once
    /* istanbul ignore next */
    if (this.called) return
    this.called = true

    this.error = null

    // create a regex to figure out whether our user
    // wants to compile a single tag or some tags in a folder
    this.extRegex = new RegExp(`\\.${opt.ext || 'tag' }$`)

    // make sure the parsers object is always valid
    opt.parsers = helpers.extend(
      compiler.parsers,
      opt.parsers || {}
    )

    if (opt.compiler) {
      // validate the compiler options
      const err = this.validate(opt.compiler, opt.parsers)
      if (err) return this.handleError(err, opt.isCli)
    } else {
      // make sure to set always the compiler options
      opt.compiler = {}
    }

    if (opt.stdin) {
      if (opt.from) {
        helpers.log('Stdin will be used instead of the files/dirs specified.')
        delete opt.stdin
      }
    } else {
      // Resolve to absolute paths
      opt.from = path.resolve(opt.from)
      // Check if the path exsists
      if (!sh.test('-e', opt.from)) return this.handleError(NO_FILE_FOUND, opt.isCli)
    }

    if (opt.stdout) {
      if (opt.to) {
        helpers.log('Stdout will be used instead of the files/dirs specified.')
        delete opt.to
      }
    } else {
      // If no target dir, default to source dir
      const from = opt.from || ''
      opt.to = opt.to || (this.extRegex.test(from) ? path.dirname(from) : from)
      // Resolve to absolute paths
      opt.to = path.resolve(opt.to)
    }

    /**
     * Determine the input/output types
     * f: file
     * d: directory
     * s: stdin/stdout
     */
{'fraction_non_alphanumeric': 0.12168792934249265, 'fraction_numerical': 0.0, 'mean_word_length': 2.339066339066339, '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': '5340704', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1265, 'n_words': 378}