
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
@mands/eslint-plugin
Advanced tools
Enforces best practices with data-testid by disallowing it on semantic elements, or ARIA generic elements with ARIA attributes
A collection of custom ESLint rules we use here at M&S to help maintain code quality. Rules can be opted into individually to provide more control over which rules you want to use and at what level of severity.
pnpm i -D @mands/eslint-plugin
# OR
yarn add --dev @mands/eslint-plugin
# OR
npm i --save-dev @mands/eslint-plugin
// .eslintrc
{
"plugins": ["@mands/eslint-plugin"],
"rules": {
"@mands/eslint-plugin/jsx-disallow-testid-on-semantic-elements": "error"
},
...
}
Enforces best practices with data-testid
as dictated by the React-Testing-Library Docs, by disallowing it on elements with semantic meaning or ARIA generic elements with ARIA attributes.
Supports React components by supplying data-testid (or data-test-id) through props.
Works by checking JSXElements, the Rule differentiates between HTML Elements and React Components within JSX by checking if the JSXElement begins with a capital letter - so will only work in projects following these best practices.
<!-- ✅ Valid - ARIA Generic element, with no semantic meaning -->
<div data-testid="test">
...
</div>
<!-- ❌ Invalid - element has ARIA semantic attributes, and should be selected with them -->
<div data-testid="test" role="test" aria-label="test">
...
</div>
<!-- ❌ Invalid - semantic element's should avoid use of data-testid -->
<ul data-testid="test">
...
</ul>
<!-- ❌ Invalid - same as above, alternate spelling -->
<ul data-test-id="test">
...
</ul>
// ✅ Valid - ARIA Generic element, with no semantic meaning
const Test = ({'data-testid': dataTestId}) => (
<div data-testid={dataTestId}>
...
</div>);
const Test2 = () => (<Test data-testid='test'></Test>)
// ❌ Invalid - semantic element's should avoid use of data-testid
const Test = ({'data-testid': dataTestId}) => (
<nav data-testid={dataTestId}>
...
</nav>);
const Test2 = () => (<Test data-testid='test'></Test>)
// ❌ Invalid - element has ARIA semantic attributes, and should be selected with them
const Test = ({'data-testid': dataTestId}) => (
<div data-testid={dataTestId} role="test" aria-label="test">
...
</div>);
const Test2 = () => (<Test data-testid='test'></Test>)
data-testid
's use on any ARIA generic element, this uses aria-query for the current accessibility web standards.data-testid
data-testid
through component props.data-testid
usage on semantic and generic elements.data-test-id
FAQs
Enforces best practices with data-testid by disallowing it on semantic elements, or ARIA generic elements with ARIA attributes
We found that @mands/eslint-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.