Skip to content

Commit 90c05bc

Browse files
committed
Update linter
1 parent e45b5b7 commit 90c05bc

File tree

6 files changed

+118
-105
lines changed

6 files changed

+118
-105
lines changed

.github/linters/.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ rules:
4646
'no-console': 'off',
4747
'no-unused-vars': 'off',
4848
'prettier/prettier': 'error',
49-
'semi': 'off'
49+
'semi': 'off',
5050
}

.prettierrc.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
22
"printWidth": 80,
3-
"tabWidth": 4,
3+
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,
66
"singleQuote": true,
77
"quoteProps": "as-needed",
88
"jsxSingleQuote": false,
9-
"trailingComma": "all",
9+
"trailingComma": "es5",
1010
"bracketSpacing": true,
1111
"bracketSameLine": true,
1212
"arrowParens": "avoid",
1313
"proseWrap": "always",
1414
"htmlWhitespaceSensitivity": "css",
15-
"endOfLine": "lf"
15+
"endOfLine": "lf",
16+
"overrides": [
17+
{
18+
"files": "*.js",
19+
"options": {
20+
"tabWidth": 4
21+
}
22+
}
23+
]
1624
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ There are a few things to keep in mind when writing your action code:
8888
In `main.js`, you will see that the action is run in an `async` function.
8989

9090
```javascript
91-
const core = require('@actions/core')
91+
const core = require('@actions/core');
9292
//...
9393

9494
async function run() {
9595
try {
9696
//...
9797
} catch (error) {
98-
core.setFailed(error.message)
98+
core.setFailed(error.message);
9999
}
100100
}
101101
```

__tests__/index.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
* Unit tests for the action's entrypoint, src/index.js
33
*/
44

5-
const { run } = require('../src/main')
5+
const { run } = require('../src/main');
66

77
// Mock the action's entrypoint
88
jest.mock('../src/main', () => ({
9-
run: jest.fn()
10-
}))
9+
run: jest.fn(),
10+
}));
1111

1212
describe('index', () => {
13-
it('calls run when imported', async () => {
14-
require('../src/index')
13+
it('calls run when imported', async () => {
14+
require('../src/index');
1515

16-
expect(run).toHaveBeenCalled()
17-
})
18-
})
16+
expect(run).toHaveBeenCalled();
17+
});
18+
});

__tests__/main.test.js

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,101 @@
11
/**
22
* Unit tests for the action's main functionality, src/main.js
33
*/
4-
const core = require('@actions/core')
5-
const main = require('../src/main')
4+
const core = require('@actions/core');
5+
const main = require('../src/main');
66

77
// Mock the GitHub Actions core library
8-
const debugMock = jest.spyOn(core, 'debug').mockImplementation()
9-
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
10-
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
11-
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
8+
const debugMock = jest.spyOn(core, 'debug').mockImplementation();
9+
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation();
10+
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation();
11+
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation();
1212

1313
// Mock the action's main function
14-
const runMock = jest.spyOn(main, 'run')
14+
const runMock = jest.spyOn(main, 'run');
1515

1616
// Other utilities
17-
const timeRegex = /^\d{2}:\d{2}:\d{2}/
17+
const timeRegex = /^\d{2}:\d{2}:\d{2}/;
1818

