{"action":"created","issue":{"url":"https://api.github.com/repos/phetsims/chipper/issues/396","labels_url":"https://api.github.com/repos/phetsims/chipper/issues/396/labels{/name}","comments_url":"https://api.github.com/repos/phetsims/chipper/issues/396/comments","events_url":"https://api.github.com/repos/phetsims/chipper/issues/396/events","html_url":"https://github.com/phetsims/chipper/issues/396","id":114291677,"number":396,"title":"Prevent naming mismatches when using the string plugin","user":{"login":"samreid","id":679486,"avatar_url":"https://avatars.githubusercontent.com/u/679486?v=3","gravatar_id":"","url":"https://api.github.com/users/samreid","html_url":"https://github.com/samreid","followers_url":"https://api.github.com/users/samreid/followers","following_url":"https://api.github.com/users/samreid/following{/other_user}","gists_url":"https://api.github.com/users/samreid/gists{/gist_id}","starred_url":"https://api.github.com/users/samreid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samreid/subscriptions","organizations_url":"https://api.github.com/users/samreid/orgs","repos_url":"https://api.github.com/users/samreid/repos","events_url":"https://api.github.com/users/samreid/events{/privacy}","received_events_url":"https://api.github.com/users/samreid/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"samreid","id":679486,"avatar_url":"https://avatars.githubusercontent.com/u/679486?v=3","gravatar_id":"","url":"https://api.github.com/users/samreid","html_url":"https://github.com/samreid","followers_url":"https://api.github.com/users/samreid/followers","following_url":"https://api.github.com/users/samreid/following{/other_user}","gists_url":"https://api.github.com/users/samreid/gists{/gist_id}","starred_url":"https://api.github.com/users/samreid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samreid/subscriptions","organizations_url":"https://api.github.com/users/samreid/orgs","repos_url":"https://api.github.com/users/samreid/repos","events_url":"https://api.github.com/users/samreid/events{/privacy}","received_events_url":"https://api.github.com/users/samreid/received_events","type":"User","site_admin":false},"milestone":null,"comments":29,"created_at":"2015-10-30T15:25:53Z","updated_at":"2015-11-04T00:20:38Z","closed_at":null,"body":"During the Bending Light code review, @jessegreenberg pointed out several lines in Bending Light where there was a mismatch between the string key and the var declared in the require statement.  For instance:\r\n\r\n```js\r\nvar miss = require( 'string!BENDING_LIGHT/miss' );\r\n```\r\n\r\nand \r\n```js\r\nvar c_units = require( 'string!BENDING_LIGHT/c_units' );\r\n```\r\n\r\nI wrote a eslint rule that requires the the following to be true: `varName+'String' === keyName`.\r\n\r\nHere is the code for the rule:\r\n\r\n```js\r\n// Copyright 2002-2015, University of Colorado Boulder\r\n/**\r\n * @fileoverview Rule to check that a require statement assigns to the correct variable name for the string! plugin.\r\n * @author Sam Reid (PhET Interactive Simulations)\r\n * @copyright 2015 University of Colorado Boulder\r\n */\r\n\r\n//------------------------------------------------------------------------------\r\n// Rule Definition\r\n//------------------------------------------------------------------------------\r\n\r\nmodule.exports = function( context ) {\r\n  'use strict';\r\n\r\n  var endsWith = function( string, s ) {\r\n    return string.length >= s.length && string.substring( string.length - s.length ) === s;\r\n  };\r\n  return {\r\n\r\n    // Similar to the require-statement-match.js, please visit that file for AST example\r\n    VariableDeclaration: function requireStatementMatch( node ) {\r\n\r\n      if ( node.declarations &&\r\n           node.declarations.length > 0 &&\r\n           node.declarations[ 0 ].init &&\r\n           node.declarations[ 0 ].init.arguments &&\r\n           node.declarations[ 0 ].init.arguments.length > 0 ) {\r\n        if ( node.declarations[ 0 ].init &&\r\n             node.declarations[ 0 ].init.callee.name === 'require' ) {\r\n          var lhs = node.declarations[ 0 ].id.name;\r\n          var rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;\r\n\r\n          if ( rhs.indexOf( 'string!' ) === 0 ) {\r\n\r\n            var lastSlash = rhs.lastIndexOf( '/' );\r\n            var tail = rhs.substring( lastSlash + 1 );\r\n            var lhsEndsWithString = endsWith( lhs, 'String' );\r\n            var startsOK = lhs.indexOf( tail ) === 0;\r\n            var midStringOK = lhs.length === (tail + 'String').length;\r\n            if ( !lhsEndsWithString || !startsOK || !midStringOK ) {\r\n              context.report( {\r\n                node: node,\r\n                loc: node.loc.start,\r\n                message: 'Mismatched var in require(string!), ' +\r\n                         'key=' + tail + ', ' +\r\n                         'var=' + lhs\r\n              } );\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  };\r\n};\r\n\r\nmodule.exports.schema = [\r\n  // JSON Schema for rule options goes here\r\n];\r\n```"},"comment":{"url":"https://api.github.com/repos/phetsims/chipper/issues/comments/153531910","html_url":"https://github.com/phetsims/chipper/issues/396#issuecomment-153531910","issue_url":"https://api.github.com/repos/phetsims/chipper/issues/396","id":153531910,"user":{"login":"pixelzoom","id":3046552,"avatar_url":"https://avatars.githubusercontent.com/u/3046552?v=3","gravatar_id":"","url":"https://api.github.com/users/pixelzoom","html_url":"https://github.com/pixelzoom","followers_url":"https://api.github.com/users/pixelzoom/followers","following_url":"https://api.github.com/users/pixelzoom/following{/other_user}","gists_url":"https://api.github.com/users/pixelzoom/gists{/gist_id}","starred_url":"https://api.github.com/users/pixelzoom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixelzoom/subscriptions","organizations_url":"https://api.github.com/users/pixelzoom/orgs","repos_url":"https://api.github.com/users/pixelzoom/repos","events_url":"https://api.github.com/users/pixelzoom/events{/privacy}","received_events_url":"https://api.github.com/users/pixelzoom/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T00:20:38Z","updated_at":"2015-11-04T00:20:38Z","body":"Here's another problematic case, from graphing-lines:\r\n\r\n```\r\n/Users/cmalley/PhET/GitHub/graphing-lines/js/common/view/PointToolNode.js\r\n  27:3  error  Mismatched var in require(string!), key=point.xy, var=pointXYString, desiredVar=pointXyString  string-require-statement-match\r\n```"}}