Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update rule meta to satisfiy lint rules #621

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ This config will be interpreted in the following way:

| Name                                        | Description | 💼 | 🔧 ||
| :------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- | :- | :- | :- |
| [a11y-aria-label-is-well-formatted](docs/rules/a11y-aria-label-is-well-formatted.md) | [aria-label] text should be formatted as you would visual text. | ⚛️ | | |
| [a11y-aria-label-is-well-formatted](docs/rules/a11y-aria-label-is-well-formatted.md) | enforce [aria-label] text to be formatted as you would visual text. | ⚛️ | | |
| [a11y-no-generic-link-text](docs/rules/a11y-no-generic-link-text.md) | disallow generic link text | | ||
| [a11y-no-title-attribute](docs/rules/a11y-no-title-attribute.md) | Guards against developers using the title attribute | ⚛️ | | |
| [a11y-no-visually-hidden-interactive-element](docs/rules/a11y-no-visually-hidden-interactive-element.md) | Ensures that interactive elements are not visually hidden | ⚛️ | | |
| [a11y-role-supports-aria-props](docs/rules/a11y-role-supports-aria-props.md) | Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. | ⚛️ | | |
| [a11y-svg-has-accessible-name](docs/rules/a11y-svg-has-accessible-name.md) | SVGs must have an accessible name | ⚛️ | | |
| [a11y-no-title-attribute](docs/rules/a11y-no-title-attribute.md) | disallow using the title attribute | ⚛️ | | |
| [a11y-no-visually-hidden-interactive-element](docs/rules/a11y-no-visually-hidden-interactive-element.md) | enforce that interactive elements are not visually hidden | ⚛️ | | |
| [a11y-role-supports-aria-props](docs/rules/a11y-role-supports-aria-props.md) | enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. | ⚛️ | | |
| [a11y-svg-has-accessible-name](docs/rules/a11y-svg-has-accessible-name.md) | require SVGs to have an accessible name | ⚛️ | | |
| [array-foreach](docs/rules/array-foreach.md) | enforce `for..of` loops over `Array.forEach` || | |
| [async-currenttarget](docs/rules/async-currenttarget.md) | disallow `event.currentTarget` calls inside of async functions | 🔍 | | |
| [async-preventdefault](docs/rules/async-preventdefault.md) | disallow `event.preventDefault` calls inside of async functions | 🔍 | | |
| [authenticity-token](docs/rules/authenticity-token.md) | disallow usage of CSRF tokens in JavaScript | 🔐 | | |
| [filenames-match-regex](docs/rules/filenames-match-regex.md) | ensure filenames match a regex naming convention | | | |
| [filenames-match-regex](docs/rules/filenames-match-regex.md) | require filenames to match a regex naming convention | | | |
| [get-attribute](docs/rules/get-attribute.md) | disallow wrong usage of attribute names | 🔍 | 🔧 | |
| [js-class-name](docs/rules/js-class-name.md) | enforce a naming convention for js- prefixed classes | 🔐 | | |
| [no-blur](docs/rules/no-blur.md) | disallow usage of `Element.prototype.blur()` | 🔍 | | |
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/a11y-aria-label-is-well-formatted.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [aria-label] text should be formatted as you would visual text (`github/a11y-aria-label-is-well-formatted`)
# Enforce [aria-label] text to be formatted as you would visual text (`github/a11y-aria-label-is-well-formatted`)

💼 This rule is enabled in the ⚛️ `react` config.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/a11y-no-title-attribute.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Guards against developers using the title attribute (`github/a11y-no-title-attribute`)
# Disallow using the title attribute (`github/a11y-no-title-attribute`)

💼 This rule is enabled in the ⚛️ `react` config.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ensures that interactive elements are not visually hidden (`github/a11y-no-visually-hidden-interactive-element`)
# Enforce that interactive elements are not visually hidden (`github/a11y-no-visually-hidden-interactive-element`)

💼 This rule is enabled in the ⚛️ `react` config.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/a11y-svg-has-accessible-name.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SVGs must have an accessible name (`github/a11y-svg-has-accessible-name`)
# Require SVGs to have an accessible name (`github/a11y-svg-has-accessible-name`)

💼 This rule is enabled in the ⚛️ `react` config.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/filenames-match-regex.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ensure filenames match a regex naming convention (`github/filenames-match-regex`)
# Require filenames to match a regex naming convention (`github/filenames-match-regex`)

