<commit_before>const _ = require('lodash');
const fs = require('mz/fs');
const globby = require('globby');
const { parse } = require('scss-parser');
const createQueryAst = require('query-ast');

// Local
const createBem = require('./bem.js');
const createResult = require('./result.js');
const createOptions = require('./options.js');

// AST
function eachWrapper(wrapper, callback) {
  _.each(wrapper.nodes, callback);
}

function nodeToString(node) {
  const result = [];

  if (node.type === 'id') {
    result.push('#');
  } else if (node.type === 'class') {
    result.push('.');
  } else if (node.type === 'pseudo_class') {
    result.push(':');
  } else if (node.type === 'arguments') {
    result.push('(');
  }

  if (typeof node.value === 'string') {
    result.push(node.value);
  } else {
    result.push(node.value.reduce((acc, child) => acc + nodeToString(child), ''));
  }

  if (node.type === 'arguments') {
    result.push(')');
  }

  return result.join('');
}

function eachClassName($, fn) {
  eachWrapper($('class').find('identifier'), (wrapper) => {
    const className = wrapper.node.value;
    fn(className, wrapper);
  });
}

function isClassFollowedByAPseudoClass($wrapper) {
  return $wrapper.parent().next().get(0).type === 'pseudo_class';
}

function getIsIsolatedBlock(fileOptions, blockName) {
  return fileOptions.excludeBlock.indexOf(blockName) === -1;
}

function bemLintFileData(filePath, data, result, blockList, options) {
  const fileOptions = options.getFileOptions(filePath);
  const bem = createBem(fileOptions);
  const moduleName = fileOptions.name;
  const blockName = bem.getBlockNameFromFile(filePath);
  const isIsolatedBlock = getIsIsolatedBlock(fileOptions, blockName);
  if (isIsolatedBlock) {
    result.addBlock(moduleName, blockName);
  }
  const ast = parse(data);<commit_msg>Add attribute support when converting selector to string<commit_after>const _ = require('lodash');
const fs = require('mz/fs');
const globby = require('globby');
const { parse } = require('scss-parser');
const createQueryAst = require('query-ast');

// Local
const createBem = require('./bem.js');
const createResult = require('./result.js');
const createOptions = require('./options.js');

// AST
function eachWrapper(wrapper, callback) {
  _.each(wrapper.nodes, callback);
}

function nodeToString(node) {
  const result = [];

  if (node.type === 'id') {
    result.push('#');
  } else if (node.type === 'class') {
    result.push('.');
  } else if (node.type === 'pseudo_class') {
    result.push(':');
  } else if (node.type === 'arguments') {
    result.push('(');
  } else if (node.type === 'attribute') {
    result.push('[');
  }

  if (typeof node.value === 'string') {
    result.push(node.value);
  } else {
    result.push(node.value.reduce((acc, child) => acc + nodeToString(child), ''));
  }

  if (node.type === 'arguments') {
    result.push(')');
  } else if (node.type === 'attribute') {
    result.push(']');
  }

  return result.join('');
}

function eachClassName($, fn) {
  eachWrapper($('class').find('identifier'), (wrapper) => {
    const className = wrapper.node.value;
    fn(className, wrapper);
  });
}

function isClassFollowedByAPseudoClass($wrapper) {
  return $wrapper.parent().next().get(0).type === 'pseudo_class';
}

function getIsIsolatedBlock(fileOptions, blockName) {
  return fileOptions.excludeBlock.indexOf(blockName) === -1;
}

function bemLintFileData(filePath, data, result, blockList, options) {
  const fileOptions = options.getFileOptions(filePath);
  const bem = createBem(fileOptions);
  const moduleName = fileOptions.name;
  const blockName = bem.getBlockNameFromFile(filePath);
  const isIsolatedBlock = getIsIsolatedBlock(fileOptions, blockName);
  if (isIsolatedBlock) {
    result.addBlock(moduleName, blockName);
  }
  const ast = parse(data);
{'fraction_non_alphanumeric': 0.17958757504568, 'fraction_numerical': 0.0010441138084051162, 'mean_word_length': 4.443181818181818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1396107', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1217, 'n_words': 254}