Skip to content

Commit 9596c5d

Browse files
committed
[fix] ignore css-unused-selector rule if <style global>
Fixes #123
1 parent 55fc0bd commit 9596c5d

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

Diff for: src/preprocess.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ export const preprocess = text => {
7373
}
7474
const { ast, warnings, vars, mapper } = result;
7575

76+
const global_style = result.ast?.css?.attributes.some(attr => attr.name === 'global');
77+
7678
const references_and_reassignments = `{${vars.filter(v => v.referenced || v.name[0] === '$').map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`;
7779
state.var_names = new Set(vars.map(v => v.name));
7880

7981
// convert warnings to linting messages
8082
const filtered_warnings = processor_options.ignore_warnings ? warnings.filter(warning => !processor_options.ignore_warnings(warning)) : warnings;
81-
state.messages = filtered_warnings.map(({ code, message, start, end }) => {
83+
state.messages = filtered_warnings.filter(warning => {
84+
// ignore "css-unused-selector" warnings if `<style global>`
85+
return !(global_style && warning.code === 'css-unused-selector');
86+
}).map(({ code, message, start, end }) => {
8287
const start_pos = processor_options.typescript && start ?
8388
mapper.get_original_position(start) :
8489
start && { line: start.line, column: start.column + 1 };

Diff for: test/samples/global-style/.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
rules: {},
3+
};

Diff for: test/samples/global-style/Input.svelte

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<style global>
2+
h1 {
3+
color: red;
4+
}
5+
</style>

Diff for: test/samples/global-style/expected.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)