<commit_before>/* global require, module */

const path   = require('path');
const fs     = require('fs');
const leasot = require('leasot');

const DEFAULT_OPTIONS = {
  console:            true,       // default true
  tags:               [],         // default TODO
  reporter:           'markdown', // default markdown
  skipUnsupported:    true,       // skip unsupported files
  suppressFileOutput: false,      // don't output to file,
  relativeFilePath:   true        // display relative file paths in report
};

function TodoWebpackPlugin(options) {
  this.pluginOpts = Object.assign({}, DEFAULT_OPTIONS, options);
}

TodoWebpackPlugin.prototype = {
  constructor: TodoWebpackPlugin,

  apply: function (compiler) {
    compiler.plugin('done', (compilation, callback) => {
      return reporter(this.pluginOpts, compiler._lastCompilationFileDependencies);
    });
  }
};

function reporter(options, files) {
    let todos  = [];
    let output = '';

    files.forEach(file => {
      if (/node_modules|bower_components|vendor/.test(file)) {
        return; // skip node modules
      }
      if (options.skipUnsupported) {
        if (!leasot.isExtSupported(path.extname(file))) {
          return;
        }
      }
      var todo = leasot.parse({
        ext:        path.extname(file),
        content:    fs.readFileSync(file, 'utf8'),
        fileName:   file,
        customTags: options.tags,
        reporter:   options.reporter,
      });
      todos = todos.concat(todo);
    });

    if (options.console) {
      console.log('\n');
      output = leasot.reporter(todos, {reporter: 'table', spacing: 2});
      if (options.relativeFilePath) {
        output = relativePath(output);
      }
      console.log(output); // eslint-disable-line
      console.log('\n\n');
    }

    output = leasot.reporter(todos, {reporter: options.reporter, spacing: 2});

  if (output.length > 0) {
      var outputFilename = options.filename || '';
      if (outputFilename.length === 0) {
        outputFilename = (options.reporter === 'markdown') ? 'TODO.md' : 'todo.' + options.reporter;
        if (options.reporter === 'table') {
          outputFilename = 'todo.txt';
        }
      }

      if (!options.suppressFileOutput) {
        if (options.relativeFilePath) {
          output = relativePath(output);
        }
        fs.writeFile(outputFilename, output, (err) => {
          if (err) throw err;<commit_msg>support for leasot’s inline files option (#9)<commit_after>/* global require, module */

const path   = require('path');
const fs     = require('fs');
const leasot = require('leasot');

const DEFAULT_OPTIONS = {
  console:            true,       // default true
  tags:               [],         // default TODO
  reporter:           'markdown', // default markdown
  skipUnsupported:    true,       // skip unsupported files
  suppressFileOutput: false,      // don't output to file,
  relativeFilePath:   true,       // display relative file paths in report
  withInlineFiles:    false       // parse possible inline files
};

function TodoWebpackPlugin(options) {
  this.pluginOpts = Object.assign({}, DEFAULT_OPTIONS, options);
}

TodoWebpackPlugin.prototype = {
  constructor: TodoWebpackPlugin,

  apply: function (compiler) {
    compiler.plugin('done', (compilation, callback) => {
      return reporter(this.pluginOpts, compiler._lastCompilationFileDependencies);
    });
  }
};

function reporter(options, files) {
    let todos  = [];
    let output = '';

    files.forEach(file => {
      if (/node_modules|bower_components|vendor/.test(file)) {
        return; // skip node modules
      }
      if (options.skipUnsupported) {
        if (!leasot.isExtSupported(path.extname(file))) {
          return;
        }
      }
      var todo = leasot.parse({
        ext:              path.extname(file),
        content:          fs.readFileSync(file, 'utf8'),
        fileName:         file,
        customTags:       options.tags,
        reporter:         options.reporter,
        withInlineFiles:  options.withInlineFiles
      });
      todos = todos.concat(todo);
    });

    if (options.console) {
      console.log('\n');
      output = leasot.reporter(todos, {reporter: 'table', spacing: 2});
      if (options.relativeFilePath) {
        output = relativePath(output);
      }
      console.log(output); // eslint-disable-line
      console.log('\n\n');
    }

    output = leasot.reporter(todos, {reporter: options.reporter, spacing: 2});

  if (output.length > 0) {
      var outputFilename = options.filename || '';
      if (outputFilename.length === 0) {
        outputFilename = (options.reporter === 'markdown') ? 'TODO.md' : 'todo.' + options.reporter;
        if (options.reporter === 'table') {
          outputFilename = 'todo.txt';
        }
      }

      if (!options.suppressFileOutput) {
        if (options.relativeFilePath) {
          output = relativePath(output);
        }
        fs.writeFile(outputFilename, output, (err) => {
          if (err) throw err;
{'fraction_non_alphanumeric': 0.13412935323383085, 'fraction_numerical': 0.0021890547263681594, 'mean_word_length': 2.341755319148936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2285807', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1475, 'n_words': 319}