Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: support opaque types (fixes #377)
  • Loading branch information
gajus committed May 16, 2020
1 parent e06f09a commit b1c588f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/rules/typeIdMatch.js
Expand Up @@ -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,
};
};

Expand Down
8 changes: 8 additions & 0 deletions 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: [
Expand Down

0 comments on commit b1c588f

Please sign in to comment.