Files
formipay/node_modules/eslint-plugin-playwright/lib/rules/prefer-to-be.js
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 17:02:14 +07:00

89 lines
3.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ast_1 = require("../utils/ast");
const fixer_1 = require("../utils/fixer");
const parseExpectCall_1 = require("../utils/parseExpectCall");
function shouldUseToBe(expectCall) {
let arg = expectCall.args[0];
if (arg.type === 'UnaryExpression' && arg.operator === '-') {
arg = arg.argument;
}
if (arg.type === 'Literal') {
// regex literals are classed as literals, but they're actually objects
// which means "toBe" will give different results than other matchers
return !('regex' in arg);
}
return arg.type === 'TemplateLiteral';
}
function reportPreferToBe(context, expectCall, whatToBe, notModifier) {
context.report({
fix(fixer) {
const fixes = [
(0, fixer_1.replaceAccessorFixer)(fixer, expectCall.matcher, `toBe${whatToBe}`),
];
if (expectCall.args?.length && whatToBe !== '') {
fixes.push(fixer.remove(expectCall.args[0]));
}
if (notModifier) {
const [start, end] = notModifier.range;
fixes.push(fixer.removeRange([start - 1, end]));
}
return fixes;
},
messageId: `useToBe${whatToBe}`,
node: expectCall.matcher,
});
}
exports.default = {
create(context) {
return {
CallExpression(node) {
const expectCall = (0, parseExpectCall_1.parseExpectCall)(node);
if (!expectCall)
return;
const notMatchers = ['toBeUndefined', 'toBeDefined'];
const notModifier = expectCall.modifiers.find((node) => (0, ast_1.getStringValue)(node) === 'not');
if (notModifier && notMatchers.includes(expectCall.matcherName)) {
return reportPreferToBe(context, expectCall, expectCall.matcherName === 'toBeDefined' ? 'Undefined' : 'Defined', notModifier);
}
const argumentMatchers = ['toBe', 'toEqual', 'toStrictEqual'];
const firstArg = expectCall.args[0];
if (!argumentMatchers.includes(expectCall.matcherName) || !firstArg) {
return;
}
if (firstArg.type === 'Literal' && firstArg.value === null) {
return reportPreferToBe(context, expectCall, 'Null');
}
if ((0, ast_1.isIdentifier)(firstArg, 'undefined')) {
const name = notModifier ? 'Defined' : 'Undefined';
return reportPreferToBe(context, expectCall, name, notModifier);
}
if ((0, ast_1.isIdentifier)(firstArg, 'NaN')) {
return reportPreferToBe(context, expectCall, 'NaN');
}
if (shouldUseToBe(expectCall) && expectCall.matcherName !== 'toBe') {
reportPreferToBe(context, expectCall, '');
}
},
};
},
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `toBe()` for primitive literals',
recommended: false,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-be.md',
},
fixable: 'code',
messages: {
useToBe: 'Use `toBe` when expecting primitive literals',
useToBeDefined: 'Use `toBeDefined` instead',
useToBeNaN: 'Use `toBeNaN` instead',
useToBeNull: 'Use `toBeNull` instead',
useToBeUndefined: 'Use `toBeUndefined` instead',
},
schema: [],
type: 'suggestion',
},
};