Skip to content

Commit

Permalink
fix linting messages when using write-only store (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
j3rem1e authored Apr 23, 2021
1 parent 4715a5c commit 24c10d0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const preprocess = text => {
}
const { ast, warnings, vars, mapper } = result;

const references_and_reassignments = `{${vars.filter(v => v.referenced).map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`;
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
Expand Down Expand Up @@ -184,7 +184,7 @@ export const preprocess = text => {
},
});

block.transformed_code += `{${vars.filter(v => v.referenced_from_script).map(v => v.name)}}`;
block.transformed_code += `{${vars.filter(v => v.referenced_from_script || v.name[0] === '$').map(v => v.name)}}`;
}

// return processed string
Expand Down
5 changes: 5 additions & 0 deletions test/samples/unused-write-only-store/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"no-unused-vars": "error",
},
};
12 changes: 12 additions & 0 deletions test/samples/unused-write-only-store/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { imported, createStore } from './store.js';
const writeOnly = createStore();
$writeOnly = 99;
const readOnly = createStore();
$readOnly;
$imported = 'some value';
</script>
<div on:click={() => $imported = 'clicked' }/>
1 change: 1 addition & 0 deletions test/samples/unused-write-only-store/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 24c10d0

Please sign in to comment.