Update checked-in dependencies
This commit is contained in:
parent
99c9f6a498
commit
e266801e21
242 changed files with 2638 additions and 9296 deletions
41
node_modules/eslint-plugin-github/lib/rules/a11y-svg-has-accessible-name.js
generated
vendored
Normal file
41
node_modules/eslint-plugin-github/lib/rules/a11y-svg-has-accessible-name.js
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
const {hasProp} = require('jsx-ast-utils')
|
||||
const {getElementType} = require('../utils/get-element-type')
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'SVGs must have an accessible name',
|
||||
url: require('../url')(module),
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
JSXOpeningElement: node => {
|
||||
const elementType = getElementType(context, node)
|
||||
if (elementType !== 'svg') return
|
||||
|
||||
// Check if there is a nested title element that is the first child of the `<svg>`
|
||||
const hasNestedTitleAsFirstChild =
|
||||
node.parent.children?.[0]?.type === 'JSXElement' &&
|
||||
node.parent.children?.[0]?.openingElement?.name?.name === 'title'
|
||||
|
||||
// Check if `aria-label` or `aria-labelledby` is set
|
||||
const hasAccessibleName = hasProp(node.attributes, 'aria-label') || hasProp(node.attributes, 'aria-labelledby')
|
||||
|
||||
// Check if SVG is decorative
|
||||
const isDecorative =
|
||||
hasProp(node.attributes, 'role', 'presentation') || hasProp(node.attributes, 'aria-hidden', 'true')
|
||||
|
||||
if (elementType === 'svg' && !hasAccessibleName && !isDecorative && !hasNestedTitleAsFirstChild) {
|
||||
context.report({
|
||||
node,
|
||||
message:
|
||||
'`<svg>` must have an accessible name. Set `aria-label` or `aria-labelledby`, or nest a `<title>` element. However, if the `<svg>` is purely decorative, hide it with `aria-hidden="true"` or `role="presentation"`.',
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue