Skip to content

Commit

Permalink
Update to ES6 var/let, see #786
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Sep 23, 2019
1 parent d514514 commit 8ddfb08
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions eslint/rules/string-require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = function( context ) {

// Adapted from Stack Overflow, see http://stackoverflow.com/questions/25085306/javascript-space-separated-string-to-camelcase
function toCamelCase( string ) {
var out = '';
let out = '';

// Add whitespace after each digit so that strings like myString1pattern will get camelcased with uppercase P
var withWhitespaceAfterDigits = string.replace( /\d/g, function( a ) {return a + ' ';} ).trim();
const withWhitespaceAfterDigits = string.replace( /\d/g, function( a ) {return a + ' ';} ).trim();

// Split on whitespace, remove whitespace and uppercase the first word in each term
withWhitespaceAfterDigits.split( ' ' ).forEach( function( element, index ) {
Expand Down Expand Up @@ -47,24 +47,24 @@ module.exports = function( context ) {
node.declarations[ 0 ].init.arguments.length > 0 ) {
if ( node.declarations[ 0 ].init &&
node.declarations[ 0 ].init.callee.name === 'require' ) {
var varName = node.declarations[ 0 ].id.name;
var rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;
const varName = node.declarations[ 0 ].id.name;
const rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;

if ( rhs && rhs.indexOf( 'string!' ) === 0 ) {

var lastSlash = rhs.lastIndexOf( '/' );
var key = rhs.substring( lastSlash + 1 );
const lastSlash = rhs.lastIndexOf( '/' );
let key = rhs.substring( lastSlash + 1 );

// For a11y strings, no need to prefix vars with "a11y"
if ( key.indexOf( 'a11y.' ) === 0 ) {
key = key.replace( 'a11y.', '' );
}

// Convert various separators to whitespace
var withWhitespace = key.replace( /[\.\-\_]/g, ' ' );
const withWhitespace = key.replace( /[.\-_]/g, ' ' );

// Convert whitespace delimited string to camel case and append string suffix
var desiredVarName = toCamelCase( withWhitespace ) + 'String';
const desiredVarName = toCamelCase( withWhitespace ) + 'String';

if ( varName !== desiredVarName ) {
context.report( {
Expand Down

0 comments on commit 8ddfb08

Please sign in to comment.