interfaceIdMatch.js.flow 731 B

123456789101112131415161718192021222324252627282930313233
  1. const schema = [
  2. {
  3. type: 'string',
  4. },
  5. ];
  6. const create = (context) => {
  7. const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$', 'u');
  8. const checkInterface = (interfaceDeclarationNode) => {
  9. const interfaceIdentifierName = interfaceDeclarationNode.id.name;
  10. if (!pattern.test(interfaceIdentifierName)) {
  11. context.report({
  12. data: {
  13. name: interfaceIdentifierName,
  14. pattern: pattern.toString(),
  15. },
  16. message: 'Interface identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.',
  17. node: interfaceDeclarationNode,
  18. });
  19. }
  20. };
  21. return {
  22. InterfaceDeclaration: checkInterface,
  23. };
  24. };
  25. export default {
  26. create,
  27. schema,
  28. };