Skip to content

Commit c361e75

Browse files
committed
add svelte3/compiler-options setting
1 parent 1e4c888 commit c361e75

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ This can be `true` or `false` or an array of Svelte compiler warning codes or a
4040

4141
The default is to not ignore any warnings.
4242

43+
### `svelte3/compiler-options`
44+
45+
Most compiler options do not affect the validity of compiled components, but a couple of them can. If you are compiling to custom elements, or otherwise need to control how the plugin compiles the components it's linting, you can use this setting.
46+
47+
This can be an object of compiler options or a function that accepts a file path and returns an object of compiler options.
48+
49+
The default is to compile with `{ generate: false }`.
50+
4351
### `svelte3/ignore-styles`
4452

4553
If you're using some sort of preprocessor on the component styles, then it's likely that when this plugin calls the Svelte compiler on your component, it will throw an exception. In a perfect world, this plugin would be able to apply the preprocessor to the component and then use source maps to translate any warnings back to the original source. In the current reality, however, you can instead simply disregard styles written in anything other than standard CSS. You won't get warnings about the styles from the linter, but your application will still use them (of course) and compiler warnings will still appear in your build logs.

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { compile } = require('svelte/compiler');
44

5-
let messages, transformed_code, ignore_warnings, module_info, instance_info;
5+
let compiler_options, messages, transformed_code, ignore_warnings, module_info, instance_info;
66

77
// get the total length, number of lines, and length of the last line of a string
88
const get_offsets = str => {
@@ -134,7 +134,7 @@ const preprocess = text => {
134134
// get information about the component
135135
let result;
136136
try {
137-
result = compile(text, { generate: false });
137+
result = compile(text, compiler_options);
138138
} catch ({ name, message, start, end }) {
139139
// convert the error to a linting message, store it, and return
140140
messages = [
@@ -241,7 +241,7 @@ const get_setting_function = (config, key, default_value) => {
241241
}
242242
const value = config.settings[key];
243243
return typeof value === 'function' ? value :
244-
typeof value === 'boolean' ? () => value :
244+
typeof value === 'boolean' || typeof value === 'object' ? () => value :
245245
Array.isArray(value) ? Array.prototype.includes.bind(value) :
246246
v => v === value;
247247
};
@@ -269,6 +269,8 @@ Linter.prototype.verify = function(code, config, options) {
269269
return ignore_styles(attrs) ? match.replace(/\S/g, ' ') : match;
270270
});
271271
}
272+
const compiler_options_setting = get_setting_function(config, 'svelte3/compiler-options', false);
273+
compiler_options = compiler_options_setting ? Object.assign({ generate: false }, compiler_options_setting(options.filename)) : { generate: false };
272274
}
273275
}
274276

0 commit comments

Comments
 (0)