Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/pmb/node_modules/eslint-plugin-testing-library/rules/ drwxr-xr-x | |
| Viewing file: Select action/file-type: "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RULE_NAME = void 0;
const create_testing_library_rule_1 = require("../create-testing-library-rule");
const node_utils_1 = require("../node-utils");
exports.RULE_NAME = 'prefer-presence-queries';
exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
name: exports.RULE_NAME,
meta: {
docs: {
description: 'Ensure appropriate `get*`/`query*` queries are used with their respective matchers',
recommendedConfig: {
dom: 'error',
angular: 'error',
react: 'error',
vue: 'error',
marko: 'error',
},
},
messages: {
wrongPresenceQuery: 'Use `getBy*` queries rather than `queryBy*` for checking element is present',
wrongAbsenceQuery: 'Use `queryBy*` queries rather than `getBy*` for checking element is NOT present',
},
schema: [
{
type: 'object',
additionalProperties: false,
properties: {
presence: {
type: 'boolean',
},
absence: {
type: 'boolean',
},
},
},
],
type: 'suggestion',
},
defaultOptions: [
{
presence: true,
absence: true,
},
],
create(context, [{ absence = true, presence = true }], helpers) {
return {
'CallExpression Identifier'(node) {
const expectCallNode = (0, node_utils_1.findClosestCallNode)(node, 'expect');
if (!expectCallNode || !(0, node_utils_1.isMemberExpression)(expectCallNode.parent)) {
return;
}
if (!helpers.isSyncQuery(node)) {
return;
}
const isPresenceQuery = helpers.isGetQueryVariant(node);
const expectStatement = expectCallNode.parent;
const isPresenceAssert = helpers.isPresenceAssert(expectStatement);
const isAbsenceAssert = helpers.isAbsenceAssert(expectStatement);
if (!isPresenceAssert && !isAbsenceAssert) {
return;
}
if (presence && isPresenceAssert && !isPresenceQuery) {
context.report({ node, messageId: 'wrongPresenceQuery' });
}
else if (absence && isAbsenceAssert && isPresenceQuery) {
context.report({ node, messageId: 'wrongAbsenceQuery' });
}
},
};
},
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0067 ]-- |