Move the shared ESLint plugin/config into the monorepo (#24670)
* Move the shared ESLint plugin/config into the monorepo * Add peer dependencies to ESLint plugin
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
def164f790
Коммит
ff929e4a15
49
webapp/platform/eslint-plugin/rules/no-dispatch-getstate.js
Обычный файл
49
webapp/platform/eslint-plugin/rules/no-dispatch-getstate.js
Обычный файл
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
unexpected: 'Unexpected second argument passed to dispatch. getState does not need to be passed into dispatch.',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
function checkDispatch(node) {
|
||||
const args = node.arguments;
|
||||
if (args.length === 2) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unexpected',
|
||||
fix(fixer) {
|
||||
const sourceCode = context.getSourceCode();
|
||||
|
||||
const before = sourceCode.getTokenBefore(args[1]);
|
||||
const after = sourceCode.getTokenAfter(args[1]);
|
||||
|
||||
// Remove the getState argument and the preceding comma
|
||||
const fixes = [
|
||||
fixer.remove(before),
|
||||
fixer.remove(args[1]),
|
||||
];
|
||||
|
||||
// And remove the trailing comma if one exists
|
||||
if (after.type === 'Punctuator' && after.value === ',') {
|
||||
fixes.push(fixer.remove(after));
|
||||
}
|
||||
|
||||
// Note that this sometimes mangles the whitespace slightly
|
||||
|
||||
return fixes;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"CallExpression[callee.name='dispatch']": checkDispatch,
|
||||
"CallExpression[callee.name='doDispatch']": checkDispatch,
|
||||
};
|
||||
},
|
||||
};
|
||||
43
webapp/platform/eslint-plugin/rules/use-external-link.js
Обычный файл
43
webapp/platform/eslint-plugin/rules/use-external-link.js
Обычный файл
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
const astUtils = require('jsx-ast-utils')
|
||||
const getElementType = require('eslint-plugin-jsx-a11y/lib/util/getElementType')
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Enforce all anchors with target="_blank" to use ExternalLink component',
|
||||
},
|
||||
},
|
||||
create: (context) => {
|
||||
const elementType = getElementType(context);
|
||||
return {
|
||||
JSXOpeningElement: (node) => {
|
||||
const { attributes } = node;
|
||||
const typeCheck = 'a';
|
||||
const nodeType = 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',
|
||||
});
|
||||
return
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Ссылка в новой задаче
Block a user