@@ -223,20 +223,24 @@ if (!LinterPath) {
223223}
224224const Linter = require ( LinterPath ) ;
225225
226+ // get an array-valued setting from ESLint config
227+ const getArraySetting = ( config , key , defaultValue ) => {
228+ const value = config && config . settings && config . settings [ key ] || defaultValue ;
229+ if ( ! Array . isArray ( value ) ) {
230+ throw new Error ( `Setting ${ key } is not an array` ) ;
231+ }
232+ return value ;
233+ } ;
234+
226235// patch Linter#verify
227236const { verify } = Linter . prototype ;
228237Linter . prototype . verify = function ( code , config , options ) {
229238 if ( typeof options === 'string' ) {
230239 options = { filename : options } ;
231240 }
232241 if ( options && options . filename ) {
233- // get 'svelte3/extensions' settings value
234- const extensions = config && config . settings && config . settings [ 'svelte3/extensions' ] || [ '.svelte' ] ;
235- if ( ! Array . isArray ( extensions ) ) {
236- throw new Error ( 'Setting svelte3/extensions is not an array' ) ;
237- }
238- ignore = config && config . settings && config . settings [ 'svelte3/ignore' ] || [ ] ;
239-
242+ const extensions = getArraySetting ( config , 'svelte3/extensions' , [ '.svelte' ] ) ;
243+ ignore = getArraySetting ( config , 'svelte3/ignore' , [ ] ) ;
240244 if ( extensions . some ( extension => options . filename . endsWith ( extension ) ) ) {
241245 // lint this Svelte file
242246 options = Object . assign ( { } , options , { preprocess, postprocess } ) ;
0 commit comments