<commit_before>/* @flow */

import path from 'path'

import State from '../State'
import File from '../File'
import Rule from '../Rule'

import type { Command, OptionsInterface, Phase } from '../types'

export default class CopyTargetsToRoot extends Rule {
  static parameterTypes: Array<Set<string>> = [new Set(['*'])]
  static description: string = 'Copy targets to root directory.'
  static alwaysEvaluate: boolean = true

  static async appliesToParameters (state: State, command: Command, phase: Phase, options: OptionsInterface, ...parameters: Array<File>): Promise<boolean> {
    return !!options.copyTargetsToRoot &&
      parameters.every(file => state.targets.has(file.filePath) && path.dirname(file.filePath) !== '.')
  }

  async initialize () {
    this.removeTarget(this.firstParameter.filePath)
    await this.addResolvedTarget('$BASE_0')
  }

  async run () {
    const filePath = this.resolvePath('$ROOTDIR/$BASE_0')
    await this.firstParameter.copy(filePath)
    await this.getOutput(filePath)
    return true
  }
}<commit_msg>Add comments and check for virtual files<commit_after>/* @flow */

import path from 'path'

import State from '../State'
import File from '../File'
import Rule from '../Rule'

import type { Command, OptionsInterface, Phase } from '../types'

export default class CopyTargetsToRoot extends Rule {
  static parameterTypes: Array<Set<string>> = [new Set(['*'])]
  static description: string = 'Copy targets to root directory.'
  static alwaysEvaluate: boolean = true

  static async appliesToParameters (state: State, command: Command, phase: Phase, options: OptionsInterface, ...parameters: Array<File>): Promise<boolean> {
    return !!options.copyTargetsToRoot &&
      parameters.every(file => !file.virtual && state.targets.has(file.filePath) && path.dirname(file.filePath) !== '.')
  }

  async initialize () {
    // Remove the old target and replace with the new one.
    this.removeTarget(this.firstParameter.filePath)
    await this.addResolvedTarget('$BASE_0')
  }

  async run () {
    // Copy the target to it's new location and add the result as an output.
    const filePath = this.resolvePath('$ROOTDIR/$BASE_0')
    await this.firstParameter.copy(filePath)
    await this.getOutput(filePath)
    return true
  }
}
{'fraction_non_alphanumeric': 0.12884784520668427, 'fraction_numerical': 0.001759014951627089, 'mean_word_length': 4.1008968609865475, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '1205472', 'n_tokens_mistral': 648, 'n_tokens_neox': 643, 'n_words': 197}