agentleFS
MicrosoftKnown publishermicrosoft/eslint-plugin-fluentui-jsx-a11y/.github/copilot-instructions.md

eslint-plugin-fluentui-jsx-a11y

Copilot instructions30 starsChanged 9 months agoMITView on GitHub

This is @microsoft/eslint-plugin-fluentui-jsx-a11y, a static AST checker (ESLint plugin) that enforces accessibility rules on Fluent UI React v9 (@fluentui/react-components) JSX elements. Rules are written in TypeScript and target specific Fluent UI components to ensure accessible labeling, ARIA usage, and semantic structure. Most accessibility rules in this plugin check whether a component has an accessible label. Use makeLabeledControlRule from lib/util/ruleFactory.ts: When the factory pattern does not fit, use ESLintUtils.RuleCreator.withoutDocs:

  • Installs packages

The file

We split this copilot-instructions.md into the rules it gives an agent

10 rules. About 0 are common, 2 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the factory pattern does not fit, use ESLintUtils.RuleCreator.withoutDocs:

    line 100
  2. Distinctive:

    After creating the rule file:

    line 132
  3. Very specific:

    Add the export to lib/rules/index.ts.

    line 133
  4. Very specific:

    Create a matching test file in tests/lib/rules/.

    line 134
  5. Distinctive:

    All files must start with the Microsoft copyright header:

    line 191
  6. Very specific:

    Use ESLintUtils.RuleCreator.withoutDocs for custom rules.

    line 196
  7. Very specific:

    Prefer the makeLabeledControlRule factory for straightforward labeling rules.

    line 197
  8. Very specific:

    All new rules must be exported from lib/rules/index.ts.

    line 199
  9. Very specific:

    Run npm run build after adding or modifying rules to update the dist/ output.

    line 200
  10. Very specific:

    Run npm run update:eslint-docs after changing rule metadata to keep documentation in sync.

    line 201

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

Copilot Instructions

Project Overview

This is @microsoft/eslint-plugin-fluentui-jsx-a11y, a static AST checker (ESLint plugin) that enforces accessibility rules on Fluent UI React v9 (@fluentui/react-components) JSX elements. Rules are written in TypeScript and target specific Fluent UI components to ensure accessible labeling, ARIA usage, and semantic structure.

Technology Stack

  • Language: TypeScript
  • Runtime: Node.js (^14.17.0 || ^16.0.0 || >= 18.0.0)
  • Test framework: Jest with ts-jest
  • ESLint version: >=7 (peer dependency)
  • Key libraries: @typescript-eslint/utils, jsx-ast-utils, estree-jsx

Repository Structure

lib/
  rules/            # One file per ESLint rule (e.g., avatar-needs-name.ts)
    buttons/        # Button-specific rules grouped in a sub-folder
  util/             # Shared utility functions used by rules
    ruleFactory.ts  # Factory function for creating labeling rules
    hasLabeledChild.ts
    hasNonEmptyProp.ts
    labelUtils.ts
    ... (other utilities)
  index.ts          # Exports all rules
tests/
  lib/
    rules/          # One test file per rule (e.g., avatar-needs-name.test.ts)
      helper/       # Shared test helpers (ruleTester)
    util/           # Tests for utility functions
scripts/
  create-rule.js    # Scaffolding script to generate a new rule
  boilerplate/      # Templates used by create-rule.js
docs/               # Rule documentation

Common Commands

# Install dependencies
npm install

# Build (compiles TypeScript to dist/)
npm run build

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run linters (ESLint + markdownlint + eslint-doc check)
npm run lint

# Fix markdown lint issues
npm run fix:md

# Update rule documentation
npm run update:eslint-docs

# Scaffold a new rule (interactive)
node ./scripts/create-rule

Creating a New ESLint Rule

Option 1 — Rule Factory (preferred for labeling rules)

Most accessibility rules in this plugin check whether a component has an accessible label. Use makeLabeledControlRule from lib/util/ruleFactory.ts:

// lib/rules/my-component-needs-labelling.ts
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { makeLabeledControlRule } from "../util/ruleFactory";

