Skip to content

Commit 5392e84

Browse files
authored
Improve default setting for svelte3/ignore-styles (#141)
New default: Do not ignore unless a `lang=` or `type=` attribute is present on the style tag
1 parent e68ea65 commit 5392e84

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/preprocess.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ const find_contextual_names = (compiler, node) => {
2222
}
2323
}
2424
};
25+
// ignore_styles when a `lang=` or `type=` attribute is present on the <style> tag
26+
const ignoreStylesFallback = ({ type, lang }) => !!type || !!lang;
2527

2628
// extract scripts to lint from component definition
2729
export const preprocess = text => {
2830
const compiler = processor_options.custom_compiler || default_compiler || (default_compiler = require('svelte/compiler'));
29-
if (processor_options.ignore_styles) {
31+
const ignore_styles = processor_options.ignore_styles ? processor_options.ignore_styles : ignoreStylesFallback;
32+
if (ignore_styles) {
3033
// wipe the appropriate <style> tags in the file
3134
text = text.replace(/<style(\s[^]*?)?>[^]*?<\/style>/gi, (match, attributes = '') => {
3235
const attrs = {};
@@ -38,7 +41,7 @@ export const preprocess = text => {
3841
attrs[attr.slice(0, p)] = '\'"'.includes(attr[p + 1]) ? attr.slice(p + 2, -1) : attr.slice(p + 1);
3942
}
4043
});
41-
return processor_options.ignore_styles(attrs) ? match.replace(/\S/g, ' ') : match;
44+
return ignore_styles(attrs) ? match.replace(/\S/g, ' ') : match;
4245
});
4346
}
4447

0 commit comments

Comments
 (0)