<commit_before>/* jshint node: true, esnext: false */
/* jscs: disable */
'use strict';

var Funnel = require('broccoli-funnel');
var path = require('path');
var intersection = require('./lib/intersection');
var difference = require('./lib/difference');

module.exports = {
  name: 'ember-composable-helpers',

  included: function(app) {
    this._super.included.apply(this, arguments);

    // see: https://github.com/ember-cli/ember-cli/issues/3718
    if (typeof app.import !== 'function' && app.app) {
      app = app.app;
    }

    this.app = app;
    this.app.options = this.app.options || {};

    var config = this.app.options[this.name] || {};
    this.whitelist = this.generateWhitelist(config);
    this.blacklist = this.generateBlacklist(config);
  },

  treeForAddon: function() {
    // see: https://github.com/ember-cli/ember-cli/issues/4463
    var tree = this._super.treeForAddon.apply(this, arguments);
    return this.filterHelpers(tree, new RegExp('^modules\/' + this.name + '\/helpers\/', 'i'));
  },

  filterHelpers: function(tree, regex) {
    var whitelist = this.whitelist;
    var blacklist = this.blacklist;
    var _this = this;

    // exit early if no opts defined
    if (whitelist.length === 0 && blacklist.length === 0) {
      return new Funnel(tree);
    }

    return new Funnel(tree, {
      exclude: [function(name) {
        return _this.exclusionFilter(name, regex, {
          whitelist: whitelist,
          blacklist: blacklist
        });
      }]
    });
  },

  exclusionFilter: function(name, regex, lists) {
    var whitelist = lists.whitelist || [];
    var blacklist = lists.blacklist || [];
    var isAddonHelper = regex.test(name);
    var helperName = path.basename(name, '.js');
    var isWhitelisted = whitelist.indexOf(helperName) !== -1;
    var isBlacklisted = blacklist.indexOf(helperName) !== -1;

    // non-helper, don't exclude
    if (!isAddonHelper) {
      return false;
    }

    // don't exclude if both lists are empty
    if (whitelist.length === 0 && blacklist.length === 0) {
      return false;
    }<commit_msg>Check if whitelist|blacklist exists in filterHelpers (#260)<commit_after>/* jshint node: true, esnext: false */
/* jscs: disable */
'use strict';

var Funnel = require('broccoli-funnel');
var path = require('path');
var intersection = require('./lib/intersection');
var difference = require('./lib/difference');

module.exports = {
  name: 'ember-composable-helpers',

  included: function(app) {
    this._super.included.apply(this, arguments);

    // see: https://github.com/ember-cli/ember-cli/issues/3718
    if (typeof app.import !== 'function' && app.app) {
      app = app.app;
    }

    this.app = app;
    this.app.options = this.app.options || {};

    var config = this.app.options[this.name] || {};
    this.whitelist = this.generateWhitelist(config);
    this.blacklist = this.generateBlacklist(config);
  },

  treeForAddon: function() {
    // see: https://github.com/ember-cli/ember-cli/issues/4463
    var tree = this._super.treeForAddon.apply(this, arguments);
    return this.filterHelpers(tree, new RegExp('^modules\/' + this.name + '\/helpers\/', 'i'));
  },

  filterHelpers: function(tree, regex) {
    var whitelist = this.whitelist;
    var blacklist = this.blacklist;
    var _this = this;

    // exit early if no opts defined
    if ((!whitelist || whitelist.length === 0) && (!blacklist || blacklist.length === 0)) {
      return new Funnel(tree);
    }

    return new Funnel(tree, {
      exclude: [function(name) {
        return _this.exclusionFilter(name, regex, {
          whitelist: whitelist,
          blacklist: blacklist
        });
      }]
    });
  },

  exclusionFilter: function(name, regex, lists) {
    var whitelist = lists.whitelist || [];
    var blacklist = lists.blacklist || [];
    var isAddonHelper = regex.test(name);
    var helperName = path.basename(name, '.js');
    var isWhitelisted = whitelist.indexOf(helperName) !== -1;
    var isBlacklisted = blacklist.indexOf(helperName) !== -1;

    // non-helper, don't exclude
    if (!isAddonHelper) {
      return false;
    }

    // don't exclude if both lists are empty
    if (whitelist.length === 0 && blacklist.length === 0) {
      return false;
    }
{'fraction_non_alphanumeric': 0.15648496240601503, 'fraction_numerical': 0.007283834586466165, 'mean_word_length': 2.9380203515263643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5570931', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1339, 'n_words': 304}