'use strict';

var helpers = require('../helpers'),
    yaml = require('js-yaml'),
    fs = require('fs'),
    path = require('path');

var pseudoElements = yaml.safeLoad(
      fs.readFileSync(path.join(__dirname, '../../data', 'pseudoElements.yml'), 'utf8')
    ).split(' '),
    pseudoClasses = yaml.safeLoad(
      fs.readFileSync(path.join(__dirname, '../../data', 'pseudoClasses.yml'), 'utf8')
    ).split(' ');

/**
 * Get prefix free version of string
 *
 * @param {Object|string} name - The value to test
 * @returns {string} A prefix free version of the string
 */
var prefixFree = function prefixFree (name) {
  return typeof name === 'string' && name.charAt(0) === '-' ? helpers.stripPrefix(name) : name;
};

/**
 * Check if string is pseudo-element
 *
 * @param {string} name - The name to check
 * @returns {Boolean} Whether or not name is pseudo-element
 */
var isPseudoElement = function isPseudoElement (name) {
  return pseudoElements.indexOf(prefixFree(name)) !== -1;
};

/**
 * Check if string is pseudo-class
 *
 * @param {string} name - The name to check
 * @returns {Boolean} Whether or not name is pseudo-class
 */
var isPseudoClass = function isPseudoClass (name) {
  return pseudoClasses.indexOf(prefixFree(name)) !== -1;
};

module.exports = {
  'name': 'pseudo-element',
  'detect': function (ast, parser) {
    var result = [];

    ast.traverseByType('pseudoClass', function (node) {
      if (isPseudoElement(node.content[0].content)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Pseudo-elements must start with double colons',
          'severity': parser.severity
        });
      }
    });

    ast.traverseByType('pseudoElement', function (node) {
      if (isPseudoClass(node.content[0].content)) {
        result = helpers.addUnique(result, {
          'ruleId': parser.rule.name,
          'line': node.start.line,
          'column': node.start.column,
          'message': 'Pseudo-classes must start with a single colon',
          'severity': parser.severity
        });
      }
    });

    return result;
  }
};

@@ -423,41 +423,128 @@
 %0A * 
-Get prefix free version of string
+Check if the given argument is a prefixed string. If it is we return an unprefixed%0A * version, else return it unmodified
 %0A *%0A
@@ -808,34 +808,55 @@
 %0A/**%0A * 
-Check if string is
+Determine if the given string matches a
  pseudo-
@@ -1103,26 +1103,47 @@
 %0A * 
-Check if string is
+Determine if the given string matches a
  pse

Update comments