@@ -13,7 +13,7 @@ const TRACE_INSIGHTS_UI_STRINGS_FILENAME_REGEX = /models\/trace\/insights\/.*\.(
1313 * Returns true iff the passed expression is of the form `UIStrings.bar`.
1414 */
1515function isStandardUIStringsMemberExpression ( expr ) {
16- if ( expr . object . type !== 'Identifier' || expr . object . name !== 'UIStrings' ) {
16+ if ( expr . object . type !== 'Identifier' || ! expr . object . name . startsWith ( 'UIStrings' ) ) {
1717 return false ;
1818 }
1919
@@ -31,10 +31,13 @@ module.exports = {
3131 category : 'Possible Errors' ,
3232 } ,
3333 fixable : 'code' ,
34- schema : [ ] // no options
34+ schema : [ ] , // no options
3535 } ,
36- create : function ( context ) {
37- const filename = ( context . filename ?? context . getFilename ( ) ) . replaceAll ( '\\' , '/' ) ;
36+ create : function ( context ) {
37+ const filename = ( context . filename ?? context . getFilename ( ) ) . replaceAll (
38+ '\\' ,
39+ '/' ,
40+ ) ;
3841 const sourceCode = context . sourceCode ?? context . getSourceCode ( ) ;
3942 const declaredUIStringsKeys = new Map ( ) ;
4043 const usedUIStringsKeys = new Set ( ) ;
@@ -46,7 +49,8 @@ module.exports = {
4649 // some standard formatting. Otherwise we would have to fiddle a lot
4750 // with tokens and whitespace.
4851 let lineToRemoveStart = source . getLocFromIndex ( property . range [ 0 ] ) . line ;
49- const lineToRemoveEnd = source . getLocFromIndex ( property . range [ 1 ] ) . line + 1 ;
52+ const lineToRemoveEnd =
53+ source . getLocFromIndex ( property . range [ 1 ] ) . line + 1 ;
5054
5155 // Are there comments in front of the property?
5256 // Move the line we want to remove to the line of the first comment.
@@ -55,8 +59,14 @@ module.exports = {
5559 lineToRemoveStart = source . getLocFromIndex ( comments [ 0 ] . range [ 0 ] ) . line ;
5660 }
5761
58- const removeStart = source . getIndexFromLoc ( { line : lineToRemoveStart , column : 0 } ) ;
59- const removeEnd = source . getIndexFromLoc ( { line : Math . min ( lineToRemoveEnd , source . lines . length ) , column : 0 } ) ;
62+ const removeStart = source . getIndexFromLoc ( {
63+ line : lineToRemoveStart ,
64+ column : 0 ,
65+ } ) ;
66+ const removeEnd = source . getIndexFromLoc ( {
67+ line : Math . min ( lineToRemoveEnd , source . lines . length ) ,
68+ column : 0 ,
69+ } ) ;
6070 return fixer . removeRange ( [ removeStart , removeEnd ] ) ;
6171 }
6272
@@ -70,12 +80,17 @@ module.exports = {
7080 return ;
7181 }
7282
73- if ( ! l10nHelper . isUIStringsVariableDeclarator ( context , variableDeclarator ) ) {
83+ if (
84+ ! l10nHelper . isUIStringsVariableDeclarator ( context , variableDeclarator )
85+ ) {
7486 return ;
7587 }
7688
7789 for ( const property of variableDeclarator . init . expression . properties ) {
78- if ( property . type !== 'Property' || property . key . type !== 'Identifier' ) {
90+ if (
91+ property . type !== 'Property' ||
92+ property . key . type !== 'Identifier'
93+ ) {
7994 continue ;
8095 }
8196 declaredUIStringsKeys . set ( property . key . name , property ) ;
@@ -87,7 +102,7 @@ module.exports = {
87102 }
88103 usedUIStringsKeys . add ( memberExpression . property . name ) ;
89104 } ,
90- 'Program:exit' : function ( ) {
105+ 'Program:exit' : function ( ) {
91106 for ( const usedKey of usedUIStringsKeys ) {
92107 declaredUIStringsKeys . delete ( usedKey ) ;
93108 }
@@ -101,5 +116,5 @@ module.exports = {
101116 }
102117 } ,
103118 } ;
104- }
119+ } ,
105120} ;
0 commit comments