@@ -9,6 +9,7 @@ require('angular-hint');
9
9
10
10
angular . hint . onAny ( function ( data , severity ) {
11
11
window . postMessage ( {
12
+ __fromBatarang : true ,
12
13
module : this . event . split ( ':' ) [ 0 ] ,
13
14
event : this . event ,
14
15
data : data ,
@@ -1363,12 +1364,17 @@ module.exports = function(str) {
1363
1364
return true ;
1364
1365
}
1365
1366
1366
- if ( str . toLowerCase ( ) === str || str . charAt ( 0 ) . toUpperCase ( ) === str . charAt ( 0 ) ) {
1367
+ if ( str . charAt ( 0 ) . toUpperCase ( ) === str . charAt ( 0 ) ) {
1367
1368
angular . hint . emit ( MODULE_NAME , 'The best practice for' +
1368
- ' module names is to use lowerCamelCase. Check the name of "' + str + '".' ,
1369
+ ' module names is to use dot.case or lowerCamelCase. Check the name of "' + str + '".' ,
1369
1370
SEVERITY_SUGGESTION ) ;
1370
1371
return false ;
1371
1372
}
1373
+ if ( str . toLowerCase ( ) === str && str . indexOf ( '.' ) === - 1 ) {
1374
+ angular . hint . emit ( MODULE_NAME , 'Module names should be namespaced' +
1375
+ ' with a dot (app.dashboard) or lowerCamelCase (appDashboard). Check the name of "' + str + '".' , SEVERITY_SUGGESTION ) ;
1376
+ return false ;
1377
+ }
1372
1378
return true ;
1373
1379
} ;
1374
1380
@@ -1627,18 +1633,43 @@ angular.module = function() {
1627
1633
var ngEventAttributes = require ( '../lib/event-directives' ) ,
1628
1634
MODULE_NAME = 'Events' ;
1629
1635
1636
+ /*
1637
+ * Remove string expressions except property accessors.
1638
+ * ex. abc["def"] = "gef"; // `removeStringExp` will remove "gef" but not "def".
1639
+ */
1640
+ function removeStringExp ( str ) {
1641
+ return str . replace ( / " (?: [ ^ " \\ ] | \\ .) * " | ' (?: [ ^ ' \\ ] | \\ .) * ' / g,
1642
+ function ( match , pos , full ) {
1643
+ // this is our lookaround code so that our regex doesn't become so
1644
+ // complicated.
1645
+ if ( pos !== 0 && ( match . length + pos ) !== full . length &&
1646
+ full [ pos - 1 ] === '[' && full [ pos + match . length ] === ']' ) {
1647
+ return match ;
1648
+ }
1649
+ return '' ;
1650
+ } ) ;
1651
+ }
1630
1652
1631
1653
var getFunctionNames = function ( str ) {
1632
1654
if ( typeof str !== 'string' ) {
1633
1655
return [ ] ;
1634
1656
}
1635
- var results = str . replace ( / \s + / g, '' ) . split ( / [ \+ \- \/ \| \< \> \^ = & ! % ~ ; ] / g) . map ( function ( x ) {
1636
- if ( isNaN ( + x ) ) {
1637
- if ( x . match ( / \w + \( .* \) $ / ) ) {
1638
- return x . substr ( 0 , x . indexOf ( '(' ) ) ;
1657
+ // There are still a bunch of corner cases here where we aren't going to be able to handle
1658
+ // but we shouldn't break the user's app and we should handle most common cases.
1659
+ // example of corner cases: we can't check for properties inside of function
1660
+ // arguments like `move(a.b.c)` with the current implementation
1661
+ // or property accessors with parentheses in them
1662
+ // like `prop["hello (world)"] = "test";`.
1663
+ // To fully fix these issues we would need a full blown expression parser.
1664
+ var results = removeStringExp ( str . replace ( / \s + / g, '' ) )
1665
+ . replace ( / \( .* ?\) / g, '' )
1666
+ . split ( / [ \+ \- \/ \| \< \> \^ = & ! % ~ ; ] / g) . map ( function ( x ) {
1667
+ if ( isNaN ( + x ) ) {
1668
+ if ( x . match ( / \w + \( .* \) $ / ) ) {
1669
+ return x . substr ( 0 , x . indexOf ( '(' ) ) ;
1670
+ }
1671
+ return x ;
1639
1672
}
1640
- return x ;
1641
- }
1642
1673
} ) . filter ( function ( x ) {
1643
1674
return x ;
1644
1675
} ) ;
0 commit comments