diff --git a/eslint.config.js b/eslint.config.js index 44c1011..bc5e25f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,5 +18,6 @@ export default antfu( 'yaml/indent': 'off', }, }, + ignores: ['**/playground/**'], }, ) diff --git a/package.json b/package.json index 0788b20..cfadc6b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@vue-macros/cli", "type": "module", - "version": "1.2.0", + "version": "1.2.1", "packageManager": "pnpm@8.10.5", "description": "Rewriting at vue macros powered by ast-grep.", "author": "zhiyuanzmj ", diff --git a/playground/src/App.vue b/playground/src/App.vue index 21393c9..123449d 100644 --- a/playground/src/App.vue +++ b/playground/src/App.vue @@ -20,6 +20,8 @@ const compRef = shallowRef() v-loading.fullscreen.lock="true" v-memo="[select?.id === i.id]" v-on="on" + v-on:click="alert" + @sub-mit.prevent @click.once="select = i" @submit="alert" @update:model-value="select.id = $event" diff --git a/src/sg/index.ts b/src/sg/index.ts index 95f5c00..2edf8e1 100644 --- a/src/sg/index.ts +++ b/src/sg/index.ts @@ -65,6 +65,7 @@ export async function sg(target: string) { if (['setup-sfc', 'define-render', 'export-render'].includes(macro)) { await $`${sg} scan -c ${config}.yml -U --filter '^self-closing-tag' ${target}` + await $`${sg} scan -c ${config}.yml -U --filter '^dot-to-underline' ${target}` await $`${sg} scan -c ${config}.yml -U --filter '^v-' ${target}` await $`${sg} scan -c ${config}.yml -U --filter '^${macro === 'setup-sfc' ? 'export-render' : macro}' ${target}` await useTsx(async () => { diff --git a/src/sg/rules/jsx-directive/pascal-case.yml b/src/sg/rules/jsx-directive/pascal-case.yml index e51b874..efca25c 100644 --- a/src/sg/rules/jsx-directive/pascal-case.yml +++ b/src/sg/rules/jsx-directive/pascal-case.yml @@ -15,32 +15,4 @@ transform: source: $A toCase: pascalCase separatedBy: [dash] -fix: - $B - ---- - -id: v-pascal-case for attributeName -language: tsx -rule: - any: - - kind: property_identifier - pattern: $A - regex: ^[^v]- - - kind: identifier - pattern: $A - regex: '-' - follows: - kind: identifier - stopBy: end - inside: - kind: jsx_namespace_name - -transform: - B: - convert: - source: $A - toCase: camelCase - separatedBy: [dash] -fix: - $B +fix: $B diff --git a/src/sg/rules/jsx-directive/v-directive.yml b/src/sg/rules/jsx-directive/v-directive.yml index 06486cf..e3a6218 100644 --- a/src/sg/rules/jsx-directive/v-directive.yml +++ b/src/sg/rules/jsx-directive/v-directive.yml @@ -1,17 +1,25 @@ id: v-directive language: html rule: - kind: attribute + kind: quoted_attribute_value has: + kind: attribute_value + pattern: $V + follows: kind: attribute_name pattern: $NAME - regex: ^v- - precedes: - kind: quoted_attribute_value - has: - kind: attribute_value - pattern: $V - stopBy: end + regex: ^v-|@ + stopBy: end +fix: |- + {$V} + +--- + +id: dot-to-underline +language: html +rule: + kind: attribute_name + pattern: $NAME transform: K: replace: @@ -19,4 +27,4 @@ transform: by: _ source: $NAME fix: |- - $K={$V} + $K diff --git a/src/sg/rules/jsx-directive/v-on.yml b/src/sg/rules/jsx-directive/v-on.yml index 97aa4f9..bfe6cfd 100644 --- a/src/sg/rules/jsx-directive/v-on.yml +++ b/src/sg/rules/jsx-directive/v-on.yml @@ -1,48 +1,20 @@ -id: v-on shorthand +id: v-on language: html rule: - kind: attribute - has: - kind: attribute_name - regex: ^@ - pattern: $NAME - precedes: - kind: quoted_attribute_value - has: - kind: attribute_value - pattern: $V - stopBy: end + kind: attribute_name + regex: '^@|v-on:' + pattern: $NAME transform: B: - substring: - startChar: 1 - endChar: 2 + replace: + replace: '^@|v-on:' + by: '' source: $NAME C: convert: source: $B - toCase: upperCase - D: - substring: - startChar: 2 - source: $NAME - K: - replace: - replace: \. - by: _ - source: $D -fix: |- - on$C$K={$V} - ---- - -id: v-on to on -language: tsx -rule: - kind: property_identifier - regex: ^v-on$ -fix: - on + toCase: capitalize +fix: on$C ---