Permalink
Cannot retrieve contributors at this time
66 lines (61 sloc)
1.35 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-github/lib/rules/a11y-no-title-attribute.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {getProp, getPropValue} = require('jsx-ast-utils') | |
const {getElementType} = require('../utils/get-element-type') | |
const SEMANTIC_ELEMENTS = [ | |
'a', | |
'button', | |
'summary', | |
'select', | |
'option', | |
'textarea', | |
'input', | |
'span', | |
'div', | |
'p', | |
'h1', | |
'h2', | |
'h3', | |
'h4', | |
'h5', | |
'h6', | |
'details', | |
'summary', | |
'dialog', | |
'tr', | |
'th', | |
'td', | |
'label', | |
] | |
const ifSemanticElement = (context, node) => { | |
const elementType = getElementType(context, node.openingElement, true) | |
for (const semanticElement of SEMANTIC_ELEMENTS) { | |
if (elementType === semanticElement) { | |
return true | |
} | |
} | |
return false | |
} | |
module.exports = { | |
meta: { | |
docs: { | |
description: 'Guards against developers using the title attribute', | |
url: require('../url')(module), | |
}, | |
schema: [], | |
}, | |
create(context) { | |
return { | |
JSXElement: node => { | |
const elementType = getElementType(context, node.openingElement, true) | |
if (elementType !== `iframe` && ifSemanticElement(context, node)) { | |
const titleProp = getPropValue(getProp(node.openingElement.attributes, `title`)) | |
if (titleProp) { | |
context.report({ | |
node, | |
message: 'The title attribute is not accessible and should never be used unless for an `<iframe>`.', | |
}) | |
} | |
} | |
}, | |
} | |
}, | |
} |