Files
Harrison HealeyandGitHub a9462cd85c MM-69002 Convert ESLint configs to flat config (#36750)
* 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
2026-06-01 12:03:05 -04:00

50 lines
1.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
export default {
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,
};
},
};