123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const schema = [
- {
- type: 'string',
- },
- ];
- const message = '$FlowFixMe is treated as \'any\' and must be fixed.';
- const isIdentifier = (node, name) => (
- node && node.type === 'Identifier' && node.name.match(name)
- );
- const create = (context) => {
- const allowedPattern = context.options[0] ? new RegExp(context.options[0], 'u') : null;
- const extraMessage = allowedPattern ? ` Fix it or match '${allowedPattern.toString()}'.` : '';
- const passesExtraRegex = (value) => {
- if (!allowedPattern) {
- return false;
- }
- return value.match(allowedPattern);
- };
- const handleComment = (comment) => {
- const value = comment.value.trim();
- if (/\$FlowFixMe/u.test(value) && !passesExtraRegex(value)) {
- context.report({
- message: message + extraMessage,
- node: comment,
- });
- }
- };
- return {
- GenericTypeAnnotation(node) {
- if (isIdentifier(node.id, /\$FlowFixMe/u)) {
- context.report({
- message,
- node: node.id,
- });
- }
- },
- Program() {
- for (const comment of context
- .getSourceCode()
- .getAllComments()
- .filter((node) => node.type === 'Block' || node.type === 'Line')) {
- handleComment(comment);
- }
- },
- };
- };
- export default {
- create,
- schema,
- };
|