Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint-plugin-jsx-a11y(anchor-is-valid): working incorrectly #5746

Closed
Huliiiiii opened this issue Sep 13, 2024 · 1 comment · Fixed by #5781
Closed

eslint-plugin-jsx-a11y(anchor-is-valid): working incorrectly #5746

Huliiiiii opened this issue Sep 13, 2024 · 1 comment · Fixed by #5781
Assignees
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers

Comments

@Huliiiiii
Copy link

Huliiiiii commented Sep 13, 2024

Example
export const shouldBeValid = (
	<>
		<a href="/some/valid/uri">Navigate to page</a>
		<a href={"/some/valid/uri"}>Navigate to page</a>
		<a href={`/some/valid/uri`}>Navigate to page</a>
		<a href="#top">Navigate to internal page location</a>
		<a href={"#top"}>Navigate to internal page location</a>
		<a href={`#top`}>Navigate to internal page location</a>
		<a href="https://github.com">github</a>
		<a href={"https://github.com"}>github</a>
		<a href={`https://github.com`}>github</a>
		<a href="#section">section</a>
		<a href={"#section"}>section</a>
		<a href={`#section`}>section</a>
	</>
)

export const shouldBeInvalid = (
	<>
		<a href="#">invalid</a>
		<a href={"#"}>invalid</a>
		<a href={`#`}>invalid</a>
	</>
)
Result

Oxlint:

> bunx oxlint --jsx-a11y-plugin src\bar.tsx  

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
   ╭─[src\bar.tsx:3:4]
 2 │     <>
 3 │         <a href="/some/valid/uri">Navigate to page</a>
   ·          ─
 4 │         <a href={"/some/valid/uri"}>Navigate to page</a>
   ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
   ╭─[src\bar.tsx:4:4]
 3 │         <a href="/some/valid/uri">Navigate to page</a>
 4 │         <a href={"/some/valid/uri"}>Navigate to page</a>
   ·          ─
 5 │         <a href={`/some/valid/uri`}>Navigate to page</a>
   ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
   ╭─[src\bar.tsx:6:4]
 5 │         <a href={`/some/valid/uri`}>Navigate to page</a>
 6 │         <a href="#top">Navigate to internal page location</a>
   ·          ─
 7 │         <a href={"#top"}>Navigate to internal page location</a>
   ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
   ╭─[src\bar.tsx:7:4]
 6 │         <a href="#top">Navigate to internal page location</a>
 7 │         <a href={"#top"}>Navigate to internal page location</a>
   ·          ─
 8 │         <a href={`#top`}>Navigate to internal page location</a>
   ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:9:4]
  8 │         <a href={`#top`}>Navigate to internal page location</a>
  9 │         <a href="https://github.com">github</a>
    ·          ─
 10 │         <a href={"https://github.com"}>github</a>
    ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:10:4]
  9 │         <a href="https://github.com">github</a>
 10 │         <a href={"https://github.com"}>github</a>
    ·          ─
 11 │         <a href={`https://github.com`}>github</a>
    ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:12:4]
 11 │         <a href={`https://github.com`}>github</a>
 12 │         <a href="#section">section</a>
    ·          ─
 13 │         <a href={"#section"}>section</a>
    ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:13:4]
 12 │         <a href="#section">section</a>
 13 │         <a href={"#section"}>section</a>
    ·          ─
 14 │         <a href={`#section`}>section</a>
    ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:20:4]
 19 │     <>
 20 │         <a href="#">invalid</a>
    ·          ─
 21 │         <a href={"#"}>invalid</a>
    ╰────
  help: Provide a correct href for the `a` element.

  ⚠ eslint-plugin-jsx-a11y(anchor-is-valid): Use an incorrect href for the 'a' element.
    ╭─[src\bar.tsx:21:4]
 20 │         <a href="#">invalid</a>
 21 │         <a href={"#"}>invalid</a>
    ·          ─
 22 │         <a href={`#`}>invalid</a>
    ╰────
  help: Provide a correct href for the `a` element.

Finished in 5ms on 1 file with 121 rules using 12 threads.
Found 10 warnings and 0 errors.

Eslint:
Only the last 3

  20:3  error  The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md  jsx-a11y/anchor-is-valid  
  21:3  error  The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md  jsx-a11y/anchor-is-valid  
  22:3  error  The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md  jsx-a11y/anchor-is-valid  

✖ 3 problems (3 errors, 0 warnings)

We can notice that the string wrapped in backquotes will only be considered a valid href, even if it's not valid (e.g. <a href={`#`}>invalid</a>)

@Huliiiiii Huliiiiii added the C-bug Category - Bug label Sep 13, 2024
@Boshen Boshen added the good first issue Experience Level - Good for newcomers label Sep 13, 2024
@Boshen Boshen changed the title eslint-plugin-jsx-a11y(anchor-is-valid): Doesn't work at all eslint-plugin-jsx-a11y(anchor-is-valid): working incorrectly Sep 13, 2024
@DonIsaac DonIsaac added the A-linter Area - Linter label Sep 13, 2024
@Arian94
Copy link
Contributor

Arian94 commented Sep 14, 2024

Would like to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers
Projects
None yet
4 participants