Skip to content

Commit bbd33fd

Browse files
authored
fix(stylistic): apply javascript formatting conventions (#262)
1 parent 2412c29 commit bbd33fd

22 files changed

+513
-335
lines changed

eslint.config.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@ import globals from 'globals'
22
import pluginJs from '@eslint/js'
33
import eslintPlugin from 'eslint-plugin-eslint-plugin'
44
import mochaPlugin from 'eslint-plugin-mocha'
5+
import stylistic from '@stylistic/eslint-plugin'
56

67
export default [
78
pluginJs.configs.recommended,
89
eslintPlugin.configs['flat/recommended'],
910
mochaPlugin.configs.recommended,
10-
{ignores: ['test-project/']},
11+
stylistic.configs.recommended,
12+
{ ignores: ['test-project/'] },
1113
{
1214
languageOptions: {
13-
globals: globals.node
15+
globals: globals.node,
1416
},
1517
rules: {
1618
'no-redeclare': 'off',
19+
'@stylistic/arrow-parens': ['error', 'always'],
20+
'@stylistic/indent': ['error', 2],
21+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
22+
'@stylistic/quotes': ['error', 'single'],
23+
'@stylistic/semi': ['error', 'never'],
1724
'eslint-plugin/require-meta-docs-url':
18-
['error', { 'pattern': 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md' }],
25+
['error', { pattern: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md' }],
1926
'eslint-plugin/require-meta-docs-description': 'error',
2027
'eslint-plugin/meta-property-ordering': 'error',
2128
'eslint-plugin/test-case-property-ordering': 'error',
2229
'mocha/no-mocha-arrows': 'off',
23-
'mocha/no-setup-in-describe': 'off'
24-
}
30+
'mocha/no-setup-in-describe': 'off',
31+
},
2532
},
2633
]

lib/flat.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const plugin = {
2020
},
2121
}
2222

23-
const commonGlobals =
24-
Object.assign({
23+
const commonGlobals
24+
= Object.assign({
2525
cy: false,
2626
Cypress: false,
2727
expect: false,
@@ -33,20 +33,20 @@ Object.assign(plugin.configs, {
3333
globals: {
3434
name: 'cypress/globals',
3535
plugins: {
36-
cypress: plugin
36+
cypress: plugin,
3737
},
3838
languageOptions: {
3939
globals:
4040
commonGlobals,
41-
}
42-
}
41+
},
42+
},
4343
})
4444

4545
Object.assign(plugin.configs, {
4646
recommended: {
4747
name: 'cypress/recommended',
4848
plugins: {
49-
cypress: plugin
49+
cypress: plugin,
5050
},
5151
rules: {
5252
'cypress/no-assigning-return-values': 'error',
@@ -57,8 +57,8 @@ Object.assign(plugin.configs, {
5757
languageOptions: {
5858
globals:
5959
commonGlobals,
60-
}
61-
}
60+
},
61+
},
6262
})
6363

6464
module.exports = plugin

lib/rules/assertion-before-screenshot.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ module.exports = {
2828
unexpected: 'Make an assertion on the page state before taking a screenshot',
2929
},
3030
},
31-
create (context) {
31+
create(context) {
3232
return {
33-
CallExpression (node) {
33+
CallExpression(node) {
3434
if (isCallingCyScreenshot(node) && !isPreviousAnAssertion(node)) {
3535
context.report({ node, messageId: 'unexpected' })
3636
}
@@ -39,12 +39,12 @@ module.exports = {
3939
},
4040
}
4141

42-
function isRootCypress (node) {
42+
function isRootCypress(node) {
4343
while (node.type === 'CallExpression') {
4444
if (node.callee.type !== 'MemberExpression') return false
4545

46-
if (node.callee.object.type === 'Identifier' &&
47-
node.callee.object.name === 'cy') {
46+
if (node.callee.object.type === 'Identifier'
47+
&& node.callee.object.name === 'cy') {
4848
return true
4949
}
5050

@@ -54,26 +54,26 @@ function isRootCypress (node) {
5454
return false
5555
}
5656

57-
function getPreviousInChain (node) {
58-
return node.type === 'CallExpression' &&
59-
node.callee.type === 'MemberExpression' &&
60-
node.callee.object.type === 'CallExpression' &&
61-
node.callee.object.callee.type === 'MemberExpression' &&
62-
node.callee.object.callee.property.type === 'Identifier' &&
63-
node.callee.object.callee.property.name
57+
function getPreviousInChain(node) {
58+
return node.type === 'CallExpression'
59+
&& node.callee.type === 'MemberExpression'
60+
&& node.callee.object.type === 'CallExpression'
61+
&& node.callee.object.callee.type === 'MemberExpression'
62+
&& node.callee.object.callee.property.type === 'Identifier'
63+
&& node.callee.object.callee.property.name
6464
}
6565

66-
function getCallExpressionCypressCommand (node) {
67-
return isRootCypress(node) &&
68-
node.callee.property.type === 'Identifier' &&
69-
node.callee.property.name
66+
function getCallExpressionCypressCommand(node) {
67+
return isRootCypress(node)
68+
&& node.callee.property.type === 'Identifier'
69+
&& node.callee.property.name
7070
}
7171

72-
function isCallingCyScreenshot (node) {
72+
function isCallingCyScreenshot(node) {
7373
return getCallExpressionCypressCommand(node) === 'screenshot'
7474
}
7575

76-
function getPreviousCypressCommand (node) {
76+
function getPreviousCypressCommand(node) {
7777
const previousInChain = getPreviousInChain(node)
7878

7979
if (previousInChain) {
@@ -97,15 +97,15 @@ function getPreviousCypressCommand (node) {
9797

9898
const previousStatement = body[index - 1]
9999

100-
if (previousStatement.type !== 'ExpressionStatement' ||
101-
previousStatement.expression.type !== 'CallExpression') {
100+
if (previousStatement.type !== 'ExpressionStatement'
101+
|| previousStatement.expression.type !== 'CallExpression') {
102102
return null
103103
}
104104

105105
return getCallExpressionCypressCommand(previousStatement.expression)
106106
}
107107

108-
function isPreviousAnAssertion (node) {
108+
function isPreviousAnAssertion(node) {
109109
const previousCypressCommand = getPreviousCypressCommand(node)
110110

111111
return assertionCommands.indexOf(previousCypressCommand) >= 0

lib/rules/no-assigning-return-values.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
// safely get nested object property
4-
function get (obj, propertyString = '') {
4+
function get(obj, propertyString = '') {
55
const properties = propertyString.split('.')
66

77
for (let i = 0; i < properties.length; i++) {
@@ -29,9 +29,9 @@ module.exports = {
2929
unexpected: 'Do not assign the return value of a Cypress command',
3030
},
3131
},
32-
create (context) {
32+
create(context) {
3333
return {
34-
VariableDeclaration (node) {
34+
VariableDeclaration(node) {
3535
if (node.declarations.some(isCypressCommandDeclaration)) {
3636
context.report({ node, messageId: 'unexpected' })
3737
}
@@ -47,7 +47,7 @@ const allowedCommands = {
4747
stub: true,
4848
}
4949

50-
function isCypressCommandDeclaration (declarator) {
50+
function isCypressCommandDeclaration(declarator) {
5151
let object = get(declarator, 'init.callee.object')
5252

5353
if (!object) return

lib/rules/no-async-before.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ module.exports = {
1515
},
1616
},
1717

18-
create (context) {
19-
function isBeforeBlock (callExpressionNode) {
18+
create(context) {
19+
function isBeforeBlock(callExpressionNode) {
2020
const { type, name } = callExpressionNode.callee
2121

2222
return type === 'Identifier'
23-
&& name === 'before' || name === 'beforeEach'
23+
&& (name === 'before' || name === 'beforeEach')
2424
}
2525

26-
function isBeforeAsync (node) {
26+
function isBeforeAsync(node) {
2727
return node.arguments
28-
&& node.arguments.length >= 2
29-
&& node.arguments[1].async === true
28+
&& node.arguments.length >= 2
29+
&& node.arguments[1].async === true
3030
}
3131
const sourceCode = context.sourceCode ?? context.getSourceCode()
3232

3333
return {
34-
Identifier (node) {
34+
Identifier(node) {
3535
if (node.name === 'cy' || node.name === 'Cypress') {
3636
const ancestors = sourceCode.getAncestors
3737
? sourceCode.getAncestors(node)
3838
: context.getAncestors()
3939
const asyncTestBlocks = ancestors
40-
.filter((n) => n.type === 'CallExpression')
41-
.filter(isBeforeBlock)
42-
.filter(isBeforeAsync)
40+
.filter((n) => n.type === 'CallExpression')
41+
.filter(isBeforeBlock)
42+
.filter(isBeforeAsync)
4343

4444
if (asyncTestBlocks.length >= 1) {
4545
asyncTestBlocks.forEach((node) => {

lib/rules/no-async-tests.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ module.exports = {
1515
},
1616
},
1717

18-
create (context) {
19-
function isTestBlock (callExpressionNode) {
18+
create(context) {
19+
function isTestBlock(callExpressionNode) {
2020
const { type, name } = callExpressionNode.callee
2121

2222
return type === 'Identifier'
23-
&& name === 'it' || name === 'test'
23+
&& (name === 'it' || name === 'test')
2424
}
2525

26-
function isTestAsync (node) {
26+
function isTestAsync(node) {
2727
return node.arguments
28-
&& node.arguments.length >= 2
29-
&& node.arguments[1].async === true
28+
&& node.arguments.length >= 2
29+
&& node.arguments[1].async === true
3030
}
3131
const sourceCode = context.sourceCode ?? context.getSourceCode()
3232

3333
return {
34-
Identifier (node) {
34+
Identifier(node) {
3535
if (node.name === 'cy' || node.name === 'Cypress') {
3636
const ancestors = sourceCode.getAncestors
3737
? sourceCode.getAncestors(node)
3838
: context.getAncestors()
3939
const asyncTestBlocks = ancestors
40-
.filter((n) => n.type === 'CallExpression')
41-
.filter(isTestBlock)
42-
.filter(isTestAsync)
40+
.filter((n) => n.type === 'CallExpression')
41+
.filter(isTestBlock)
42+
.filter(isTestAsync)
4343

4444
if (asyncTestBlocks.length >= 1) {
4545
asyncTestBlocks.forEach((node) => {

lib/rules/no-chained-get.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
'use strict';
1+
'use strict'
22

3-
//------------------------------------------------------------------------------
3+
// ------------------------------------------------------------------------------
44
// Rule Definition
5-
//------------------------------------------------------------------------------
5+
// ------------------------------------------------------------------------------
66

77
/** @type {import('eslint').Rule.RuleModule} */
88
module.exports = {
@@ -23,65 +23,65 @@ module.exports = {
2323
create(context) {
2424
const isRootCypress = (node) => {
2525
if (
26-
node.type !== 'CallExpression' ||
27-
node.callee.type !== 'MemberExpression'
26+
node.type !== 'CallExpression'
27+
|| node.callee.type !== 'MemberExpression'
2828
) {
29-
return false;
29+
return false
3030
}
3131

3232
if (
33-
node.callee.object.type === 'Identifier' &&
34-
node.callee.object.name === 'cy'
33+
node.callee.object.type === 'Identifier'
34+
&& node.callee.object.name === 'cy'
3535
) {
36-
return true;
36+
return true
3737
}
3838

39-
return isRootCypress(node.callee.object);
40-
};
39+
return isRootCypress(node.callee.object)
40+
}
4141

4242
const hasChainedGet = (node) => {
4343
// Check if this node is a get() call
44-
const isGetCall =
45-
node.callee &&
46-
node.callee.type === 'MemberExpression' &&
47-
node.callee.property &&
48-
node.callee.property.type === 'Identifier' &&
49-
node.callee.property.name === 'get';
44+
const isGetCall
45+
= node.callee
46+
&& node.callee.type === 'MemberExpression'
47+
&& node.callee.property
48+
&& node.callee.property.type === 'Identifier'
49+
&& node.callee.property.name === 'get'
5050

5151
if (!isGetCall) {
52-
return false;
52+
return false
5353
}
5454

55-
const obj = node.callee.object;
55+
const obj = node.callee.object
5656

5757
if (obj.type === 'CallExpression') {
58-
const objCallee = obj.callee;
58+
const objCallee = obj.callee
5959

6060
if (
61-
objCallee &&
62-
objCallee.type === 'MemberExpression' &&
63-
objCallee.property &&
64-
objCallee.property.type === 'Identifier' &&
65-
objCallee.property.name === 'get'
61+
objCallee
62+
&& objCallee.type === 'MemberExpression'
63+
&& objCallee.property
64+
&& objCallee.property.type === 'Identifier'
65+
&& objCallee.property.name === 'get'
6666
) {
67-
return true;
67+
return true
6868
}
6969

70-
return hasChainedGet(obj);
70+
return hasChainedGet(obj)
7171
}
7272

73-
return false;
74-
};
73+
return false
74+
}
7575

7676
return {
7777
CallExpression(node) {
7878
if (isRootCypress(node) && hasChainedGet(node)) {
7979
context.report({
8080
node,
8181
messageId: 'unexpected',
82-
});
82+
})
8383
}
8484
},
85-
};
85+
}
8686
},
87-
};
87+
}

0 commit comments

Comments
 (0)