Skip to content

Commit

Permalink
no-useless-undefined: Ignore ref(undefined) in Vue project (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 26, 2022
1 parent 2c914d4 commit e7306e5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rules/no-useless-undefined.js
Expand Up @@ -70,6 +70,8 @@ const shouldIgnore = node => {
}

return compareFunctionNames.has(name)
// https://vuejs.org/api/reactivity-core.html#ref
|| name === 'ref'
// `set.add(undefined)`
|| name === 'add'
// `map.set(foo, undefined)`
Expand Down
35 changes: 34 additions & 1 deletion test/no-useless-undefined.mjs
@@ -1,5 +1,5 @@
import outdent from 'outdent';
import {getTester} from './utils/test.mjs';
import {getTester, parsers} from './utils/test.mjs';

const {test} = getTester(import.meta);

Expand Down Expand Up @@ -436,3 +436,36 @@ test.snapshot({
'foo.notBind(bar, undefined)',
],
});

test.snapshot({
testerOptions: {
parser: parsers.vue,
},
valid: [
outdent`
<script>
import {ref} from 'vue';
export default {
setup() {
return {foo: ref(undefined)};
}
};
</script>
`,
outdent`
<script setup>
import * as vue from 'vue';
const foo = vue.ref(undefined);
</script>
`,
],
invalid: [
outdent`
<script>
import {nextTick} from 'vue';
const foo = nextTick(undefined);
</script>
`,
],
});
25 changes: 25 additions & 0 deletions test/snapshots/no-useless-undefined.mjs.md
Expand Up @@ -299,3 +299,28 @@ Generated by [AVA](https://avajs.dev).
> 1 | foo.notBind(bar, undefined)␊
| ^^^^^^^^^ Do not use useless \`undefined\`.␊
`

## Invalid #1
1 | <script>
2 | import {nextTick} from 'vue';
3 | const foo = nextTick(undefined);
4 | </script>

> Output
`␊
1 | <script>␊
2 | import {nextTick} from 'vue';␊
3 | const foo = nextTick();␊
4 | </script>␊
`

> Error 1/1
`␊
1 | <script>␊
2 | import {nextTick} from 'vue';␊
> 3 | const foo = nextTick(undefined);␊
| ^^^^^^^^^ Do not use useless \`undefined\`.␊
4 | </script>␊
`
Binary file modified test/snapshots/no-useless-undefined.mjs.snap
Binary file not shown.

0 comments on commit e7306e5

Please sign in to comment.