Skip to content

Commit

Permalink
Merge pull request #122 from microsoft/user/aubreyquinn/fixIndex
Browse files Browse the repository at this point in the history
User/aubreyquinn/fix index
  • Loading branch information
aubreyquinn authored Sep 27, 2024
2 parents 1638988 + 9df9e71 commit 862ee6b
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 327 deletions.
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ or contact [[email protected]](mailto:[email protected]) with any addi

- Install [Visual Studio Code](https://code.visualstudio.com/).

- Install [Node.js](https://nodejs.org/en/), with [nvm](https://github.com/nvm-sh/nvm). Please use node version 16.
- Install [Node.js](https://nodejs.org/en/), with [nvm](https://github.com/nvm-sh/nvm). Please use Node version 16 and npm v 8.

- **Internal collaborators:** Please send Aubrey Quinn your email address. After getting `Write` access, you can create branches and directly submit pull requests against this repo.
- **Internal collaborators:** Please send Aubrey Quinn your email address. After getting `Write` access, you can create branches and directly submit pull requests against this repo. Make and submit changes following the [pull request submission workflow](#pull-requests)
- **External collaborators:** [Fork the repo and clone your fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo)

- Install the dependencies
Expand All @@ -49,13 +49,13 @@ or contact [[email protected]](mailto:[email protected]) with any addi

## To create a new ESLint rule

### eslint:rule
If you want to create a new ESLint rule:

If you want to create a new ESLint rule, make sure you're in the top-level directory and type:
```sh
yo eslint:rule
```
1. create a rule file under `lib/rules`
2. create a doc file under `docs`
3. create a test file under `tests`
4. add your rule to `lib/rules/index.ts`
5. add your rule to `index.ts`

## Pull requests

Expand Down
105 changes: 35 additions & 70 deletions README.md

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions dist/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
console.log("Loading my-eslint-plugin");
const prefer_aria_over_title_attribute_1 = __importDefault(require("./rules/prefer-aria-over-title-attribute"));
const checkbox_needs_labelling_1 = __importDefault(require("./rules/checkbox-needs-labelling"));
const image_button_missing_aria_1 = __importDefault(require("./rules/buttons/image-button-missing-aria"));
const link_missing_labelling_1 = __importDefault(require("./rules/link-missing-labelling"));
const input_components_require_accessible_name_1 = __importDefault(require("./rules/input-components-require-accessible-name"));
const menu_item_needs_labelling_1 = __importDefault(require("./rules/menu-item-needs-labelling"));
const switch_needs_labelling_1 = __importDefault(require("./rules/switch-needs-labelling"));
const toolbar_missing_aria_1 = __importDefault(require("./rules/toolbar-missing-aria"));
const combobox_needs_labelling_1 = __importDefault(require("./rules/combobox-needs-labelling"));
const no_empty_components_1 = __importDefault(require("./rules/no-empty-components"));
const accordion_header_needs_labelling_1 = __importDefault(require("./rules/accordion-header-needs-labelling"));
const accordion_item_needs_header_and_panel_1 = __importDefault(require("./rules/accordion-item-needs-header-and-panel"));
const compound_button_needs_labelling_1 = __importDefault(require("./rules/buttons/compound-button-needs-labelling"));
const no_empty_buttons_1 = __importDefault(require("./rules/buttons/no-empty-buttons"));
const spin_button_needs_labelling_1 = __importDefault(require("./rules/spin-button-needs-labelling"));
const spin_button_unrecommended_labelling_1 = __importDefault(require("./rules/spin-button-unrecommended-labelling"));
const breadcrumb_needs_labelling_1 = __importDefault(require("./rules/breadcrumb-needs-labelling"));
const dropdown_needs_labelling_1 = __importDefault(require("./rules/dropdown-needs-labelling"));
const tooltip_not_recommended_1 = __importDefault(require("./rules/tooltip-not-recommended"));
const avatar_needs_name_1 = __importDefault(require("./rules/avatar-needs-name"));
const radio_button_missing_label_1 = __importDefault(require("./rules/radio-button-missing-label"));
const radiogroup_missing_label_1 = __importDefault(require("./rules/radiogroup-missing-label"));
const dialogbody_needs_title_content_and_actions_1 = __importDefault(require("./rules/dialogbody-needs-title-content-and-actions"));
const dialogsurface_needs_aria_1 = __importDefault(require("./rules/dialogsurface-needs-aria"));
const spinner_needs_labelling_1 = __importDefault(require("./rules/spinner-needs-labelling"));
const badge_needs_accessible_name_1 = __importDefault(require("./rules/badge-needs-accessible-name"));
const progressbar_needs_labelling_1 = __importDefault(require("./rules/progressbar-needs-labelling"));
const field_needs_labelling_1 = __importDefault(require("./rules/field-needs-labelling"));
const tablist_and_tabs_need_labelling = __importDefault(require("./rules/tablist-and-tabs-need-labelling"));
const rules = __importStar(require("./rules"));
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand All @@ -44,67 +35,76 @@ const tablist_and_tabs_need_labelling = __importDefault(require("./rules/tablist
// import all rules in lib/rules
module.exports = {
rules: {
"checkbox-needs-labelling": checkbox_needs_labelling_1.default,
"image-button-missing-aria": image_button_missing_aria_1.default,
"link-missing-labelling": link_missing_labelling_1.default,
"input-components-require-accessible-name": input_components_require_accessible_name_1.default,
"menu-item-needs-labelling": menu_item_needs_labelling_1.default,
"switch-needs-labelling": switch_needs_labelling_1.default,
"toolbar-missing-aria": toolbar_missing_aria_1.default,
"combobox-needs-labelling": combobox_needs_labelling_1.default,
"no-empty-components": no_empty_components_1.default,
"accordion-header-needs-labelling": accordion_header_needs_labelling_1.default,
"accordion-item-needs-header-and-panel": accordion_item_needs_header_and_panel_1.default,
"compound-button-needs-labelling": compound_button_needs_labelling_1.default,
"no-empty-buttons": no_empty_buttons_1.default,
"spin-button-needs-labelling": spin_button_needs_labelling_1.default,
"spin-button-unrecommended-labelling": spin_button_unrecommended_labelling_1.default,
"breadcrumb-needs-labelling": breadcrumb_needs_labelling_1.default,
"dropdown-needs-labelling": dropdown_needs_labelling_1.default,
"tooltip-not-recommended": tooltip_not_recommended_1.default,
"avatar-needs-name": avatar_needs_name_1.default,
"radio-button-missing-label": radio_button_missing_label_1.default,
"radiogroup-missing-label": radiogroup_missing_label_1.default,
"prefer-aria-over-title-attribute": prefer_aria_over_title_attribute_1.default,
"dialogbody-needs-title-content-and-actions": dialogbody_needs_title_content_and_actions_1.default,
"dialogsurface-needs-aria": dialogsurface_needs_aria_1.default,
"spinner-needs-labelling": spinner_needs_labelling_1.default,
"badge-needs-accessible-name": badge_needs_accessible_name_1.default,
"progressbar-needs-labelling": progressbar_needs_labelling_1.default,
"field-needs-labelling": field_needs_labelling_1.default,
"tablist-and-tabs-need-labelling": tablist_and_tabs_need_labelling.default
"accordion-header-needs-labelling": rules.accordionHeaderNeedsLabelling,
"accordion-item-needs-header-and-panel": rules.accordionItemNeedsHeaderAndPanel,
"avatar-needs-name": rules.avatarNeedsName,
"avoid-using-aria-describedby-for-primary-labelling": rules.avoidUsingAriaDescribedByForPrimaryLabelling,
"badge-needs-accessible-name": rules.badgeNeedsAccessibleName,
"breadcrumb-needs-labelling": rules.breadcrumbNeedsLabelling,
"checkbox-needs-labelling": rules.checkboxNeedsLabelling,
"combobox-needs-labelling": rules.comboboxNeedsLabelling,
"compound-button-needs-labelling": rules.compoundButtonNeedsLabelling,
"counter-badge-needs-count": rules.counterBadgeNeedsCount,
"dialogbody-needs-title-content-and-actions": rules.dialogbodyNeedsTitleContentAndActions,
"dialogsurface-needs-aria": rules.dialogsurfaceNeedsAria,
"dropdown-needs-labelling": rules.dropdownNeedsLabelling,
"field-needs-labelling": rules.fieldNeedsLabelling,
"image-button-missing-aria": rules.imageButtonMissingAria,
"input-components-require-accessible-name": rules.inputComponentsRequireAccessibleName,
"link-missing-labelling": rules.linkMissingLabelling,
"menu-item-needs-labelling": rules.menuItemNeedsLabelling,
"no-empty-buttons": rules.noEmptyButtons,
"no-empty-components": rules.noEmptyComponents,
"prefer-aria-over-title-attribute": rules.preferAriaOverTitleAttribute,
"progressbar-needs-labelling": rules.progressbarNeedsLabelling,
"radio-button-missing-label": rules.radioButtonMissingLabel,
"radiogroup-missing-label": rules.radiogroupMissingLabel,
"rating-needs-name": rules.ratingNeedsName,
"spin-button-needs-labelling": rules.spinButtonNeedsLabelling,
"spin-button-unrecommended-labelling": rules.spinButtonUnrecommendedLabelling,
"spinner-needs-labelling": rules.spinnerNeedsLabelling,
"switch-needs-labelling": rules.switchNeedsLabelling,
"tablist-and-tabs-need-labelling": rules.tablistAndTabsNeedLabelling,
"toolbar-missing-aria": rules.toolbarMissingAria,
"tooltip-not-recommended": rules.tooltipNotRecommended,
"visual-label-better-than-aria-suggestion": rules.visualLabelBetterThanAriaSuggestion
},
configs: {
recommended: {
rules: {
"@microsoft/fluentui-jsx-a11y/checkbox-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/link-missing-labelling": "error",
"@microsoft/fluentui-jsx-a11y/input-components-require-accessible-name": "error",
"@microsoft/fluentui-jsx-a11y/menu-item-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/switch-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/image-button-missing-aria": "error",
"@microsoft/fluentui-jsx-a11y/toolbar-missing-aria": "error",
"@microsoft/fluentui-jsx-a11y/combobox-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/no-empty-components": "error",
"@microsoft/fluentui-jsx-a11y/accordion-header-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/accordion-item-needs-header-and-panel": "error",
"@microsoft/fluentui-jsx-a11y/compound-button-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/no-empty-buttons": "error",
"@microsoft/fluentui-jsx-a11y/spin-button-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/spin-button-unrecommended-labelling": "error",
"@microsoft/fluentui-jsx-a11y/avatar-needs-name": "error",
"@microsoft/fluentui-jsx-a11y/avoid-using-aria-describedby-for-primary-labelling": "error",
"@microsoft/fluentui-jsx-a11y/badge-needs-accessible-name": "error",
"@microsoft/fluentui-jsx-a11y/breadcrumb-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/checkbox-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/combobox-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/compound-button-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/counter-badge-needs-count": "error",
"@microsoft/fluentui-jsx-a11y/dialogbody-needs-title-content-and-actions": "error",
"@microsoft/fluentui-jsx-a11y/dialogsurface-needs-aria": "error",
"@microsoft/fluentui-jsx-a11y/dropdown-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/tooltip-not-recommended": "error",
"@microsoft/fluentui-jsx-a11y/avatar-needs-name": "error",
"@microsoft/fluentui-jsx-a11y/field-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/image-button-missing-aria": "error",
"@microsoft/fluentui-jsx-a11y/input-components-require-accessible-name": "error",
"@microsoft/fluentui-jsx-a11y/link-missing-labelling": "error",
"@microsoft/fluentui-jsx-a11y/menu-item-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/no-empty-buttons": "error",
"@microsoft/fluentui-jsx-a11y/no-empty-components": "error",
"@microsoft/fluentui-jsx-a11y/prefer-aria-over-title-attribute": "warn",
"@microsoft/fluentui-jsx-a11y/progressbar-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/radio-button-missing-label": "error",
"@microsoft/fluentui-jsx-a11y/radiogroup-missing-label": "error",
"@microsoft/fluentui-jsx-a11y/prefer-aria-over-title-attribute": "warn",
"@microsoft/fluentui-jsx-a11y/dialogbody-needs-title-content-and-actions": "error",
"@microsoft/fluentui-jsx-a11y/dialogsurface-needs-aria": "error",
"@microsoft/fluentui-jsx-a11y/rating-needs-name": "error",
"@microsoft/fluentui-jsx-a11y/spin-button-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/spin-button-unrecommended-labelling": "error",
"@microsoft/fluentui-jsx-a11y/spinner-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/progressbar-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/field-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/tablist-and-tabs-need-labelling": "error"
"@microsoft/fluentui-jsx-a11y/switch-needs-labelling": "error",
"@microsoft/fluentui-jsx-a11y/tablist-and-tabs-need-labelling": "error",
"@microsoft/fluentui-jsx-a11y/toolbar-missing-aria": "error",
"@microsoft/fluentui-jsx-a11y/tooltip-not-recommended": "error",
"@microsoft/fluentui-jsx-a11y/visual-label-better-than-aria-suggestion": "warn"
}
}
}
Expand Down
18 changes: 2 additions & 16 deletions dist/lib/rules/tablist-and-tabs-need-labelling.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
export namespace meta {
namespace messages {
let missingTabLabel: string;
let missingTablistLabel: string;
}
let type: string;
namespace docs {
let description: string;
let recommended: boolean;
let url: string;
}
let schema: never[];
}
export function create(context: any): {
JSXOpeningElement(node: any): void;
};
declare const _exports: import("eslint").Rule.RuleModule;
export = _exports;
85 changes: 37 additions & 48 deletions dist/lib/rules/tablist-and-tabs-need-labelling.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
Expand All @@ -23,54 +20,46 @@ module.exports = {
missingTablistLabel: 'Accessibility: Tablist must have an accessible label'
},
},

create(context) {
const { hasTextContentChild } = require('../util/hasTextContentChild');
const { hasNonEmptyProp } = require('../util/hasNonEmptyProp');
const { hasAssociatedLabelViaAriaLabelledBy } = require('../util/labelUtils');

var elementType = require("jsx-ast-utils").elementType;

return {

// visitor functions for different types of nodes
JSXOpeningElement(node) {
const elementTypeValue = elementType(node);

// if it is not a Tablist or Tab, return
if (elementTypeValue !== 'Tablist' && elementTypeValue !== 'Tab') {
return;
}

// Check for Tablist elements
if (elementTypeValue === "Tablist") {
if (
create(context) {
const { hasTextContentChild } = require('../util/hasTextContentChild');
const { hasNonEmptyProp } = require('../util/hasNonEmptyProp');
const { hasAssociatedLabelViaAriaLabelledBy } = require('../util/labelUtils');
var elementType = require("jsx-ast-utils").elementType;
return {
// visitor functions for different types of nodes
JSXOpeningElement(node) {
const elementTypeValue = elementType(node);
// if it is not a Tablist or Tab, return
if (elementTypeValue !== 'Tablist' && elementTypeValue !== 'Tab') {
return;
}
// Check for Tablist elements
if (elementTypeValue === "Tablist") {
if (
// if the Tablist has a label, if the Tablist has an associated label, return
hasNonEmptyProp(node.attributes, 'aria-label') || //aria-label
hasAssociatedLabelViaAriaLabelledBy(node, context) // aria-labelledby
) {
return;
hasAssociatedLabelViaAriaLabelledBy(node, context) // aria-labelledby
) {
return;
}
context.report({
node,
messageId: 'missingTablistLabel'
});
}
context.report({
node,
messageId: 'missingTablistLabel'
});
}

// Check for Tab elements
if (elementTypeValue === 'Tab') {
if (
hasTextContentChild(node.parent) || // text content
hasNonEmptyProp(node.attributes, 'aria-label') // aria-label
) {
return;
// Check for Tab elements
if (elementTypeValue === 'Tab') {
if (hasTextContentChild(node.parent) || // text content
hasNonEmptyProp(node.attributes, 'aria-label') // aria-label
) {
return;
}
context.report({
node,
messageId: 'missingTabLabel'
});
}
context.report({
node,
messageId: 'missingTabLabel'
});
}
}
};
},
};
},
};
Loading

0 comments on commit 862ee6b

Please sign in to comment.