Skip to content

Commit

Permalink
Use outdent
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 18, 2020
1 parent 6a33884 commit 583622e
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions test/prefer-spread.js
@@ -1,5 +1,6 @@
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import {outdent} from 'outdent';
import rule from '../rules/prefer-spread';

const ruleTester = avaRuleTester(test, {
Expand Down Expand Up @@ -128,7 +129,7 @@ ruleTester.run('prefer-spread', rule, {
// Semicolon
// #254
{
code: `
code: outdent`
const foo = []
Array.from(arrayLike).forEach(doSomething)
`,
Expand All @@ -137,155 +138,155 @@ ruleTester.run('prefer-spread', rule, {
message: 'Prefer the spread operator over `Array.from()`.'
}
],
output: `
output: outdent`
const foo = []
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = "1"
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = "1"
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = null
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = null
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = true
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = true
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = 1
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = 1
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = /./
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = /./
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = /./g
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = /./g
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = bar
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = bar
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = bar.baz
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = bar.baz
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
function* foo() {
yield Array.from(arrayLike).forEach(doSomething)
}
`,
errors: [{}],
output: `
output: outdent`
function* foo() {
yield [...arrayLike].forEach(doSomething)
}
`
},
{
code: `
code: outdent`
const foo = \`bar\`
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = \`bar\`
;[...arrayLike].forEach(doSomething)
`
},
{
code: `
code: outdent`
const foo = [];
Array.from(arrayLike).forEach(doSomething)
`,
errors: [{}],
output: `
output: outdent`
const foo = [];
[...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: `
code: outdent`
for (const key of Array.from(arrayLike)) {
}
`,
errors: [{}],
output: `
output: outdent`
for (const key of [...arrayLike]) {
}
`
},
// TokenType of `in` is `Keyword`
{
code: `
code: outdent`
for (const key in Array.from(arrayLike)) {
}
`,
errors: [{}],
output: `
output: outdent`
for (const key in [...arrayLike]) {
}
`
Expand All @@ -300,13 +301,13 @@ ruleTester.run('prefer-spread', rule, {
},
// https://github.com/angular/angular/blob/9e70bcb34f91d439f5203dc22a44f323d02c4648/packages/service-worker/worker/testing/cache.ts#L48
{
code: `
code: outdent`
async function foo(){
return await Array.from(arrayLike)
}
`,
errors: [{}],
output: `
output: outdent`
async function foo(){
return await [...arrayLike]
}
Expand All @@ -315,7 +316,7 @@ ruleTester.run('prefer-spread', rule, {

// https://github.com/gatsbyjs/gatsby/blob/e720d8efe58eba0f6fae9f26ec8879128967d0b5/packages/gatsby/src/bootstrap/page-hot-reloader.js#L30
{
code: `
code: outdent`
foo()
Array.from(arrayLike).forEach(doSomething)
`,
Expand All @@ -324,14 +325,14 @@ ruleTester.run('prefer-spread', rule, {
message: 'Prefer the spread operator over `Array.from()`.'
}
],
output: `
output: outdent`
foo()
;[...arrayLike].forEach(doSomething)
`
},
// https://github.com/gatsbyjs/gatsby/blob/4ab3f194cf5d6dcafcb2a75d9604aac79d963554/packages/gatsby/src/redux/__tests__/nodes.js#L277
{
code: `
code: outdent`
const foo = {}
Array.from(arrayLike).forEach(doSomething)
`,
Expand All @@ -340,7 +341,7 @@ ruleTester.run('prefer-spread', rule, {
message: 'Prefer the spread operator over `Array.from()`.'
}
],
output: `
output: outdent`
const foo = {}
;[...arrayLike].forEach(doSomething)
`
Expand Down

0 comments on commit 583622e

Please sign in to comment.