/**
 * @fileoverview Utilities for working with ESLint syntax tree.
 */

'use strict';

const {UnderscoreForm} = require('./types');

/**
 * Determines whether two adjacent tokens are on the same line.
 * @param {(!ESLint.ASTNode|!Espree.Token)} left The left token object.
 * @param {(!ESLint.ASTNode|!Espree.Token)} right The right token object.
 * @returns {boolean} Whether or not the tokens are on the same line.
 */
function isTokenOnSameLine(left, right) {
  return left.loc.end.line === right.loc.start.line;
}

/**
 * Checks if a string contains an underscore.
 * @param {string} name The string to check.
 * @returns {boolean} if the string is underscored
 */
function isUnderscored(name) {
  return name.indexOf("_") > -1;
}


/**
 * Determine the type of underscore that an indentifer contains.
 * @param {string} name The string to check.
 * @return {!UnderscoreForm} the type of underscored identifier.
 */
function categorizeUnderscoredIdentifier(name) {
  if (name == "") {
    return UnderscoreForm.NO_UNDERSCORE;
  } else if (name.toUpperCase() == name) {
    return UnderscoreForm.CONSTANT;
  } else if (name.indexOf('_') == -1) {
    // This check must come after the constant check otherwise we wrongly
    // categorize identifiers like ALLCAPS.
    return UnderscoreForm.NO_UNDERSCORE;
  } else if (name === 'var_args') {
    return UnderscoreForm.VAR_ARGS;
  } else if (name.substring(0, 4) === 'opt_') {
    return UnderscoreForm.OPT_PREFIX;
  } else if (name[0] == '_') {
    return UnderscoreForm.LEADING;
  } else if (name[name.length - 1] == '_') {
    return UnderscoreForm.TRAILING;
  } else {
    return UnderscoreForm.OTHER;
  }
}


module.exports = {
  categorizeUnderscoredIdentifier,
  isTokenOnSameLine,
  isUnderscored,
};

@@ -986,33 +986,37 @@
 %22) %7B%0A    return 
-U
+'no_u
 nderscoreForm.NO
@@ -1008,34 +1008,17 @@
 derscore
-Form.NO_UNDERSCORE
+'
 ;%0A  %7D el
@@ -1069,31 +1069,18 @@
 urn 
-UnderscoreForm.CONSTANT
+'constant'
 ;%0A  
@@ -1238,33 +1238,37 @@
 APS.%0A    return 
-U
+'no_u
 nderscoreForm.NO
@@ -1264,26 +1264,9 @@
 core
-Form.NO_UNDERSCORE
+'
 ;%0A  
@@ -1314,31 +1314,18 @@
 urn 
-UnderscoreForm.VAR_ARGS
+'var_args'
 ;%0A  
@@ -1385,33 +1385,20 @@
 urn 
-UnderscoreForm.OPT_PREFIX
+'opt_prefix'
 ;%0A  
@@ -1441,30 +1441,17 @@
 urn 
-UnderscoreForm.LEADING
+'leading'
 ;%0A  
@@ -1508,32 +1508,19 @@
 urn 
-UnderscoreForm.TRAILING;
+'trailing;'
 %0A  %7D
@@ -1542,28 +1542,15 @@
 urn 
-UnderscoreForm.OTHER
+'other'
 ;%0A  

return enum strings directly