@@ -29,30 +29,6 @@ const CAPS_ALLOWED = [
2929 "BigInt" ,
3030] ;
3131
32- /**
33- * A reducer function to invert an array to an Object mapping the string form of the key, to `true`.
34- * @param {Object } map Accumulator object for the reduce.
35- * @param {string } key Object key to set to `true`.
36- * @returns {Object } Returns the updated Object for further reduction.
37- */
38- function invert ( map , key ) {
39- map [ key ] = true ;
40- return map ;
41- }
42-
43- /**
44- * Creates an object with the cap is new exceptions as its keys and true as their values.
45- * @param {Object } config Rule configuration
46- * @returns {Object } Object with cap is new exceptions.
47- */
48- function calculateCapIsNewExceptions ( config ) {
49- const capIsNewExceptions = Array . from (
50- new Set ( [ ...config . capIsNewExceptions , ...CAPS_ALLOWED ] ) ,
51- ) ;
52-
53- return capIsNewExceptions . reduce ( invert , { } ) ;
54- }
55-
5632//------------------------------------------------------------------------------
5733// Rule Definition
5834//------------------------------------------------------------------------------
@@ -125,12 +101,15 @@ module.exports = {
125101 const [ config ] = context . options ;
126102 const skipProperties = ! config . properties ;
127103
128- const newIsCapExceptions = config . newIsCapExceptions . reduce ( invert , { } ) ;
104+ const newIsCapExceptions = new Set ( config . newIsCapExceptions ) ;
129105 const newIsCapExceptionPattern = config . newIsCapExceptionPattern
130106 ? new RegExp ( config . newIsCapExceptionPattern , "u" )
131107 : null ;
132108
133- const capIsNewExceptions = calculateCapIsNewExceptions ( config ) ;
109+ const capIsNewExceptions = new Set ( [
110+ ...config . capIsNewExceptions ,
111+ ...CAPS_ALLOWED ,
112+ ] ) ;
134113 const capIsNewExceptionPattern = config . capIsNewExceptionPattern
135114 ? new RegExp ( config . capIsNewExceptionPattern , "u" )
136115 : null ;
@@ -178,16 +157,16 @@ module.exports = {
178157
179158 /**
180159 * Check if capitalization is allowed for a CallExpression
181- * @param {Object } allowedMap Object mapping calleeName to a Boolean
160+ * @param {Set<string> } allowedNames Set of allowed callee names
182161 * @param {ASTNode } node CallExpression node
183162 * @param {string } calleeName Capitalized callee name from a CallExpression
184163 * @param {Object } pattern RegExp object from options pattern
185164 * @returns {boolean } Returns true if the callee may be capitalized
186165 */
187- function isCapAllowed ( allowedMap , node , calleeName , pattern ) {
166+ function isCapAllowed ( allowedNames , node , calleeName , pattern ) {
188167 const sourceText = sourceCode . getText ( node . callee ) ;
189168
190- if ( allowedMap [ calleeName ] || allowedMap [ sourceText ] ) {
169+ if ( allowedNames . has ( calleeName ) || allowedNames . has ( sourceText ) ) {
191170 return true ;
192171 }
193172
0 commit comments