• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / eslint-plugin-fluentui-jsx-a11y / 17781003248

16 Sep 2025 10:42PM UTC coverage: 97.074%. First build
17781003248

push

github

rbitting
Added rule to require alt text on image

492 of 517 branches covered (95.16%)

Branch coverage included in aggregate %.

11 of 12 new or added lines in 1 file covered. (91.67%)

802 of 816 relevant lines covered (98.28%)

39.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/lib/rules/image-needs-alt.ts
1
// Copyright (c) Microsoft Corporation.
2
// Licensed under the MIT License.
3

4
const elementType = require("jsx-ast-utils").elementType;
1✔
5
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
1✔
6
import { hasNonEmptyProp } from "../util/hasNonEmptyProp";
1✔
7

1✔
8
//------------------------------------------------------------------------------
9
// Rule Definition
10
//------------------------------------------------------------------------------
11

1✔
12
const rule = ESLintUtils.RuleCreator.withoutDocs({
13
    meta: {
14
        type: "problem",
15
        docs: {
16
            description: "Accessibility: Image must have alt attribute",
17
            recommended: "error"
18
        },
19
        messages: {
20
            imageNeedsAlt: "Accessibility: Image must have alt attribute with a meaningful description of the image"
21
        },
22
        schema: []
23
    },
24
    defaultOptions: [], // no options needed
25
    create(context) {
6✔
26
        return {
27
            // Listen for variable declarations
28
            JSXOpeningElement(node: TSESTree.JSXOpeningElement) {
29
                // No error if the element is not an Image
6!
NEW
30
                if (elementType(node) !== "Image") {
×
31
                    return;
32
                }
33

6✔
34
                // No error if alt prop exists and is non-empty
2✔
35
                if (hasNonEmptyProp(node.attributes, "alt")) {
36
                    return;
4✔
37
                }
38

39
                context.report({
40
                    node,
41
                    messageId: "imageNeedsAlt"
42
                });
43
            }
44
        };
1✔
45
    }
46
});
47

48
export default rule;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc