Skip to content

Commit a12ff15

Browse files
committed
feat: add eslint plugin
1 parent 4c014f7 commit a12ff15

15 files changed

+331
-61
lines changed

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"editor.formatOnSave": true,
3-
"eslint.experimental.useFlatConfig": true
2+
"editor.formatOnSave": true
43
}

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ export const useUserStore = defineStore$('user', () => {
117117

118118
// convert to:
119119
export const useUserStore = defineStore('user', () => {
120-
let token = $ref('')
120+
const token = ref('')
121121
function login() {
122-
token = 'TOKEN'
122+
token.value = 'TOKEN'
123123
}
124124

125125
return {
126-
token: $$(token),
127-
login: $$(login),
126+
token,
127+
login,
128128
}
129129
})
130130
```
@@ -134,7 +134,7 @@ export const useUserStore = defineStore('user', () => {
134134
import { useBase64 } from '@vueuse/core'
135135
import { useUserStore } from '~/store/user'
136136
137-
const { token, login } = $useUserStore()
137+
const { token, login } = useUserStore()
138138
;[token]
139139
// convert to:
140140
const { token, login } = toRefs(useUserStore())
@@ -145,12 +145,14 @@ const text = $inject$('text', token)
145145
const text = inject('text', token)
146146
147147
const { base64 } = $useBase64$(text)
148+
;[base64]
148149
// convert to:
149-
const { base64 } = useBase64(text)
150+
let { base64 } = $useBase64(text)
151+
;[base64.value]
150152
151153
provide$('base64', base64)
152154
// convert to:
153-
provide('base64', base64)
155+
provide$('base64', base64)
154156
155157
const stop = watch$(base64, () => {
156158
console.log(base64)
@@ -173,9 +175,11 @@ defineExpose({
173175
})
174176
175177
let compRef = $useRef()
178+
;[compRef]
176179
defineRender(<Comp ref$={compRef} />)
177180
// convert to:
178181
let compRef = useRef()
182+
;[compRef.value]
179183
defineRender(<Comp ref={compRef} />)
180184
</script>
181185
```
@@ -209,6 +213,17 @@ export default {
209213
}
210214
```
211215

216+
### ESLint
217+
218+
Convert to reactivity function.
219+
220+
```ts
221+
// ./eslint.config.js
222+
import reactivityFunction from 'unplugin-vue-reactivity-function/eslint'
223+
224+
export default [reactivityFunction()]
225+
```
226+
212227
## License
213228

214229
[MIT](./LICENSE) License © 2023-PRESENT [zhiyuanzmj](https://github.com/zhiyuanzmj)

eslint.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { sxzz } from '@sxzz/eslint-config'
2+
import reactivityFunction from './dist/eslint.js'
3+
4+
export default [
5+
...sxzz({
6+
rules: {
7+
'unused-imports/no-unused-vars': 'off',
8+
'unused-imports/no-unused-imports': 'off',
9+
'import/no-default-export': 'off',
10+
},
11+
}),
12+
reactivityFunction({
13+
ignores: ['**/*.md/**'],
14+
rules: {
15+
'reactivity-function': 1,
16+
},
17+
}),
18+
]

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@
110110
"@sxzz/eslint-config": "^3.14.0",
111111
"@sxzz/prettier-config": "^2.0.2",
112112
"@types/babel__traverse": "^7.20.7",
113+
"@types/eslint": "^9.6.1",
113114
"@types/node": "^20.14.11",
114-
"@typescript-eslint/types": "^8.30.1",
115+
"@typescript-eslint/types": "^8.31.0",
116+
"@typescript-eslint/utils": "^8.30.1",
115117
"@vue-macros/reactivity-transform": "^0.4.6",
116118
"@vue-macros/test-utils": "^1.4.0",
117119
"bumpp": "^9.4.1",

patches/@typescript-eslint__scope-manager.patch

Lines changed: 0 additions & 19 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 67 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/eslint.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import rules, { type Rules } from './eslint/index'
2+
import type { Linter } from 'eslint'
3+
4+
export const plugins = {
5+
'reactivity-function': {
6+
rules,
7+
},
8+
}
9+
10+
export { rules, type Rules }
11+
12+
export default ({ rules = {}, ...options }: Linter.Config<Rules> = {}) => ({
13+
name: 'reactivity-function',
14+
plugins,
15+
rules: {
16+
'reactivity-function/reactivity-function':
17+
rules['reactivity-function'] || 1,
18+
} satisfies Rules & Record<string, unknown>,
19+
...options,
20+
})

src/eslint/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import reactivityFunction, {
2+
type ReactivityFunctionRuleOptions,
3+
} from './reactivity-function'
4+
import type { Linter } from '@typescript-eslint/utils/ts-eslint'
5+
6+
export interface RuleOptions {
7+
'reactivity-function': ReactivityFunctionRuleOptions
8+
}
9+
10+
export type Rules = Partial<{
11+
[K in keyof RuleOptions]:
12+
| Linter.Severity
13+
| [Linter.Severity, ...RuleOptions[K]]
14+
}>
15+
16+
export default {
17+
'reactivity-function': reactivityFunction,
18+
}

0 commit comments

Comments
 (0)