Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npm linting #184

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions __tests__/always-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const rule = require('../rules/always-return')
const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6
}
ecmaVersion: 6,
},
})

const message = 'Each then() should return a value or throw'
Expand Down Expand Up @@ -41,58 +41,58 @@ ruleTester.run('always-return', rule, {
two: x === 2 ? 1 : 0
}
})
})`
})`,
],

invalid: [
{
code: 'hey.then(x => {})',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { }).then(x)',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { }).then(function() { })',
errors: [{ message }, { message }]
errors: [{ message }, { message }],
},
{
code: 'hey.then(function() { return; }).then(function() { })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { doSomethingWicked(); })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { if (x) { return x; } })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { if (x) { return x; } else { }})',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function() { if (x) { } else { return x; }})',
errors: [{ message }]
errors: [{ message }],
},
{
code:
'hey.then(function() { if (x) { return you.then(function() { return x; }); } })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then( x => { x ? x.id : null })',
errors: [{ message }]
errors: [{ message }],
},
{
code: 'hey.then(function(x) { x ? x.id : null })',
errors: [{ message }]
errors: [{ message }],
},
{
code: `(function() {
Expand All @@ -105,7 +105,7 @@ ruleTester.run('always-return', rule, {
})
})
})()`,
errors: [{ message }]
}
]
errors: [{ message }],
},
],
})
16 changes: 8 additions & 8 deletions __tests__/avoid-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const rule = require('../rules/avoid-new')
const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6
}
ecmaVersion: 6,
},
})

const errorMessage = 'Avoid creating new promises.'
Expand All @@ -17,21 +17,21 @@ ruleTester.run('avoid-new', rule, {
'Promise.all()',
'new Horse()',
'new PromiseLikeThing()',
'new Promise.resolve()'
'new Promise.resolve()',
],

invalid: [
{
code: 'var x = new Promise(function (x, y) {})',
errors: [{ message: errorMessage }]
errors: [{ message: errorMessage }],
},
{
code: 'new Promise()',
errors: [{ message: errorMessage }]
errors: [{ message: errorMessage }],
},
{
code: 'Thing(new Promise(() => {}))',
errors: [{ message: errorMessage }]
}
]
errors: [{ message: errorMessage }],
},
],
})
84 changes: 42 additions & 42 deletions __tests__/catch-or-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ruleTester.run('catch-or-return', rule, {
{
code:
'postJSON("/smajobber/api/reportJob.json")\n\t.then(()=>this.setState())\n\t.catch(()=>this.setState())',
parserOptions: { ecmaVersion: 6 }
parserOptions: { ecmaVersion: 6 },
},

// return
Expand All @@ -34,187 +34,187 @@ ruleTester.run('catch-or-return', rule, {
// allowThen - .then(null, fn)
{
code: 'frank().then(go).then(null, doIt)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank().then(go).then().then().then().then(null, doIt)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code:
'frank().then(go).then().then(null, function() { /* why bother */ })',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank.then(go).then(to).then(null, jail)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},

// allowThen - .then(null, fn)
{ code: 'frank().then(a, b)', options: [{ allowThen: true }] },
{
code: 'frank().then(a).then(b).then(null, c)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank().then(a).then(b).then(c, d)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank().then(a).then(b).then().then().then(null, doIt)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code:
'frank().then(a).then(b).then(null, function() { /* why bother */ })',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},

// allowThen - .then(fn, fn)
{
code: 'frank().then(go).then(zam, doIt)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank().then(go).then().then().then().then(wham, doIt)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code:
'frank().then(go).then().then(function() {}, function() { /* why bother */ })',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},
{
code: 'frank.then(go).then(to).then(pewPew, jail)',
options: [{ allowThen: true }]
options: [{ allowThen: true }],
},

// allowFinally - .finally(fn)
{
code: 'frank().then(go).catch(doIt).finally(fn)',
options: [{ allowFinally: true }]
options: [{ allowFinally: true }],
},
{
code: 'frank().then(go).then().then().then().catch(doIt).finally(fn)',
options: [{ allowFinally: true }]
options: [{ allowFinally: true }],
},
{
code:
'frank().then(go).then().catch(function() { /* why bother */ }).finally(fn)',
options: [{ allowFinally: true }]
options: [{ allowFinally: true }],
},

// terminationMethod=done - .done(null, fn)
{
code: 'frank().then(go).done()',
options: [{ terminationMethod: 'done' }]
options: [{ terminationMethod: 'done' }],
},

// terminationMethod=[catch, done] - .done(null, fn)
{
code: 'frank().then(go).catch()',
options: [{ terminationMethod: ['catch', 'done'] }]
options: [{ terminationMethod: ['catch', 'done'] }],
},
{
code: 'frank().then(go).done()',
options: [{ terminationMethod: ['catch', 'done'] }]
options: [{ terminationMethod: ['catch', 'done'] }],
},
{
code: 'frank().then(go).finally()',
options: [{ terminationMethod: ['catch', 'finally'] }]
}
options: [{ terminationMethod: ['catch', 'finally'] }],
},
],

invalid: [
// catch failures
{
code: 'function callPromise(promise, cb) { promise.then(cb) }',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'fetch("http://www.yahoo.com").then(console.log.bind(console))',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'a.then(function() { return "x"; }).then(function(y) { throw y; })',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'Promise.resolve(frank)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(to).catch(fn).then(foo)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().finally(fn)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(to).finally(fn)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(go).catch(doIt).finally(fn)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(go).then().then().then().catch(doIt).finally(fn)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code:
'frank().then(go).then().catch(function() { /* why bother */ }).finally(fn)',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},

// return failures
{
code: 'function a() { frank().then(go) }',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'function a() { frank().then(go).then().then().then() }',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'function a() { frank().then(go).then()}',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'function a() { frank.then(go).then(to) }',
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},

// allowFinally=true failures
{
code: 'frank().then(go).catch(doIt).finally(fn).then(foo)',
options: [{ allowFinally: true }],
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},
{
code: 'frank().then(go).catch(doIt).finally(fn).foobar(foo)',
options: [{ allowFinally: true }],
errors: [{ message: catchMessage }]
errors: [{ message: catchMessage }],
},

// terminationMethod=done - .done(null, fn)
{
code: 'frank().then(go)',
options: [{ terminationMethod: 'done' }],
errors: [{ message: doneMessage }]
errors: [{ message: doneMessage }],
},
{
code: 'frank().catch(go)',
options: [{ terminationMethod: 'done' }],
errors: [{ message: doneMessage }]
errors: [{ message: doneMessage }],
},

// assume somePromise.ANYTHING() is a new promise
{
code: 'frank().catch(go).someOtherMethod()',
errors: [{ message: catchMessage }]
}
]
errors: [{ message: catchMessage }],
},
],
})