export default makeLabeledControlRule({
    component: "MyComponent",           // string or RegExp
    messageId: "myComponentNeedsLabel",
    description: "Accessibility: MyComponent must have an accessible label.",

    // Labeling strategies to accept (set true for what is valid for this component):
    labelProps: ["aria-label"],
    allowFieldParent: true,
    allowHtmlFor: false,
    allowLabelledBy: true,
    allowWrappingLabel: false,
    allowTooltipParent: false,
    allowDescribedBy: false,
    allowLabeledChild: false,
    allowTextContentChild: false,
});

Option 2 — Custom Rule (for complex validation)

When the factory pattern does not fit, use ESLintUtils.RuleCreator.withoutDocs:

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
import { elementType } from "jsx-ast-utils";
import { JSXOpeningElement } from "estree-jsx";

const rule = ESLintUtils.RuleCreator.withoutDocs({
    defaultOptions: [],
    meta: {
        messages: { missingLabel: "Accessibility: MyComponent must have an accessible name." },
        type: "problem",
        docs: { description: "...", recommended: "strict", url: "https://www.w3.org/TR/html-aria/" },
        schema: []
    },
    create(context) {
        return {
            JSXOpeningElement(node: TSESTree.JSXOpeningElement) {
                if (elementType(node as unknown as JSXOpeningElement) !== "MyComponent") return;
                // validation logic...
                context.report({ node, messageId: "missingLabel" });
            }
        };
    }
});

export default rule;

After creating the rule file:

  1. Add the export to lib/rules/index.ts.
  2. Create a matching test file in tests/lib/rules/.

Using the Scaffolding Script

node ./scripts/create-rule

This generates the rule file, test file, and documentation stubs automatically.

Writing Tests

Tests use a shared ruleTester helper (tests/lib/rules/helper/ruleTester.ts) and follow the pattern below:

// tests/lib/rules/my-component-needs-labelling.test.ts
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Rule } from "eslint";
import ruleTester from "./helper/ruleTester";
import rule from "../../../lib/rules/my-component-needs-labelling";

ruleTester.run("my-component-needs-labelling", rule as unknown as Rule.RuleModule, {
    valid: [
        '<MyComponent aria-label="Description" />',
        // ...more valid cases
    ],
    invalid: [
        {
            code: "<MyComponent />",
            errors: [{ messageId: "myComponentNeedsLabel" }]
        },
        // ...more invalid cases
    ]
});

Utility Functions

FunctionFilePurpose
makeLabeledControlRuleruleFactory.tsFactory for labeling rules
hasAccessibleLabelruleFactory.tsCentral labeling check
hasNonEmptyProphasNonEmptyProp.tsCheck a prop has a non-empty value
hasDefinedProphasDefinedProp.tsCheck a prop is present
hasLabeledChildhasLabeledChild.tsDetect accessible child content (img alt, svg title, etc.)
hasTextContentChildhasTextContentChild.tsDetect meaningful text in children
hasFieldParenthasFieldParent.tsDetect a <Field> ancestor
hasToolTipParenthasTooltipParent.tsDetect a <Tooltip> ancestor
isInsideLabelTaglabelUtils.tsDetect a wrapping <label> / <Label>
hasAssociatedLabelViaAriaLabelledBylabelUtils.tsValidate aria-labelledby references
hasAssociatedLabelViaHtmlForlabelUtils.tsValidate htmlFor/id associations
hasAssociatedLabelViaAriaDescribedbylabelUtils.tsValidate aria-describedby references

Code Conventions

  • All files must start with the Microsoft copyright header:
    // Copyright (c) Microsoft Corporation.
    // Licensed under the MIT License.
  • Use ESLintUtils.RuleCreator.withoutDocs for custom rules.
  • Prefer the makeLabeledControlRule factory for straightforward labeling rules.
  • Report errors on the opening element (node: opening) for accurate source locations.
  • All new rules must be exported from lib/rules/index.ts.
  • Run npm run build after adding or modifying rules to update the dist/ output.
  • Run npm run update:eslint-docs after changing rule metadata to keep documentation in sync.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.