Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f498913

Browse files
authored
Merge pull request actions#48 from actions/code-quality
Code quality improvements
2 parents ca14121 + 58f0ff8 commit f498913

File tree

12 files changed

+1004
-73
lines changed

12 files changed

+1004
-73
lines changed

.eslintrc.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root: true
2+
parser: '@typescript-eslint/parser'
3+
plugins: ['@typescript-eslint']
4+
extends:
5+
- eslint:recommended
6+
- plugin:@typescript-eslint/eslint-recommended
7+
- plugin:@typescript-eslint/recommended
8+
- prettier/@typescript-eslint
9+
rules:
10+
# '@typescript-eslint/explicit-function-return-type': 0
11+
'@typescript-eslint/no-use-before-define':
12+
- 2
13+
- functions: false

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ jobs:
1515
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
1616
restore-keys: ${{runner.os}}-npm-
1717
- run: npm ci
18+
- run: npm run style:check
1819
- run: npm test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
/node_modules/
2+
!/.vscode/

.prettierrc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
arrowParens: avoid
2+
bracketSpacing: false
3+
semi: false
4+
singleQuote: true
5+
trailingComma: none

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.organizeImports": true
5+
},
6+
"files.exclude": {
7+
"**/dist": true,
8+
"**/node_modules": true
9+
}
10+
}

__test__/async-function.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import {callAsyncFunction} from '../src/async-function'
24

35
describe('callAsyncFunction', () => {
46
test('calls the function with its arguments', async () => {
5-
const result = await callAsyncFunction({foo: 'bar'}, 'return foo')
7+
const result = await callAsyncFunction({foo: 'bar'} as any, 'return foo')
68
expect(result).toEqual('bar')
79
})
810

911
test('throws on ReferenceError', async () => {
1012
expect.assertions(1)
1113

1214
try {
13-
await callAsyncFunction({}, 'proces')
15+
await callAsyncFunction({} as any, 'proces')
1416
} catch (err) {
1517
expect(err).toBeInstanceOf(ReferenceError)
1618
}
1719
})
1820

1921
test('can access process', async () => {
20-
await callAsyncFunction({}, 'process')
22+
await callAsyncFunction({} as any, 'process')
2123
})
2224

2325
test('can access console', async () => {
24-
await callAsyncFunction({}, 'console')
26+
await callAsyncFunction({} as any, 'console')
2527
})
2628
})

dist/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9274,7 +9274,7 @@ var core = __webpack_require__(470);
92749274
var lib_github = __webpack_require__(469);
92759275

92769276
// CONCATENATED MODULE: ./src/async-function.ts
9277-
const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
9277+
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
92789278
function callAsyncFunction(args, source) {
92799279
const fn = new AsyncFunction(...Object.keys(args), source);
92809280
return fn(...Object.values(args));
@@ -9300,7 +9300,7 @@ async function main() {
93009300
opts.previews = previews.split(',');
93019301
const github = new lib_github.GitHub(token, opts);
93029302
const script = Object(core.getInput)('script', { required: true });
9303-
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilatin errors.
9303+
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
93049304
const result = await callAsyncFunction({ require: __webpack_require__(875), github, context: lib_github.context, core: core }, script);
93059305
let encoding = Object(core.getInput)('result-encoding');
93069306
encoding = encoding ? encoding : 'json';
@@ -9317,14 +9317,10 @@ async function main() {
93179317
}
93189318
Object(core.setOutput)('result', output);
93199319
}
9320+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
93209321
function handleError(err) {
93219322
console.error(err);
9322-
if (err && err.message) {
9323-
Object(core.setFailed)(err.message);
9324-
}
9325-
else {
9326-
Object(core.setFailed)(`Unhandled error: ${err}`);
9327-
}
9323+
Object(core.setFailed)(`Unhandled error: ${err}`);
93289324
}
93299325

93309326

docs/development.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ bash> npm run build
1515

1616
It also has a pre-commit hook configured via
1717
[husky](https://www.npmjs.com/package/husky) that should run the build script
18-
before each commit.
18+
before each commit. Additionally, this hook formats code and lints it, as
19+
well.
1920

2021
## Releasing
2122

0 commit comments

Comments
 (0)