mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* MM-68153 Migrate all ESLint configuration to flat config files * Use shared ESLint plugin and ESLint configuration to lint shared ESLint plugin and ESLint configuration as well as non-shared ESLint configuration
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import astUtils from 'jsx-ast-utils';
|
|
|
|
export default {
|
|
meta: {
|
|
docs: {
|
|
description: 'Enforce all anchors with target="_blank" to use ExternalLink component',
|
|
},
|
|
},
|
|
create: (context) => {
|
|
return {
|
|
JSXOpeningElement: (node) => {
|
|
const typeCheck = 'a';
|
|
const nodeType = astUtils.elementType(node);
|
|
|
|
// Only check anchor elements
|
|
if (!nodeType || typeCheck !== nodeType) {
|
|
return;
|
|
}
|
|
|
|
const propsToValidate = ['target'];
|
|
const values = propsToValidate.map((prop) => astUtils.getPropValue(astUtils.getProp(node.attributes, prop)));
|
|
|
|
// Checks if the target attribute is set to _blank (ie, is an external link)
|
|
const hasBlankTarget = values.some((value) => value != null && value === '_blank');
|
|
|
|
// When there is no target value at all, this rule does not apply:
|
|
if (!hasBlankTarget) {
|
|
return;
|
|
}
|
|
|
|
context.report({
|
|
node,
|
|
message: 'Use ExternalLink component (components/external_link) for _blank target link-outs',
|
|
});
|
|
},
|
|
};
|
|
},
|
|
};
|