Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Disallow all link components except <VLink> with eslint rule #916

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

zackkrida
Copy link
Member

Fixes

Related to #871

Description

This PR adds a custom vue eslint rule disallowing usage of raw <a> tags and encouraging the use of <VLink> instead.

Testing Instructions

Try adding this code <a href="cool">cool</a> to any Vue component in a text editor where you receive eslint messages and observe the correct eslint error:

CleanShot 2022-02-20 at 21 06 16@2x

Suggestions are welcome regarding the error message or lint rule implementation. I didn't dive into the vue-eslint AST1 too deeply so there may be a more specific rule we'd like to use.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Footnotes

  1. https://github.com/vuejs/vue-eslint-parser/blob/master/docs/ast.md

@zackkrida zackkrida requested a review from a team as a code owner February 21, 2022 02:14
@zackkrida zackkrida requested review from dhruvkb and sarayourfriend and removed request for a team February 21, 2022 02:14
@zackkrida zackkrida changed the title init Disallow <a> and encourage <VLink> with eslint rule Feb 21, 2022
@zackkrida zackkrida added 🌟 goal: addition Addition of new feature 🟩 priority: low Low priority and doesn't need to be rushed 🤖 aspect: dx Concerns developers' experience with the codebase labels Feb 21, 2022
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add NuxtLink, too?

Base automatically changed from add/bigger_vlink_component to main February 21, 2022 02:24
@zackkrida
Copy link
Member Author

@obulat added RouterLink too, just to be safe. Great suggestion. Note that the PascalCase names are pascalcase in the AST. We could also add additional rules for router-link and nuxt-link but ideally those would be caught by the no-kebab-case rule and then picked up by this one.

@zackkrida zackkrida changed the base branch from main to add_vlink February 21, 2022 02:38
@zackkrida zackkrida changed the base branch from add_vlink to main February 21, 2022 02:38
@zackkrida zackkrida force-pushed the add-raw-link-linting branch from bca66c8 to ccf15b7 Compare February 21, 2022 02:40
@zackkrida zackkrida requested a review from obulat February 21, 2022 02:40
@zackkrida zackkrida changed the title Disallow <a> and encourage <VLink> with eslint rule Disallow all link components except<VLink> with eslint rule Feb 21, 2022
@zackkrida zackkrida changed the title Disallow all link components except<VLink> with eslint rule Disallow all link components except <VLink> with eslint rule Feb 21, 2022
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! Love the router-link addition for anyone who really wants to break the rules :)
You can still create an a link using <Component :is="'a'">Link</Component>. Which is good, because otherwise you would have to suppress this rule inside the VLink component itself.

@zackkrida zackkrida merged commit 6b838c6 into main Feb 21, 2022
@zackkrida zackkrida deleted the add-raw-link-linting branch February 21, 2022 03:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤖 aspect: dx Concerns developers' experience with the codebase 🌟 goal: addition Addition of new feature 🟩 priority: low Low priority and doesn't need to be rushed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants