diff --git a/src/rules/typeIdMatch.js b/src/rules/typeIdMatch.js index 916860eb..cc9f643f 100644 --- a/src/rules/typeIdMatch.js +++ b/src/rules/typeIdMatch.js @@ -7,17 +7,20 @@ const schema = [ const create = (context) => { const pattern = new RegExp(context.options[0] || '^([A-Z][a-z0-9]*)+Type$'); - return { - TypeAlias (typeAliasNode) { - const typeIdentifierName = typeAliasNode.id.name; + const checkType = (typeAliasNode) => { + const typeIdentifierName = typeAliasNode.id.name; + + if (!pattern.test(typeIdentifierName)) { + context.report(typeAliasNode, 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', { + name: typeIdentifierName, + pattern: pattern.toString(), + }); + } + }; - if (!pattern.test(typeIdentifierName)) { - context.report(typeAliasNode, 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', { - name: typeIdentifierName, - pattern: pattern.toString(), - }); - } - }, + return { + OpaqueType: checkType, + TypeAlias: checkType, }; }; diff --git a/tests/rules/assertions/typeIdMatch.js b/tests/rules/assertions/typeIdMatch.js index c24259df..215728ae 100644 --- a/tests/rules/assertions/typeIdMatch.js +++ b/tests/rules/assertions/typeIdMatch.js @@ -1,5 +1,13 @@ export default { invalid: [ + { + code: 'opaque type foo = {};', + errors: [ + { + message: 'Type identifier \'foo\' does not match pattern \'/^([A-Z][a-z0-9]*)+Type$/\'.', + }, + ], + }, { code: 'type foo = {};', errors: [