Skip to content

Commit fade6ca

Browse files
committed
check that svelte3/ignore setting value is an array
1 parent cfa5f80 commit fade6ca

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,24 @@ if (!LinterPath) {
223223
}
224224
const 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
227236
const { verify } = Linter.prototype;
228237
Linter.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

Comments
 (0)