Skip to content

Commit 29f85f2

Browse files
JS-719 Replace dependency jsx-ast-utils with jsx-ast-utils-x (#5625)
1 parent 4d52549 commit 29f85f2

File tree

9 files changed

+129
-22
lines changed

9 files changed

+129
-22
lines changed

generate-eslint-package-json.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const eslintPluginDependencies = [
2323
'builtin-modules',
2424
'bytes',
2525
'functional-red-black-tree',
26-
'jsx-ast-utils',
26+
'jsx-ast-utils-x',
2727
'lodash.merge',
2828
'minimatch',
2929
'scslre',

package-lock.json

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"@types/estree-jsx": "1.0.5",
7171
"@types/express": "5.0.3",
7272
"@types/functional-red-black-tree": "1.0.6",
73-
"@types/jsx-ast-utils": "3.3.1",
7473
"@types/lodash.merge": "4.6.9",
7574
"@types/node": "22.17.2",
7675
"@types/semver": "7.7.0",
@@ -128,7 +127,7 @@
128127
"globals": "16.3.0",
129128
"htmlparser2": "10.0.0",
130129
"http-status-codes": "2.3.0",
131-
"jsx-ast-utils": "3.3.5",
130+
"jsx-ast-utils-x": "0.1.0",
132131
"lodash.merge": "4.6.2",
133132
"minimatch": "9.0.5",
134133
"patch-package": "6.5.1",

packages/jsts/src/rules/S5256/rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import type estree from 'estree';
2020
import type { Rule } from 'eslint';
2121
import type { TSESTree } from '@typescript-eslint/utils';
22-
import pkg from 'jsx-ast-utils';
22+
import pkg from 'jsx-ast-utils-x';
2323
const { getLiteralPropValue, getProp } = pkg;
2424

2525
import { computeGrid } from '../helpers/table.js';

packages/jsts/src/rules/S5264/rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type estree from 'estree';
2121
import type { TSESTree } from '@typescript-eslint/utils';
2222
import { generateMeta, getElementType } from '../helpers/index.js';
2323
import * as meta from './generated-meta.js';
24-
import pkg from 'jsx-ast-utils';
24+
import pkg from 'jsx-ast-utils-x';
2525
const { getLiteralPropValue, getProp, getPropValue } = pkg;
2626
import { JSXAttribute, JSXOpeningElement, JSXSpreadAttribute } from 'estree-jsx';
2727

packages/jsts/src/rules/S6827/decorator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import type { Rule } from 'eslint';
1818
import { generateMeta, interceptReport } from '../helpers/index.js';
19-
import pkg from 'jsx-ast-utils';
19+
import pkg from 'jsx-ast-utils-x';
2020
const { hasAnyProp } = pkg;
2121
import type { JSXOpeningElement } from 'estree-jsx';
2222
import * as meta from './generated-meta.js';
@@ -28,7 +28,6 @@ import * as meta from './generated-meta.js';
2828
*
2929
* This will include the removal of:
3030
* - the `jsx-ast-utils` dependency
31-
* - its type definition `typings/jsx-ast-utils/index.d.ts`
3231
* - all files in the `rules/S6827/` directory
3332
*/
3433
export function decorate(rule: Rule.RuleModule): Rule.RuleModule {

packages/jsts/src/rules/helpers/accessibility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* You should have received a copy of the Sonar Source-Available License
1515
* along with this program; if not, see https://sonarsource.com/license/ssal/
1616
*/
17-
import pkg from 'jsx-ast-utils';
17+
import pkg from 'jsx-ast-utils-x';
1818
const { getProp, getLiteralPropValue, elementType } = pkg;
1919
import type { TSESTree } from '@typescript-eslint/utils';
2020
import type { JSXOpeningElement } from 'estree-jsx';

packages/jsts/src/rules/helpers/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program; if not, see https://sonarsource.com/license/ssal/
1616
*/
1717
import type { TSESTree } from '@typescript-eslint/utils';
18-
import pkg from 'jsx-ast-utils';
18+
import pkg from 'jsx-ast-utils-x';
1919
const { getLiteralPropValue, getProp } = pkg;
2020
import type { Rule } from 'eslint';
2121
import { isHtmlElement } from './isHtmlElement.js';

typings/jsx-ast-utils-x/index.d.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
declare module 'jsx-ast-utils-x' {
2+
import * as ESTree from 'estree';
3+
import * as ESTreeJSX from 'estree-jsx';
4+
5+
export interface GetPropOptions {
6+
/**
7+
* Ignores casing differences in the prop name. Enabled by default.
8+
* @default true
9+
*/
10+
ignoreCase: boolean;
11+
}
12+
13+
export interface HasPropOptions extends GetPropOptions {
14+
/**
15+
* Assumes target property is not in a spread expression applied
16+
* to the element. For example `<div {...props} />` looking for
17+
* specific prop here will return false if `spreadStrict` is true.
18+
* Enabled by default.
19+
* @default true
20+
*/
21+
spreadStrict: boolean;
22+
}
23+
24+
/**
25+
* Returns the tag name associated with a JSXOpeningElement.
26+
* @param node The visited JSXOpeningElement node object.
27+
* @returns The element's tag name.
28+
*/
29+
export function elementType(
30+
node: ESTreeJSX.JSXOpeningElement | ESTreeJSX.JSXOpeningFragment,
31+
): string;
32+
33+
/**
34+
* Returns the value of a given attribute. Different types of attributes have
35+
* their associated values in different properties on the object. This function
36+
* should return a value only if we can extract a literal value from its
37+
* attribute (i.e. values that have generic types in JavaScript including
38+
* strings, numbers, booleans, etc.)
39+
* @param prop The JSXAttribute collected by AST parser.
40+
* @returns The value of the prop.
41+
*/
42+
export function getLiteralPropValue(prop: ESTreeJSX.JSXAttribute): ESTree.Literal['value'];
43+
44+
/**
45+
* Returns the JSXAttribute itself or `undefined`, indicating the prop is not
46+
* present on the JSXOpeningElement.
47+
* @param props The attributes on the visited node (Usually node.attributes).
48+
* @param prop A string representation of the prop you want to retrieve.
49+
* @param options An object representing options for existence checking.
50+
* @returns The JSXAttribute if found, otherwise `undefined`.
51+
*/
52+
export function getProp(
53+
props: ESTreeJSX.JSXOpeningElement['attributes'],
54+
prop: string,
55+
options?: GetPropOptions,
56+
): ESTreeJSX.JSXAttribute | undefined;
57+
58+
/**
59+
* Returns the value of a given attribute. Different types of attributes have
60+
* their associated values in different properties on the object. This function
61+
* should return the most closely associated value with the intention of the JSX.
62+
* @param prop The JSXAttribute collected by AST parser.
63+
* @returns The value of the prop.
64+
*/
65+
export function getPropValue(prop: ESTreeJSX.JSXAttribute): unknown;
66+
67+
/**
68+
* Returns a boolean indicating if ANY of props in prop argument exist on the node.
69+
* @param props The attributes on the visited node (Usually node.attributes).
70+
* @param prop An array of strings representing the props you want to check for existence.
71+
* @param options An object representing options for existence checking.
72+
* @returns A boolean asserting the existence of some of the props.
73+
*/
74+
export function hasAnyProp(
75+
props: ESTreeJSX.JSXOpeningElement['attributes'],
76+
prop: string[],
77+
options?: HasPropOptions,
78+
): boolean;
79+
80+
/**
81+
* Returns a boolean indicating if ALL of props in prop argument exist on the node.
82+
* @param props The attributes on the visited node (Usually node.attributes).
83+
* @param prop An array of strings representing the props you want to check for existence.
84+
* @param options An object representing options for existence checking.
85+
* @returns A boolean asserting the existence of all of the props.
86+
*/
87+
export function hasEveryProp(
88+
props: ESTreeJSX.JSXOpeningElement['attributes'],
89+
prop: string[],
90+
options?: HasPropOptions,
91+
): boolean;
92+
93+
/**
94+
* Returns boolean indicating whether an prop exists as an attribute on a JSX element node.
95+
* @param props The attributes on the visited node (Usually node.attributes).
96+
* @param prop A string representation of the prop you want to check for existence.
97+
* @param options An object representing options for existence checking.
98+
* @returns A boolean asserting the existence of the prop.
99+
*/
100+
export function hasProp(
101+
props: ESTreeJSX.JSXOpeningElement['attributes'],
102+
prop: string,
103+
options?: HasPropOptions,
104+
): boolean;
105+
106+
/**
107+
* Returns the name associated with a JSXAttribute. For example, given `<div foo="bar" />`
108+
* and the JSXAttribute for foo, this will return the string "foo".
109+
* @param prop The JSXAttribute collected by AST parser.
110+
* @returns The name of the attribute.
111+
*/
112+
export function propName(prop: ESTreeJSX.JSXAttribute): string;
113+
}

0 commit comments

Comments
 (0)