GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix `a11y-svg-has-accessible-name` considering whitespace JSXText (#508) · github/eslint-plugin-github@30f5d80

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/rules
    • a11y-svg-has-accessible-name.js
  • tests
    • a11y-svg-has-accessible-name.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/rules/a11y-svg-has-accessible-name.js‎

Copy file name to clipboardExpand all lines: lib/rules/a11y-svg-has-accessible-name.js
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ module.exports = {
1616
const elementType = getElementType(context, node)
1717
if (elementType !== 'svg') return
1818

19-
// Check if there is a nested title element that is the first child of the `<svg>`
19+
// Check if there is a nested title element that is the first non-whitespace child of the `<svg>`
20+
const childrenWithoutWhitespace = node.parent.children?.filter(({type, value}) =>
21+
type === 'JSXText' ? value.trim() !== '' : type !== 'JSXText',
22+
)
23+
2024
const hasNestedTitleAsFirstChild =
21-
node.parent.children?.[0]?.type === 'JSXElement' &&
22-
node.parent.children?.[0]?.openingElement?.name?.name === 'title'
25+
childrenWithoutWhitespace?.[0]?.type === 'JSXElement' &&
26+
childrenWithoutWhitespace?.[0]?.openingElement?.name?.name === 'title'
2327

2428
// Check if `aria-label` or `aria-labelledby` is set
2529
const hasAccessibleName = hasProp(node.attributes, 'aria-label') || hasProp(node.attributes, 'aria-labelledby')
Collapse file

‎tests/a11y-svg-has-accessible-name.js‎

Copy file name to clipboardExpand all lines: tests/a11y-svg-has-accessible-name.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ ruleTester.run('a11y-svg-has-accessible-name', rule, {
1919
{
2020
code: "<svg height='100' width='100'><title>Circle with a black outline and red fill</title><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>",
2121
},
22+
{
23+
code: `<svg height='100' width='100'>
24+
<title>Circle with a black outline and red fill</title>
25+
<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/>
26+
</svg>`,
27+
},
2228
{
2329
code: "<svg aria-label='Circle with a black outline and red fill' height='100' width='100'><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>",
2430
},

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.