1919
describe('action', () => {
20-
beforeEach(() => {
21-
jest.clearAllMocks()
22-
})
20+
beforeEach(() => {
21+
jest.clearAllMocks();
22+
});
2323

24-
it('sets the time output', async () => {
25-
// Set the action's inputs as return values from core.getInput()
26-
getInputMock.mockImplementation(name => {
27-
switch (name) {
28-
case 'milliseconds':
29-
return '500'
30-
default:
31-
return ''
32-
}
33-
})
24+
it('sets the time output', async () => {
25+
// Set the action's inputs as return values from core.getInput()
26+
getInputMock.mockImplementation(name => {
27+
switch (name) {
28+
case 'milliseconds':
29+
return '500';
30+
default:
31+
return '';
32+
}
33+
});
3434

35-
await main.run()
36-
expect(runMock).toHaveReturned()
35+
await main.run();
36+
expect(runMock).toHaveReturned();
3737

38-
// Verify that all of the core library functions were called correctly
39-
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
40-
expect(debugMock).toHaveBeenNthCalledWith(
41-
2,
42-
expect.stringMatching(timeRegex)
43-
)
44-
expect(debugMock).toHaveBeenNthCalledWith(
45-
3,
46-
expect.stringMatching(timeRegex)
47-
)
48-
expect(setOutputMock).toHaveBeenNthCalledWith(
49-
1,
50-
'time',
51-
expect.stringMatching(timeRegex)
52-
)
53-
})
38+
// Verify that all of the core library functions were called correctly
39+
expect(debugMock).toHaveBeenNthCalledWith(
40+
1,
41+
'Waiting 500 milliseconds ...'
42+
);
43+
expect(debugMock).toHaveBeenNthCalledWith(
44+
2,
45+
expect.stringMatching(timeRegex)
46+
);
47+
expect(debugMock).toHaveBeenNthCalledWith(
48+
3,
49+
expect.stringMatching(timeRegex)
50+
);
51+
expect(setOutputMock).toHaveBeenNthCalledWith(
52+
1,
53+
'time',
54+
expect.stringMatching(timeRegex)
55+
);
56+
});
5457

55-
it('sets a failed status', async () => {
56-
// Set the action's inputs as return values from core.getInput()
57-
getInputMock.mockImplementation(name => {
58-
switch (name) {
59-
case 'milliseconds':
60-
return 'this is not a number'
61-
default:
62-
return ''
63-
}
64-
})
58+
it('sets a failed status', async () => {
59+
// Set the action's inputs as return values from core.getInput()
60+
getInputMock.mockImplementation(name => {
61+
switch (name) {
62+
case 'milliseconds':
63+
return 'this is not a number';
64+
default:
65+
return '';
66+
}
67+
});
6568

66-
await main.run()
67-
expect(runMock).toHaveReturned()
69+
await main.run();
70+
expect(runMock).toHaveReturned();
6871

69-
// Verify that all of the core library functions were called correctly
70-
expect(setFailedMock).toHaveBeenNthCalledWith(
71-
1,
72-
'milliseconds not a number'
73-
)
74-
})
72+
// Verify that all of the core library functions were called correctly
73+
expect(setFailedMock).toHaveBeenNthCalledWith(
74+
1,
75+
'milliseconds not a number'
76+
);
77+
});
7578

76-
it('fails if no input is provided', async () => {
77-
// Set the action's inputs as return values from core.getInput()
78-
getInputMock.mockImplementation(name => {
79-
switch (name) {
80-
case 'milliseconds':
81-
throw new Error('Input required and not supplied: milliseconds')
82-
default:
83-
return ''
84-
}
85-
})
79+
it('fails if no input is provided', async () => {
80+
// Set the action's inputs as return values from core.getInput()
81+
getInputMock.mockImplementation(name => {
82+
switch (name) {
83+
case 'milliseconds':
84+
throw new Error(
85+
'Input required and not supplied: milliseconds'
86+
);
87+
default:
88+
return '';
89+
}
90+
});
8691

87-
await main.run()
88-
expect(runMock).toHaveReturned()
92+
await main.run();
93+
expect(runMock).toHaveReturned();
8994

90-
// Verify that all of the core library functions were called correctly
91-
expect(setFailedMock).toHaveBeenNthCalledWith(
92-
1,
93-
'Input required and not supplied: milliseconds'
94-
)
95-
})
96-
})
95+
// Verify that all of the core library functions were called correctly
96+
expect(setFailedMock).toHaveBeenNthCalledWith(
97+
1,
98+
'Input required and not supplied: milliseconds'
99+
);
100+
});
101+
});

__tests__/wait.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
/**
22
* Unit tests for src/wait.js
33
*/
4-
const { wait } = require('../src/wait')
5-
const { expect } = require('@jest/globals')
4+
const { wait } = require('../src/wait');
5+
const { expect } = require('@jest/globals');
66

77
describe('wait.js', () => {
8-
it('throws an invalid number', async () => {
9-
const input = parseInt('foo', 10)
10-
expect(isNaN(input)).toBe(true)
8+
it('throws an invalid number', async () => {
9+
const input = parseInt('foo', 10);
10+
expect(isNaN(input)).toBe(true);
1111

12-
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
13-
})
12+
await expect(wait(input)).rejects.toThrow('milliseconds not a number');
13+
});
1414

15-
it('waits with a valid number', async () => {
16-
const start = new Date()
17-
await wait(500)
18-
const end = new Date()
15+
it('waits with a valid number', async () => {
16+
const start = new Date();
17+
await wait(500);
18+
const end = new Date();
1919

20-
const delta = Math.abs(end.getTime() - start.getTime())
20+
const delta = Math.abs(end.getTime() - start.getTime());
2121

22-
expect(delta).toBeGreaterThan(450)
23-
})
24-
})
22+
expect(delta).toBeGreaterThan(450);
23+
});
24+
});

0 commit comments

Comments
 (0)