Skip to content

Commit

Permalink
Fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 18, 2020
1 parent 5862427 commit 44e2c3b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rules/prefer-spread.js
Expand Up @@ -19,9 +19,7 @@ const tokenTypesCantFollowOpenBracket = new Set([
'Null',
'Boolean',
'Numeric',
'Template',
'RegularExpression',
'Identifier'
'RegularExpression'
]);

const create = context => {
Expand All @@ -47,10 +45,19 @@ const create = context => {
return true;
}

if (type === 'Template') {
return value.endsWith('`');
}

const lastBlockNode = sourceCode.getNodeByRangeIndex(tokenBefore.range[0]);
if (lastBlockNode && lastBlockNode.type === 'ObjectExpression') {
return true;
}

// `for...of`
if (type === 'Identifier') {
return !(value === 'of' && lastBlockNode && lastBlockNode.type === 'ForOfStatement');
}
}

return false;
Expand Down
33 changes: 33 additions & 0 deletions test/prefer-spread.js
Expand Up @@ -265,6 +265,39 @@ ruleTester.run('prefer-spread', rule, {
[...arrayLike].forEach(doSomething)
`
},
// https://github.com/angular/angular/blob/9e70bcb34f91d439f5203dc22a44f323d02c4648/packages/benchpress/src/webdriver/selenium_webdriver_adapter.ts#L37
// TokenType of `of` is `Identifier`
{
code: `
for (const key of Array.from(arrayLike)) {
}
`,
errors: [{}],
output: `
for (const key of [...arrayLike]) {
}
`
},
// TokenType of `in` is `Keyword`
{
code: `
for (const key in Array.from(arrayLike)) {
}
`,
errors: [{}],
output: `
for (const key in [...arrayLike]) {
}
`
},
// https://github.com/facebook/relay/blob/c7dd4cc33eb2dba82629884bff865f0905fc269e/packages/relay-compiler/transforms/ValidateUnusedVariablesTransform.js#L57
{
// eslint-disable-next-line no-template-curly-in-string
code: 'const foo = `${Array.from(arrayLike)}`',
errors: [{}],
// eslint-disable-next-line no-template-curly-in-string
output: 'const foo = `${[...arrayLike]}`'
},

// https://github.com/gatsbyjs/gatsby/blob/e720d8efe58eba0f6fae9f26ec8879128967d0b5/packages/gatsby/src/bootstrap/page-hot-reloader.js#L30
{
Expand Down

0 comments on commit 44e2c3b

Please sign in to comment.