@double-great/remark-lint-alt-text
Advanced tools
Comparing version 0.1.0 to 0.2.0
23
index.js
const rule = require("unified-lint-rule"); | ||
const visit = require("unist-util-visit"); | ||
const visit = require("unist-util-visit-parents"); | ||
const altText = require("@double-great/alt-text"); | ||
@@ -7,5 +7,16 @@ | ||
const textToNodes = {}; | ||
const aggregate = node => { | ||
let imageIsLink = false; | ||
let hasAltText = false; | ||
const aggregate = (node, ancestors) => { | ||
imageIsLink = ancestors.filter(a => a.type === "link").length > 0; | ||
const alt = node.alt || undefined; | ||
if (!alt) return; | ||
if (alt) hasAltText = true; | ||
if (!alt && !imageIsLink) return; | ||
if (!alt && imageIsLink) { | ||
file.message( | ||
"No alt text found: Images inside a link tag require alt text that describes the purpose of the link.", | ||
node | ||
); | ||
} | ||
if (!textToNodes[alt]) { | ||
@@ -26,2 +37,8 @@ textToNodes[alt] = []; | ||
} | ||
if (imageIsLink && hasAltText) { | ||
file.message( | ||
"Images inside a link tag require alt text that describes the purpose of the link.", | ||
node | ||
); | ||
} | ||
}); | ||
@@ -28,0 +45,0 @@ }); |
{ | ||
"name": "@double-great/remark-lint-alt-text", | ||
"version": "0.1.0", | ||
"description": "A remark-lint plugin to warn against inaccessible alt text.", | ||
"version": "0.2.0", | ||
"description": "A remark-lint plugin that finds unhelpful or missing image alt text", | ||
"main": "index.js", | ||
@@ -15,5 +15,5 @@ "scripts": { | ||
"dependencies": { | ||
"@double-great/alt-text": "^0.1.0", | ||
"@double-great/alt-text": "^0.2.0", | ||
"unified-lint-rule": "^1.0.4", | ||
"unist-util-visit": "^2.0.1" | ||
"unist-util-visit-parents": "^3.0.1" | ||
}, | ||
@@ -28,3 +28,3 @@ "devDependencies": { | ||
"remark": "^11.0.2", | ||
"tape": "^4.12.1" | ||
"tape": "^4.13.0" | ||
}, | ||
@@ -40,2 +40,3 @@ "husky": { | ||
"keywords": [ | ||
"accessibility", | ||
"remark", | ||
@@ -42,0 +43,0 @@ "remark-plugin", |
# remark-lint-alt-text [![Build Status](https://travis-ci.com/double-great/remark-lint-alt-text.svg?branch=master)](https://travis-ci.com/double-great/remark-lint-alt-text) | ||
A [remark-lint](https://github.com/remarkjs/remark-lint) plugin to warn against inaccessible alt text. | ||
A [remark-lint](https://github.com/remarkjs/remark-lint) plugin that finds unhelpful or missing image alt text. | ||
@@ -5,0 +5,0 @@ ## Install |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4186
4
41
+ Added@double-great/alt-text@0.2.0(transitive)
+ Addedcli-git.io@1.0.1(transitive)
+ Addedgithub-slugger@1.5.0(transitive)
- Removedunist-util-visit@^2.0.1
- Removed@double-great/alt-text@0.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)