Skip to content

Commit

Permalink
[fix] ignore css-unused-selector rule if <style global>
Browse files Browse the repository at this point in the history
Fixes #123
  • Loading branch information
metonym committed Mar 28, 2022
1 parent 55fc0bd commit 9596c5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ export const preprocess = text => {
}
const { ast, warnings, vars, mapper } = result;

const global_style = result.ast?.css?.attributes.some(attr => attr.name === 'global');

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')}}`;
state.var_names = new Set(vars.map(v => v.name));

// convert warnings to linting messages
const filtered_warnings = processor_options.ignore_warnings ? warnings.filter(warning => !processor_options.ignore_warnings(warning)) : warnings;
state.messages = filtered_warnings.map(({ code, message, start, end }) => {
state.messages = filtered_warnings.filter(warning => {
// ignore "css-unused-selector" warnings if `<style global>`
return !(global_style && warning.code === 'css-unused-selector');
}).map(({ code, message, start, end }) => {
const start_pos = processor_options.typescript && start ?
mapper.get_original_position(start) :
start && { line: start.line, column: start.column + 1 };
Expand Down
3 changes: 3 additions & 0 deletions test/samples/global-style/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
rules: {},
};
5 changes: 5 additions & 0 deletions test/samples/global-style/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style global>
h1 {
color: red;
}
</style>
1 change: 1 addition & 0 deletions test/samples/global-style/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 9596c5d

Please sign in to comment.