From e0c328d4848be2b248935f3f49eb119bcd3b320a Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Fri, 1 Jun 2018 13:45:26 -0500 Subject: [PATCH] fix: object-type-delimeter with new babel-eslint (#317) Using babel-eslint 8.2.1, the object-type-delimeter rule does nothing, apparently because the ObjectType{CallProperty,Indexer,Property} nodes no longer contain trailing semicolons/commas, but their parent ObjectTypeAnnotation nodes do. I tried to keep compatibility with both cases, because it's not clear what version this project is targeting. However, I don't know of a good way to test the new behavior given the version of babel-eslint now locked in devDependencies. --- src/rules/objectTypeDelimiter.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rules/objectTypeDelimiter.js b/src/rules/objectTypeDelimiter.js index 7d801063..9ebd430d 100644 --- a/src/rules/objectTypeDelimiter.js +++ b/src/rules/objectTypeDelimiter.js @@ -24,8 +24,18 @@ const create = (context) => { } const requireProperPunctuation = (node) => { - const tokens = context.getSourceCode().getTokens(node); - const lastToken = tokens[tokens.length - 1]; + const sourceCode = context.getSourceCode(); + const tokens = sourceCode.getTokens(node); + let lastToken; + + lastToken = tokens[tokens.length - 1]; + if (lastToken.type !== 'Punctuator' || + !(lastToken.value === SEMICOLON.char || + lastToken.value === COMMA.char)) { + const parentTokens = sourceCode.getTokens(node.parent); + + lastToken = parentTokens[parentTokens.indexOf(lastToken) + 1]; + } if (lastToken.type === 'Punctuator') { if (lastToken.value === BAD.char) {