Skip to content

Commit

Permalink
fix: object-type-delimeter with new babel-eslint (#317)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mwiencek authored and gajus committed Jun 1, 2018
1 parent 3cd70b8 commit e0c328d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/rules/objectTypeDelimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e0c328d

Please sign in to comment.