diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 000000000..e5b6d8d6a --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 000000000..43b72b358 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://unpkg.com/@changesets/config/schema.json", + "changelog": [ + "@svitejs/changesets-changelog-github-compact", + { + "repo": "vuejs/eslint-plugin-vue" + } + ], + "commit": false, + "linked": [], + "access": "public", + "baseBranch": "master", + "bumpVersionsWithWorkspaceProtocolOnly": true, + "ignore": [] +} diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 000000000..260b73582 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,35 @@ +name: Release + +on: + push: + branches: + - master + +permissions: {} + +jobs: + release: + # prevents this action from running on forks + if: github.repository == 'vuejs/eslint-plugin-vue' + permissions: + contents: write # to create release (changesets/action) + pull-requests: write # to create pull request (changesets/action) + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + - name: Install Dependencies + run: npm install -f + + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 + with: + version: npm run changeset:version + publish: npm run changeset:publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..b21ab6f6f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# eslint-plugin-vue + +## 10.2.0 + +### Minor Changes + +- [vue/no-restricted-html-elements](https://eslint.vuejs.org/rules/no-restricted-html-elements.html) now accepts multiple elements in each entry. ([#2750](https://github.com/vuejs/eslint-plugin-vue/pull/2750)) + +### Patch Changes + +- Updates resources ([#2747](https://github.com/vuejs/eslint-plugin-vue/pull/2747)) diff --git a/docs/rules/no-restricted-html-elements.md b/docs/rules/no-restricted-html-elements.md index 2a6d6c997..fef08aeb2 100644 --- a/docs/rules/no-restricted-html-elements.md +++ b/docs/rules/no-restricted-html-elements.md @@ -37,16 +37,16 @@ This rule takes a list of strings, where each string is an HTML element name to ```json { - "vue/no-restricted-html-elements": ["error", "button", "marquee"] + "vue/no-restricted-html-elements": ["error", "a", "marquee"] } ``` - + ```vue ``` @@ -60,8 +60,8 @@ Alternatively, the rule also accepts objects. "vue/no-restricted-html-elements": [ "error", { - "element": "button", - "message": "Prefer use of our custom component" + "element": ["a", "RouterLink"], + "message": "Prefer the use of component" }, { "element": "marquee", @@ -73,18 +73,18 @@ Alternatively, the rule also accepts objects. The following properties can be specified for the object. -- `element` ... Specify the html element. +- `element` ... Specify the HTML element or an array of HTML elements. - `message` ... Specify an optional custom message. -### `{ "element": "marquee" }, { "element": "button" }` +### `{ "element": "marquee" }, { "element": "a" }` - + ```vue ``` diff --git a/lib/rules/no-restricted-html-elements.js b/lib/rules/no-restricted-html-elements.js index e906d86f2..8d5f3c300 100644 --- a/lib/rules/no-restricted-html-elements.js +++ b/lib/rules/no-restricted-html-elements.js @@ -23,7 +23,12 @@ module.exports = { { type: 'object', properties: { - element: { type: 'string' }, + element: { + oneOf: [ + { type: 'string' }, + { type: 'array', items: { type: 'string' } } + ] + }, message: { type: 'string', minLength: 1 } }, required: ['element'], @@ -55,9 +60,12 @@ module.exports = { } for (const option of context.options) { - const element = option.element || option + const restrictedItem = option.element || option + const elementsToRestrict = Array.isArray(restrictedItem) + ? restrictedItem + : [restrictedItem] - if (element === node.rawName) { + if (elementsToRestrict.includes(node.rawName)) { context.report({ messageId: option.message ? 'customMessage' : 'forbiddenElement', data: { @@ -66,6 +74,8 @@ module.exports = { }, node: node.startTag }) + + return } } } diff --git a/lib/utils/vue3-export-names.json b/lib/utils/vue3-export-names.json index 349779da1..395090026 100644 --- a/lib/utils/vue3-export-names.json +++ b/lib/utils/vue3-export-names.json @@ -235,6 +235,7 @@ "AsyncComponentOptions", "defineAsyncComponent", "useModel", + "TemplateRef", "useTemplateRef", "useId", "h", @@ -263,8 +264,8 @@ "devtools", "setDevtoolsHook", "DeprecationTypes", - "WatchOptionsBase", "createElementVNode", + "WatchOptionsBase", "TransitionProps", "Transition", "TransitionGroupProps", diff --git a/package.json b/package.json index 7e44aeb84..da1053c00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-vue", - "version": "10.1.0", + "version": "10.2.0", "description": "Official ESLint plugin for Vue.js", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,12 +18,15 @@ "lint:fix": "eslint . --fix && markdownlint \"**/*.md\" --fix", "tsc": "tsc", "preversion": "npm test && git add .", - "version": "env-cmd -e version npm run update && npm run lint -- --fix && git add .", + "version": "npm run generate:version && git add .", "update": "node ./tools/update.js", "update-resources": "node ./tools/update-resources.js", "docs:watch": "vitepress dev docs", "predocs:build": "npm run update", - "docs:build": "vitepress build docs" + "docs:build": "vitepress build docs", + "generate:version": "env-cmd -e version npm run update && npm run lint -- --fix", + "changeset:version": "changeset version && npm run generate:version && git add --all", + "changeset:publish": "changeset publish" }, "files": [ "lib" @@ -66,8 +69,10 @@ "xml-name-validator": "^4.0.0" }, "devDependencies": { + "@changesets/cli": "^2.29.2", "@ota-meshi/site-kit-eslint-editor-vue": "^0.2.4", "@stylistic/eslint-plugin": "^2.12.1", + "@svitejs/changesets-changelog-github-compact": "^1.2.0", "@types/eslint": "^8.56.2", "@types/natural-compare": "^1.4.3", "@types/node": "^14.18.63", diff --git a/tests/lib/rules/eqeqeq.js b/tests/lib/rules/eqeqeq.js index afd458248..8089ebaaa 100644 --- a/tests/lib/rules/eqeqeq.js +++ b/tests/lib/rules/eqeqeq.js @@ -3,7 +3,8 @@ */ 'use strict' -const RuleTester = require('../../eslint-compat').RuleTester +const semver = require('semver') +const { RuleTester, ESLint } = require('../../eslint-compat') const rule = require('../../../lib/rules/eqeqeq') const tester = new RuleTester({ @@ -24,7 +25,19 @@ tester.run('eqeqeq', rule, { invalid: [ { code: '', - errors: ["Expected '===' and instead saw '=='."] + errors: [ + { + message: "Expected '===' and instead saw '=='.", + suggestions: semver.gte(ESLint.version, '9.26.0') + ? [ + { + desc: "Use '===' instead of '=='.", + output: `` + } + ] + : null + } + ] }, // CSS vars injection { @@ -34,7 +47,24 @@ tester.run('eqeqeq', rule, { color: v-bind(a == 1 ? 'red' : 'blue') } `, - errors: ["Expected '===' and instead saw '=='."] + errors: [ + { + message: "Expected '===' and instead saw '=='.", + suggestions: semver.gte(ESLint.version, '9.26.0') + ? [ + { + desc: "Use '===' instead of '=='.", + output: ` + ` + } + ] + : null + } + ] } ] }) diff --git a/tests/lib/rules/no-restricted-html-elements.js b/tests/lib/rules/no-restricted-html-elements.js index c3e3e9eeb..6180b046b 100644 --- a/tests/lib/rules/no-restricted-html-elements.js +++ b/tests/lib/rules/no-restricted-html-elements.js @@ -31,6 +31,11 @@ tester.run('no-restricted-html-elements', rule, { filename: 'test.vue', code: '', options: ['button'] + }, + { + filename: 'test.vue', + code: '', + options: [{ element: ['div', 'span'] }] } ], invalid: [ @@ -69,6 +74,28 @@ tester.run('no-restricted-html-elements', rule, { column: 11 } ] + }, + { + filename: 'test.vue', + code: '', + options: [ + { + element: ['a', 'RouterLink'], + message: 'Prefer the use of component' + } + ], + errors: [ + { + message: 'Prefer the use of component', + line: 1, + column: 11 + }, + { + message: 'Prefer the use of component', + line: 1, + column: 18 + } + ] } ] })