<!-- end auto-generated rule header -->

Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = [
'eslint-plugin/prefer-placeholders': 'off',
'eslint-plugin/test-case-shorthand-strings': 'off',
'eslint-plugin/require-meta-docs-url': 'off',
'eslint-plugin/require-meta-default-options': 'off',
},
},
]
9 changes: 7 additions & 2 deletions lib/rules/a11y-aria-label-is-well-formatted.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ const {getProp} = require('jsx-ast-utils')

module.exports = {
meta: {
type: 'problem',
docs: {
description: '[aria-label] text should be formatted as you would visual text.',
description: 'enforce [aria-label] text to be formatted as you would visual text.',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
formatting: '[aria-label] text should be formatted the same as you would visual text. Use sentence case.',
},
},

create(context) {
Expand All @@ -22,7 +27,7 @@ module.exports = {
if (ariaLabel.match(/^[a-z]+.*$/)) {
context.report({
node,
message: '[aria-label] text should be formatted the same as you would visual text. Use sentence case.',
messageId: 'formatting',
})
}
},
Expand Down
15 changes: 10 additions & 5 deletions lib/rules/a11y-no-generic-link-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ const stripAndDowncaseText = text => {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow generic link text',
url: require('../url')(module),
recommended: false,
},
deprecated: true,
replacedBy: ['jsx-a11y/anchor-ambiguous-text'],
schema: [],
messages: {
avoidGenericLinkText:
'Avoid setting generic link text like `Here`, `Click here`, `Read more`. Make sure that your link text is both descriptive and concise.',
ariaLabelDescriptive: 'When using ARIA to set a more descriptive text, it must fully contain the visible label.',
},
},

create(context) {
Expand All @@ -47,23 +54,21 @@ module.exports = {
if (bannedLinkText.includes(cleanAriaLabelValue)) {
context.report({
node,
message:
'Avoid setting generic link text like `Here`, `Click here`, `Read more`. Make sure that your link text is both descriptive and concise.',
messageId: 'avoidGenericLinkText',
})
}
if (cleanTextContent && !cleanAriaLabelValue.includes(cleanTextContent)) {
context.report({
node,
message: 'When using ARIA to set a more descriptive text, it must fully contain the visible label.',
messageId: 'ariaLabelDescriptive',
})
}
} else {
if (cleanTextContent) {
if (!bannedLinkText.includes(cleanTextContent)) return
context.report({
node: jsxTextNode,
message:
'Avoid setting generic link text like `Here`, `Click here`, `Read more`. Make sure that your link text is both descriptive and concise.',
messageId: 'avoidGenericLinkText',
})
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/rules/a11y-no-title-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ const ifSemanticElement = (context, node) => {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Guards against developers using the title attribute',
description: 'disallow using the title attribute',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
titleAttribute: 'The title attribute is not accessible and should never be used unless for an `<iframe>`.',
},
},

create(context) {
Expand All @@ -56,7 +61,7 @@ module.exports = {
if (titleProp) {
context.report({
node,
message: 'The title attribute is not accessible and should never be used unless for an `<iframe>`.',
messageId: 'titleAttribute',
})
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/rules/a11y-no-visually-hidden-interactive-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ const checkIfVisuallyHiddenAndInteractive = (context, options, node, isParentVis

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Ensures that interactive elements are not visually hidden',
description: 'enforce that interactive elements are not visually hidden',
url: require('../url')(module),
recommended: false,
},
schema: [schema],
messages: {
avoid:
'Avoid visually hidding interactive elements. Visually hiding interactive elements can be confusing to sighted keyboard users as it appears their focus has been lost when they navigate to the hidden element.',
},
},

create(context) {
Expand All @@ -75,8 +81,7 @@ module.exports = {
if (checkIfVisuallyHiddenAndInteractive(context, {className, componentName}, node, false)) {
context.report({
node,
message:
'Avoid visually hidding interactive elements. Visually hiding interactive elements can be confusing to sighted keyboard users as it appears their focus has been lost when they navigate to the hidden element.',
messageId: 'avoid',
})
}
},
Expand Down
13 changes: 11 additions & 2 deletions lib/rules/a11y-role-supports-aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ const {getRole} = require('../utils/get-role')

module.exports = {
meta: {
type: 'problem',
docs: {
description:
'Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`.',
'enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`.',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
notSupported: 'The attribute {{attr}} is not supported by the role {{role}}.',
},
},

create(context) {
Expand Down Expand Up @@ -51,7 +56,11 @@ module.exports = {
if (prohibitedProps?.includes(propName(prop))) {
context.report({
node,
message: `The attribute ${propName(prop)} is not supported by the role ${role}.`,
messageId: 'notSupported',
data: {
attr: propName(prop),
role,
},
})
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/rules/a11y-svg-has-accessible-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ const {getElementType} = require('../utils/get-element-type')

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'SVGs must have an accessible name',
description: 'require SVGs to have an accessible name',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
accessibleName:
'`<svg>` must have an accessible name. Set `aria-label` or `aria-labelledby`, or nest a `<title>` element. However, if the `<svg>` is purely decorative, hide it with `aria-hidden="true"` or `role="presentation"`.',
},
},

create(context) {
Expand Down Expand Up @@ -35,8 +41,7 @@ module.exports = {
if (elementType === 'svg' && !hasAccessibleName && !isDecorative && !hasNestedTitleAsFirstChild) {
context.report({
node,
message:
'`<svg>` must have an accessible name. Set `aria-label` or `aria-labelledby`, or nest a `<title>` element. However, if the `<svg>` is purely decorative, hide it with `aria-hidden="true"` or `role="presentation"`.',
messageId: 'accessibleName',
})
}
},
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/array-foreach.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ module.exports = {
docs: {
description: 'enforce `for..of` loops over `Array.forEach`',
url: require('../url')(module),
recommended: true,
},
schema: [],
messages: {
preferForOf: 'Prefer for...of instead of Array.forEach',
},
},

create(context) {
return {
CallExpression(node) {
if (node.callee.property && node.callee.property.name === 'forEach') {
context.report({node, message: 'Prefer for...of instead of Array.forEach'})
context.report({node, messageId: 'preferForOf'})
}
},
}
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/async-currenttarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ module.exports = {
docs: {
description: 'disallow `event.currentTarget` calls inside of async functions',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
asyncCurrentTarget: 'event.currentTarget inside an async function is error prone',
},
},

create(context) {
Expand All @@ -23,7 +27,7 @@ module.exports = {
if (scopeDidWait.has(scope)) {
context.report({
node,
message: 'event.currentTarget inside an async function is error prone',
messageId: 'asyncCurrentTarget',
})
break
}
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/async-preventdefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ module.exports = {
docs: {
description: 'disallow `event.preventDefault` calls inside of async functions',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
eventPreventDefault: 'event.preventDefault() inside an async function is error prone',
},
},

create(context) {
Expand All @@ -23,7 +27,7 @@ module.exports = {
if (scopeDidWait.has(scope)) {
context.report({
node,
message: 'event.preventDefault() inside an async function is error prone',
messageId: 'eventPreventDefault',
})
break
}
Expand Down
8 changes: 6 additions & 2 deletions lib/rules/authenticity-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ module.exports = {
docs: {
description: 'disallow usage of CSRF tokens in JavaScript',
url: require('../url')(module),
recommended: false,
},
schema: [],
messages: {
authenticityTokenUsage:
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
},
},

create(context) {
function checkAuthenticityTokenUsage(node, str) {
if (str.includes('authenticity_token')) {
context.report({
node,
message:
'Form CSRF tokens (authenticity tokens) should not be created in JavaScript and their values should not be used directly for XHR requests.',
messageId: 'authenticityTokenUsage',
})
}
}
Expand Down
14 changes: 11 additions & 3 deletions lib/rules/filenames-match-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {
meta: {
type: 'problem',
docs: {
description: 'ensure filenames match a regex naming convention',
description: 'require filenames to match a regex naming convention',
url: require('../url')(module),
recommended: true,
},
schema: {
type: 'array',
Expand All @@ -22,6 +23,9 @@ module.exports = {
},
],
},
messages: {
regex: "Filename '{{name}}' does not match the regex naming convention.",
},
},

create(context) {
Expand All @@ -42,8 +46,12 @@ module.exports = {
if (shouldIgnore) return
if (ignoreExporting && isExporting) return
if (!matchesRegex) {
context.report(node, "Filename '{{name}}' does not match the regex naming convention.", {
name: parsed.base,
context.report({
node,
messageId: 'regex',
data: {
name: parsed.base,
},
})
}
},
Expand Down
Loading