Skip to content

Commit 80d1190

Browse files
committed
Use message ids to comply with new eslint rules
1 parent 18a5148 commit 80d1190

File tree

6 files changed

+21
-27
lines changed

6 files changed

+21
-27
lines changed

lib/rules/no-expect-for-stub.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ module.exports = {
2828
},
2929
fixable: 'code',
3030
schema: [],
31+
messages: { 'message': 'Prefer cy.get("@stub").should(…) over expect(stub)…' },
3132
},
3233

3334
create (context) {
34-
const MESSAGE = 'Prefer cy.get("@stub").should(…) over expect(stub)…'
35-
3635
//----------------------------------------------------------------------
3736
// Helpers
3837
//----------------------------------------------------------------------
@@ -62,7 +61,7 @@ module.exports = {
6261

6362
context.report({
6463
node,
65-
message: MESSAGE,
64+
messageId: 'message',
6665
fix: (fixer) => fixCall(fixer, node, expectArgument),
6766
})
6867
},
@@ -79,7 +78,7 @@ module.exports = {
7978

8079
context.report({
8180
node,
82-
message: MESSAGE,
81+
messageId: 'message',
8382
fix: (fixer) => fixCall(fixer, node, expectArgument),
8483
})
8584
},

lib/rules/no-single-expect-in-then-or-should.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ module.exports = {
2323
},
2424
fixable: 'code',
2525
schema: [],
26+
messages: {
27+
'message_then': 'A single expect() in a then() can be rewritten with a should().',
28+
'message_should': 'A single expect() in a should() can be rewritten with just a should().',
29+
},
2630
},
2731

2832
create (context) {
29-
const MESSAGE_THEN = 'A single expect() in a then() can be rewritten with a should().'
30-
const MESSAGE_SHOULD = 'A single expect() in a should() can be rewritten with just a should().'
31-
3233
//----------------------------------------------------------------------
3334
// Helpers
3435
//----------------------------------------------------------------------
@@ -48,15 +49,15 @@ module.exports = {
4849
}
4950

5051
/**
51-
* Report an error with `message` if both conditions are satisfied:
52+
* Report an error with `messageId` if both conditions are satisfied:
5253
*
5354
* - `thenOrShouldCallNode` contains as single argument a function
5455
* with a lonely `expect()` statement, and
5556
*
5657
* - the `expect()` must take as argument the same object as the
5758
* one passed to the function.
5859
*/
59-
function checkThenOrShould (thenOrShouldCallNode, message) {
60+
function checkThenOrShould (thenOrShouldCallNode, messageId) {
6061
if (thenOrShouldCallNode.arguments.length !== 1) return
6162

6263
let argument = thenOrShouldCallNode.arguments[0]
@@ -95,7 +96,7 @@ module.exports = {
9596
if (expectArgument === anonymousFunctionArgumentName) {
9697
context.report({
9798
node: thenOrShouldCallNode,
98-
message,
99+
messageId,
99100
fix: (fixer) => fixCall(fixer, thenOrShouldCallNode, thenArgumentBody.expression),
100101
})
101102
}
@@ -111,10 +112,10 @@ module.exports = {
111112

112113
switch (node.callee.property.name) {
113114
case 'then':
114-
checkThenOrShould(node, MESSAGE_THEN)
115+
checkThenOrShould(node, 'message_then')
115116
break
116117
case 'should':
117-
checkThenOrShould(node, MESSAGE_SHOULD)
118+
checkThenOrShould(node, 'message_should')
118119
break
119120
default:
120121
return

lib/rules/no-useless-then-or-should.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ module.exports = {
2323
},
2424
fixable: 'code', // Or `code` or `whitespace`
2525
schema: [],
26+
messages: { 'message': '`.should()` and `.then()` can be removed when they only wrap commands' },
2627
},
2728

2829
create (context) {
29-
const MESSAGE = '`.should()` and `.then()` can be removed when they only wrap commands'
30-
3130
//----------------------------------------------------------------------
3231
// Helpers
3332
//----------------------------------------------------------------------
@@ -120,7 +119,7 @@ module.exports = {
120119

121120
if (!commandStatementsRange) return
122121

123-
context.report({ node, message: MESSAGE, fix: (fixer) => fixCall(fixer, node, commandStatementsRange) })
122+
context.report({ node, messageId: 'message', fix: (fixer) => fixCall(fixer, node, commandStatementsRange) })
124123
},
125124
}
126125
},

tests/lib/rules/no-expect-for-stub.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const RuleTester = require('eslint').RuleTester
1515
// Tests
1616
//------------------------------------------------------------------------------
1717

18-
const MESSAGE = 'Prefer cy.get("@stub").should(…) over expect(stub)…'
1918
const ruleTester = new RuleTester()
2019

2120
ruleTester.run('no-expect-for-stub', rule, {
@@ -29,22 +28,22 @@ ruleTester.run('no-expect-for-stub', rule, {
2928
invalid: [
3029
{
3130
code: 'expect(stub).to.have.been.calledOnce',
32-
errors: [{ message: MESSAGE, type: 'MemberExpression' }],
31+
errors: [{ messageId: 'message', type: 'MemberExpression' }],
3332
output: 'cy.get("@stub").should("have.been.calledOnce")',
3433
},
3534
{
3635
code: 'expect(getCellContentClickedCallback).to.have.been\n.calledTwice',
37-
errors: [{ message: MESSAGE, type: 'MemberExpression' }],
36+
errors: [{ messageId: 'message', type: 'MemberExpression' }],
3837
output: 'cy.get("@getCellContentClickedCallback").should("have.been.calledTwice")',
3938
},
4039
{
4140
code: 'expect(stub).to.be.calledWith(value)',
42-
errors: [{ message: MESSAGE, type: 'CallExpression' }],
41+
errors: [{ messageId: 'message', type: 'CallExpression' }],
4342
output: 'cy.get("@stub").should("be.calledWith", value)',
4443
},
4544
{
4645
code: 'expect(stub).to.be.calledWith()',
47-
errors: [{ message: MESSAGE, type: 'CallExpression' }],
46+
errors: [{ messageId: 'message', type: 'CallExpression' }],
4847
output: 'cy.get("@stub").should("be.calledWith")',
4948
},
5049
],

tests/lib/rules/no-single-expect-in-then-or-should.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ const RuleTester = require('eslint').RuleTester
1515
// Tests
1616
//------------------------------------------------------------------------------
1717

18-
const MESSAGE_THEN = 'A single expect() in a then() can be rewritten with a should().'
19-
const MESSAGE_SHOULD = 'A single expect() in a should() can be rewritten with just a should().'
20-
21-
const thenError = { message: MESSAGE_THEN, type: 'CallExpression' }
22-
const shouldError = { message: MESSAGE_SHOULD, type: 'CallExpression' }
18+
const thenError = { messageId: 'message_then', type: 'CallExpression' }
19+
const shouldError = { messageId: 'message_should', type: 'CallExpression' }
2320

2421
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } })
2522

tests/lib/rules/no-useless-then-or-should.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const RuleTester = require('eslint').RuleTester
1616
//------------------------------------------------------------------------------
1717

1818
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } })
19-
const MESSAGE = '`.should()` and `.then()` can be removed when they only wrap commands'
20-
const errors = [{ message: MESSAGE, type: 'CallExpression' }]
19+
const errors = [{ messageId: 'message', type: 'CallExpression' }]
2120

2221
ruleTester.run('no-useless-then-or-should', rule, {
2322
valid: [

0 commit comments

Comments
 (0)