<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

const jshint = require('jshint').JSHINT;
const Promise = require('bluebird');
const walk = require('walk');

// read jshintrc
var jshintrc = JSON.parse(fs.readFileSync(path.join(__dirname, '../.jshintrc'))
    .toString());
var filesToLint = [];

var options = {
  listeners: {
    file: function(root, fStat, next) {
      var f = path.join(root, fStat.name);
      if (/\.js$/.test(f)) {
        filesToLint.push(f);
      }
      next();
    }
  }
};

module.exports = {



  'jshint': {

    'before': function(done) {
      var w = walk.walkSync(path.join(__dirname, '../lib'));
      w.on('file', options.listeners.file);
      w = walk.walkSync(__dirname);
      w.on('file', options.listeners.file);
      w.once('end', done);
    },

    'should yield no errors': function(done) {
      this.slow(800); // can be slow reading all the files :(
      var errors = [];

      var read = Promise.promisify(fs.readFile);
      Promise.all(filesToLint.map(function(fileName) {
        return read(String(fileName)).then(function(data) {
          var f = path.relative(process.cwd(), fileName);
          if (!jshint(String(data), jshintrc)) {
            jshint.errors.forEach(function(e) {
              errors.push(
                util.format("%s %s:%d - %s", e.id, f, e.line, e.reason));
            });
          }
        });<commit_msg>fix walk.walkSync<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

const jshint = require('jshint').JSHINT;
const Promise = require('bluebird');
const walk = require('walk');

// read jshintrc
var jshintrc = JSON.parse(fs.readFileSync(path.join(__dirname, '../.jshintrc'))
    .toString());
var filesToLint = [];

var options = {
  listeners: {
    file: function(root, fStat, next) {
      var f = path.join(root, fStat.name);
      if (/\.js$/.test(f)) {
        filesToLint.push(f);
      }
      next();
    }
  }
};

module.exports = {



  'jshint': {

    'before': function() {
      walk.walkSync(path.join(__dirname, '../lib'), options);
      walk.walkSync(__dirname, options);
    },

    'should yield no errors': function(done) {
      this.slow(800); // can be slow reading all the files :(
      var errors = [];

      var read = Promise.promisify(fs.readFile);
      Promise.all(filesToLint.map(function(fileName) {
        return read(String(fileName)).then(function(data) {
          var f = path.relative(process.cwd(), fileName);
          if (!jshint(String(data), jshintrc)) {
            jshint.errors.forEach(function(e) {
              errors.push(
                util.format("%s %s:%d - %s", e.id, f, e.line, e.reason));
            });
          }
        });
{'fraction_non_alphanumeric': 0.1668228678537957, 'fraction_numerical': 0.0043736332396126214, 'mean_word_length': 2.5459579180509415, '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': '1591285', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1039, 'n_words': 254}