Skip to content

Commit

Permalink
Add ESLint and Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jclem committed May 18, 2020
1 parent b945d09 commit 3037861
Show file tree
Hide file tree
Showing 8 changed files with 987 additions and 71 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root: true
parser: '@typescript-eslint/parser'
plugins: ['@typescript-eslint']
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- prettier/@typescript-eslint
rules:
# '@typescript-eslint/explicit-function-return-type': 0
'@typescript-eslint/no-use-before-define':
- 2
- functions: false
5 changes: 5 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
arrowParens: avoid
bracketSpacing: false
semi: false
singleQuote: true
trailingComma: none
10 changes: 6 additions & 4 deletions __test__/async-function.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import {callAsyncFunction} from '../src/async-function'

describe('callAsyncFunction', () => {
test('calls the function with its arguments', async () => {
const result = await callAsyncFunction({foo: 'bar'}, 'return foo')
const result = await callAsyncFunction({foo: 'bar'} as any, 'return foo')
expect(result).toEqual('bar')
})

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

try {
await callAsyncFunction({}, 'proces')
await callAsyncFunction({} as any, 'proces')
} catch (err) {
expect(err).toBeInstanceOf(ReferenceError)
}
})

test('can access process', async () => {
await callAsyncFunction({}, 'process')
await callAsyncFunction({} as any, 'process')
})

test('can access console', async () => {
await callAsyncFunction({}, 'console')
await callAsyncFunction({} as any, 'console')
})
})
12 changes: 4 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9274,7 +9274,7 @@ var core = __webpack_require__(470);
var lib_github = __webpack_require__(469);

// CONCATENATED MODULE: ./src/async-function.ts
const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
function callAsyncFunction(args, source) {
const fn = new AsyncFunction(...Object.keys(args), source);
return fn(...Object.values(args));
Expand All @@ -9300,7 +9300,7 @@ async function main() {
opts.previews = previews.split(',');
const github = new lib_github.GitHub(token, opts);
const script = Object(core.getInput)('script', { required: true });
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilatin errors.
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
const result = await callAsyncFunction({ require: __webpack_require__(875), github, context: lib_github.context, core: core }, script);
let encoding = Object(core.getInput)('result-encoding');
encoding = encoding ? encoding : 'json';
Expand All @@ -9317,14 +9317,10 @@ async function main() {
}
Object(core.setOutput)('result', output);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function handleError(err) {
console.error(err);
if (err && err.message) {
Object(core.setFailed)(err.message);
}
else {
Object(core.setFailed)(`Unhandled error: ${err}`);
}
Object(core.setFailed)(`Unhandled error: ${err}`);
}


Expand Down
Loading

0 comments on commit 3037861

Please sign in to comment.