Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/brown-walls-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-jsx-a11y-x": patch
---

chore: cleanup dependencies with built-in replacements
Empty file removed .env.yarn
Empty file.
726 changes: 2 additions & 724 deletions CHANGELOG.md

Large diffs are not rendered by default.

725 changes: 725 additions & 0 deletions CHANGELOG_LEGACY.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __mocks__/JSXAttributeMock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @flow */

import toAST from 'to-ast'; // eslint-disable-line import-x/no-extraneous-dependencies
import toAST from 'to-ast';
import JSXExpressionContainerMock from './JSXExpressionContainerMock';

export type JSXAttributeMockType = {
Expand Down
3 changes: 1 addition & 2 deletions __mocks__/genInteractives.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @flow */

import { dom, roles } from 'aria-query';
import fromEntries from 'object.fromentries';

import JSXAttributeMock from './JSXAttributeMock';
import JSXElementMock from './JSXElementMock';
Expand Down Expand Up @@ -120,7 +119,7 @@ const nonInteractiveElementsMap: { [string]: Array<{ [string]: string }> } = {
};

const indeterminantInteractiveElementsMap: { [key: string]: Array<any> } =
fromEntries(domElements.map(name => [name, []]));
Object.fromEntries(domElements.map(name => [name, []]));

Object.keys(interactiveElementsMap)
.concat(Object.keys(nonInteractiveElementsMap))
Expand Down
1 change: 0 additions & 1 deletion __tests__/__util__/axeMapping.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle */
import * as axe from 'axe-core';

export function axeFailMessage(checkId, data) {
Expand Down
1 change: 0 additions & 1 deletion __tests__/__util__/helpers/getESLintCoreRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import semver from 'semver';

const isESLintV8 = semver.major(version) >= 8;

// eslint-disable-next-line global-require, import-x/no-dynamic-require, import-x/no-unresolved
const getESLintCoreRule = ruleId =>
isESLintV8
? require('eslint/use-at-your-own-risk').builtinRules.get(ruleId)
Expand Down
4 changes: 1 addition & 3 deletions __tests__/__util__/helpers/parsers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import path from 'path';
import semver from 'semver';
import entries from 'object.entries';
import { version } from 'eslint/package.json';

let tsParserVersion;
try {
// eslint-disable-next-line import-x/no-unresolved, global-require
tsParserVersion = require('@typescript-eslint/parser/package.json').version;
} catch {
//
Expand All @@ -25,7 +23,7 @@ function minEcmaVersion(features, parserOptions) {
...[]
.concat(
(parserOptions && parserOptions.ecmaVersion) || [],
entries(minEcmaVersionForFeatures).flatMap(entry => {
Object.entries(minEcmaVersionForFeatures).flatMap(entry => {
const f = entry[0];
const y = entry[1];
return features.has(f) ? y : [];
Expand Down
10 changes: 4 additions & 6 deletions __tests__/__util__/ruleOptionsMapperFactory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/** @flow */

import entries from 'object.entries';
import fromEntries from 'object.fromentries';

type ESLintTestRunnerTestCase = {
code: string,
errors: ?Array<{ message: string, type: string }>,
Expand All @@ -18,7 +15,6 @@ type RuleOptionsMapperFactoryType = (
export default function ruleOptionsMapperFactory(
ruleOptions: Array<mixed> = [],
): RuleOptionsMapperFactoryType {
// eslint-disable-next-line
return ({
code,
errors,
Expand All @@ -31,8 +27,10 @@ export default function ruleOptionsMapperFactory(
errors,
// Flatten the array of objects in an array of one object.
options: [
fromEntries(
(options || []).concat(ruleOptions).flatMap(item => entries(item)),
Object.fromEntries(
(options || [])
.concat(ruleOptions)
.flatMap(item => Object.entries(item)),
),
],
parserOptions,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('all rule files should be exported by the plugin', t => {
rules.forEach(ruleName => {
t.equal(
plugin.rules[ruleName],
require(path.join('../src/rules', ruleName)), // eslint-disable-line import-x/no-dynamic-require
require(path.join('../src/rules', ruleName)),
`exports ${ruleName}`,
);
});
Expand All @@ -34,7 +34,7 @@ test('configurations', t => {

test('schemas', t => {
rules.forEach(ruleName => {
const rule = require(path.join('../src/rules', ruleName)); // eslint-disable-line import-x/no-dynamic-require
const rule = require(path.join('../src/rules', ruleName));
const schema = rule.meta && rule.meta.schema && rule.meta.schema[0];
const { type } = schema;

Expand Down
45 changes: 33 additions & 12 deletions __tests__/src/rules/label-has-for-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// -----------------------------------------------------------------------------

import { RuleTester } from 'eslint';
import assign from 'object.assign';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/label-has-for';
Expand Down Expand Up @@ -101,19 +100,27 @@ ruleTester.run('label-has-for', rule, {
// CUSTOM ELEMENT ARRAY OPTION TESTS
{
code: '<Label htmlFor="foo" />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Label htmlFor={"foo"} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Label htmlFor={foo} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Label htmlFor={`${id}`} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{ code: '<div />', options: optionsComponents },
{
Expand All @@ -122,27 +129,39 @@ ruleTester.run('label-has-for', rule, {
},
{
code: '<Label htmlFor="foo">Test!</Label>',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Descriptor htmlFor="foo" />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Descriptor htmlFor={"foo"} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Descriptor htmlFor={foo} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Descriptor htmlFor={`${id}`} />',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{
code: '<Descriptor htmlFor="foo">Test!</Descriptor>',
options: [assign({}, optionsComponents[0], optionsRequiredSome[0])],
options: [
Object.assign({}, optionsComponents[0], optionsRequiredSome[0]),
],
},
{ code: '<label htmlFor="foo" />', options: optionsRequiredSome },
{ code: '<label htmlFor={"foo"} />', options: optionsRequiredSome },
Expand All @@ -161,7 +180,9 @@ ruleTester.run('label-has-for', rule, {
{ code: '<label><input /></label>', options: optionsChildrenAllowed },
{
code: '<Descriptor htmlFor="foo">Test!</Descriptor>',
options: [assign({}, optionsComponents, optionsChildrenAllowed)],
options: [
Object.assign({}, optionsComponents, optionsChildrenAllowed),
],
},
{ code: '<label>Test!</label>', options: optionsChildrenAllowed },
{
Expand Down
3 changes: 1 addition & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module.exports = {
presets: [
[
'airbnb',
'@babel/env',
{
targets: {
node: 18,
},
transformRuntime: false,
},
],
],
Expand Down
15 changes: 7 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ const flowPlugin = require('eslint-plugin-ft-flow');
const { FlatCompat } = require('@eslint/eslintrc');
const babelParser = require('@babel/eslint-parser');
const prettierConfig = require('eslint-config-prettier');
const {
createTypeScriptImportResolver,
} = require('eslint-import-resolver-typescript');

const compat = new FlatCompat({
baseDirectory: __dirname,
});

module.exports = defineConfig([
{
ignores: ['lib', 'reports', 'examples'],
ignores: ['.yarn', 'lib', 'reports', 'examples'],
},
{
files: [
Expand All @@ -30,9 +33,7 @@ module.exports = defineConfig([
'import-x': importPlugin.flatConfigs.recommended.plugins['import-x'],
},
languageOptions: {
globals: {
...globals.node,
},
globals: globals.node,
parser: babelParser,
},
extends: [
Expand All @@ -45,7 +46,7 @@ module.exports = defineConfig([
'import-x/no-extraneous-dependencies': 'error',
},
settings: {
'import-x/resolver': 'typescript',
'import-x/resolver-next': createTypeScriptImportResolver(),
},
},
...compat.config(flowPlugin.configs.recommended).map(config => ({
Expand Down Expand Up @@ -86,9 +87,7 @@ module.exports = defineConfig([
{
files: ['__tests__/**/*'],
languageOptions: {
globals: {
jest: true,
},
globals: globals.jest,
},
},
]);
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,21 @@
"emoji-regex": "^9.2.2",
"jsx-ast-utils-x": "^0.1.0",
"language-tags": "^1.0.9",
"minimatch": "^3.1.2",
"object.fromentries": "^2.0.8",
"safe-regex-test": "^1.0.3",
"string.prototype.includes": "^2.0.1"
"minimatch": "^3.1.2"
},
"devDependencies": {
"@1stg/prettier-config": "^5.2.0",
"@babel/cli": "^7.25.9",
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-transform-flow-strip-types": "^7.25.9",
"@babel/preset-env": "^7.27.2",
"@babel/register": "^7.25.9",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.4",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.26.0",
"auto-changelog": "^2.5.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-preset-airbnb": "^5.0.0",
"clean-pkg-json": "^1.3.0",
"eslint": "^9.27.0",
"eslint-config-prettier": "^10.1.5",
Expand All @@ -84,15 +80,12 @@
"eslint-plugin-ft-flow": "^3.0.11",
"eslint-plugin-import-x": "^4.11.1",
"estraverse": "^5.3.0",
"flow-bin": "^0.147.0",
"hermes-eslint": "^0.28.1",
"in-publish": "^2.0.1",
"jackspeak": "=2.1.1",
"jscodeshift": "^17.0.0",
"minimist": "^1.2.8",
"npm-run-all2": "^8.0.2",
"object.assign": "^4.1.5",
"object.entries": "^1.1.8",
"premove": "^4.0.0",
"prettier": "^3.5.3",
"semver": "^6.3.1",
Expand Down
6 changes: 3 additions & 3 deletions scripts/create-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
const path = require('path');
const fs = require('fs');
const { exec } = require('child_process');
const argv = require('minimist')(process.argv.slice(2)); // eslint-disable-line import-x/no-extraneous-dependencies
const jscodeshiftJSON = require('jscodeshift/package.json'); // eslint-disable-line import-x/no-extraneous-dependencies
const argv = require('minimist')(process.argv.slice(2));
const jscodeshiftJSON = require('jscodeshift/package.json');

const ruleBoilerplateGenerator = require('./boilerplate/rule');
const testBoilerplateGenerator = require('./boilerplate/test');
Expand Down Expand Up @@ -54,7 +54,7 @@ exec(
].join(' '),
error => {
if (error) {
console.error(`exec error: ${error}`); // eslint-disable-line no-console
console.error(`exec error: ${error}`);
}
},
);
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable global-require */
const flatConfigBase = require('./configs/flat-config-base');
const legacyConfigBase = require('./configs/legacy-config-base');
const { name, version } = require('../package.json');
Expand Down
6 changes: 3 additions & 3 deletions src/rules/accessible-emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import emojiRegex from 'emoji-regex';
import { getProp, getLiteralPropValue } from 'jsx-ast-utils-x';
import safeRegexTest from 'safe-regex-test';

import { generateObjSchema } from '../util/schemas';
import getElementType from '../util/getElementType';
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
Expand All @@ -33,14 +33,14 @@ export default {
create: context => {
const elementType = getElementType(context);

const testEmoji = safeRegexTest(emojiRegex());
const emojiRegexp = emojiRegex();
return {
JSXOpeningElement: node => {
const literalChildValue = node.parent.children.find(
child => child.type === 'Literal' || child.type === 'JSXText',
);

if (literalChildValue && testEmoji(literalChildValue.value)) {
if (literalChildValue && emojiRegexp.test(literalChildValue.value)) {
const elementIsHidden = isHiddenFromScreenReader(
elementType(node),
node.attributes,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/anchor-is-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import { getProp, getPropValue } from 'jsx-ast-utils-x';
import type { JSXOpeningElement } from 'ast-types-flow';
import safeRegexTest from 'safe-regex-test';
import type {
ESLintConfig,
ESLintContext,
Expand Down Expand Up @@ -52,7 +51,7 @@ export default ({

create: (context: ESLintContext): ESLintVisitorSelectorConfig => {
const elementType = getElementType(context);
const testJShref = safeRegexTest(/^\W*?javascript:/);
const jsHrefRegexp = /^\W*?javascript:/;

return {
JSXOpeningElement: (node: JSXOpeningElement): void => {
Expand Down Expand Up @@ -120,7 +119,7 @@ export default ({
value =>
value != null &&
typeof value === 'string' &&
(!value.length || value === '#' || testJShref(value)),
(!value.length || value === '#' || jsHrefRegexp.test(value)),
);
if (invalidHrefValues.length !== 0) {
// If an onClick is found it should be a button, otherwise it is an invalid link.
Expand Down
Loading
Loading