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 = 'no-dom-import';
const DOM_TESTING_LIBRARY_MODULES = [
'dom-testing-library',
'@testing-library/dom',
];
const correctModuleNameByFramework = {
angular: '@testing-library/angular',
marko: '@marko/testing-library',
};
const getCorrectModuleName = (moduleName, framework) => correctModuleNameByFramework[framework] ||
moduleName.replace('dom', framework);
exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
name: exports.RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Disallow importing from DOM Testing Library',
recommendedConfig: {
dom: false,
angular: ['error', 'angular'],
react: ['error', 'react'],
vue: ['error', 'vue'],
marko: ['error', 'marko'],
},
},
messages: {
noDomImport: 'import from DOM Testing Library is restricted, import from corresponding Testing Library framework instead',
noDomImportFramework: 'import from DOM Testing Library is restricted, import from {{module}} instead',
},
fixable: 'code',
schema: [{ type: 'string' }],
},
defaultOptions: [''],
create(context, [framework], helpers) {
function report(node, moduleName) {
if (!framework) {
return context.report({
node,
messageId: 'noDomImport',
});
}
const correctModuleName = getCorrectModuleName(moduleName, framework);
context.report({
data: { module: correctModuleName },
fix(fixer) {
if ((0, node_utils_1.isCallExpression)(node)) {
const name = node.arguments[0];
return fixer.replaceText(name, name.raw.replace(moduleName, correctModuleName));
}
else {
const name = node.source;
return fixer.replaceText(name, name.raw.replace(moduleName, correctModuleName));
}
},
messageId: 'noDomImportFramework',
node,
});
}
return {
'Program:exit'() {
const importName = helpers.getTestingLibraryImportName();
const importNode = helpers.getTestingLibraryImportNode();
if (!importNode) {
return;
}
const domModuleName = DOM_TESTING_LIBRARY_MODULES.find((module) => module === importName);
if (!domModuleName) {
return;
}
report(importNode, domModuleName);
},
};
},
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0048 ]-- |