From d5462049a6bda1b1beb372b82fffb7291b0ef23c Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Fri, 3 Nov 2017 11:56:25 +0100 Subject: [PATCH] chore: implement require-await eslint rule (#1095) --- .eslintrc.js | 1 + lib/manager/index.js | 2 +- lib/manager/npm/detect.js | 2 +- lib/manager/npm/registry.js | 2 +- lib/platform/gitlab.js | 4 +-- lib/workers/pr/index.js | 2 +- lib/workers/repository/upgrades.js | 2 +- test/config/presets.spec.js | 36 +++++++++---------- test/platform/github.spec.js | 22 ++++++------ test/platform/gitlab.spec.js | 4 +-- test/workers/branch/lock-files.spec.js | 12 +++---- .../onboarding/pr/config-description.spec.js | 2 +- .../onboarding/pr/errors-warnings.spec.js | 4 +-- .../repository/onboarding/pr/pr-list.spec.js | 4 +-- 14 files changed, 50 insertions(+), 49 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0c6028b168..80b5d1fad5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,6 +5,7 @@ module.exports = { extends: ['airbnb-base', 'prettier'], plugins: ['import', 'promise'], rules: { + 'require-await': 'error', 'no-use-before-define': 0, 'no-restricted-syntax': 0, 'no-await-in-loop': 0, diff --git a/lib/manager/index.js b/lib/manager/index.js index b087bb873e..5a9bdf8b36 100644 --- a/lib/manager/index.js +++ b/lib/manager/index.js @@ -45,7 +45,7 @@ async function detectPackageFiles(config) { return packageFiles; } -async function getPackageUpdates(config) { +function getPackageUpdates(config) { if (config.packageFile.endsWith('Dockerfile')) { return docker.getPackageUpdates(config); } else if (config.packageFile.endsWith('package.json')) { diff --git a/lib/manager/npm/detect.js b/lib/manager/npm/detect.js index 8ee0934324..2fad1c270f 100644 --- a/lib/manager/npm/detect.js +++ b/lib/manager/npm/detect.js @@ -2,7 +2,7 @@ module.exports = { detectPackageFiles, }; -async function detectPackageFiles(config, fileList) { +function detectPackageFiles(config, fileList) { const packageFiles = []; if (config.npm.enabled) { for (const file of fileList) { diff --git a/lib/manager/npm/registry.js b/lib/manager/npm/registry.js index 5e1b4e3677..879cac2c7c 100644 --- a/lib/manager/npm/registry.js +++ b/lib/manager/npm/registry.js @@ -22,7 +22,7 @@ function resetCache() { cache.clear(); } -async function setNpmrc(input) { +function setNpmrc(input) { npmrc = ini.parse(input); } diff --git a/lib/platform/gitlab.js b/lib/platform/gitlab.js index 7107c31019..55b0293cf9 100644 --- a/lib/platform/gitlab.js +++ b/lib/platform/gitlab.js @@ -98,7 +98,7 @@ async function initRepo(repoName, token, endpoint, repoLogger) { return {}; } -async function setBaseBranch(branchName) { +function setBaseBranch(branchName) { if (branchName) { config.baseBranch = branchName; } @@ -311,7 +311,7 @@ async function addAssignees(iid, assignees) { await get.put(url); } -async function addReviewers(prNo, reviewers) { +function addReviewers(prNo, reviewers) { logger.debug(`addReviewers('${prNo}, '${reviewers})`); logger.error('No reviewer functionality in GitLab'); } diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js index 39760681bd..33431be418 100644 --- a/lib/workers/pr/index.js +++ b/lib/workers/pr/index.js @@ -127,7 +127,7 @@ async function ensurePr(prConfig) { const prTitle = handlebars.compile(config.prTitle)(config); let prBody; - async function trimPrBody() { + function trimPrBody() { let prBodyMarkdown = handlebars.compile(config.prBody)(config); prBodyMarkdown = prBodyMarkdown.replace('@', '@​'); prBody = converter.makeHtml(prBodyMarkdown); diff --git a/lib/workers/repository/upgrades.js b/lib/workers/repository/upgrades.js index 973e408bc9..b7280de06d 100644 --- a/lib/workers/repository/upgrades.js +++ b/lib/workers/repository/upgrades.js @@ -159,7 +159,7 @@ function groupByBranch(upgrades) { return result; } -async function branchifyUpgrades(upgrades, parentLogger) { +function branchifyUpgrades(upgrades, parentLogger) { logger = parentLogger || logger; logger.debug('branchifyUpgrades'); logger.trace({ config: upgrades }, 'branchifyUpgrades'); diff --git a/test/config/presets.spec.js b/test/config/presets.spec.js index fe1db18088..c91d4360ed 100644 --- a/test/config/presets.spec.js +++ b/test/config/presets.spec.js @@ -158,17 +158,17 @@ describe('config/presets', () => { arg1: 'b', arg2: 'c', }; - it('replaces args in strings', async () => { + it('replaces args in strings', () => { const str = '{{arg2}} foo {{arg0}}{{arg1}}'; const res = presets.replaceArgs(str, argMappings); expect(res).toMatchSnapshot(); }); - it('replaces args twice in same string', async () => { + it('replaces args twice in same string', () => { const str = '{{arg2}}{{arg0}} foo {{arg0}}{{arg1}}'; const res = presets.replaceArgs(str, argMappings); expect(res).toEqual('ca foo ab'); }); - it('replaces objects', async () => { + it('replaces objects', () => { const obj = { foo: 'ha {{arg0}}', bar: { @@ -181,7 +181,7 @@ describe('config/presets', () => { const res = presets.replaceArgs(obj, argMappings); expect(res).toMatchSnapshot(); }); - it('replaces arrays', async () => { + it('replaces arrays', () => { const obj = { foo: [ '{{arg0}}', @@ -197,49 +197,49 @@ describe('config/presets', () => { }); describe('parsePreset', () => { // default namespace - it('returns default package name', async () => { + it('returns default package name', () => { expect(presets.parsePreset(':base')).toMatchSnapshot(); }); - it('returns default package name with params', async () => { + it('returns default package name with params', () => { expect( presets.parsePreset(':group(packages/eslint, eslint)') ).toMatchSnapshot(); }); // scoped namespace - it('returns simple scope', async () => { + it('returns simple scope', () => { expect(presets.parsePreset('@somescope')).toMatchSnapshot(); }); - it('returns simple scope and params', async () => { + it('returns simple scope and params', () => { expect(presets.parsePreset('@somescope(param1)')).toMatchSnapshot(); }); - it('returns scope with packageName and default', async () => { + it('returns scope with packageName and default', () => { expect( presets.parsePreset('@somescope/somepackagename') ).toMatchSnapshot(); }); - it('returns scope with packageName and params and default', async () => { + it('returns scope with packageName and params and default', () => { expect( presets.parsePreset( '@somescope/somepackagename(param1, param2, param3)' ) ).toMatchSnapshot(); }); - it('returns scope with presetName', async () => { + it('returns scope with presetName', () => { expect( presets.parsePreset('@somescope:somePresetName') ).toMatchSnapshot(); }); - it('returns scope with presetName and params', async () => { + it('returns scope with presetName and params', () => { expect( presets.parsePreset('@somescope:somePresetName(param1)') ).toMatchSnapshot(); }); - it('returns scope with packageName and presetName', async () => { + it('returns scope with packageName and presetName', () => { expect( presets.parsePreset('@somescope/somepackagename:somePresetName') ).toMatchSnapshot(); }); - it('returns scope with packageName and presetName and params', async () => { + it('returns scope with packageName and presetName and params', () => { expect( presets.parsePreset( '@somescope/somepackagename:somePresetName(param1, param2)' @@ -247,18 +247,18 @@ describe('config/presets', () => { ).toMatchSnapshot(); }); // non-scoped namespace - it('returns non-scoped default', async () => { + it('returns non-scoped default', () => { expect(presets.parsePreset('somepackage')).toMatchSnapshot(); }); - it('returns non-scoped package name', async () => { + it('returns non-scoped package name', () => { expect(presets.parsePreset('somepackage:webapp')).toMatchSnapshot(); }); - it('returns non-scoped package name full', async () => { + it('returns non-scoped package name full', () => { expect( presets.parsePreset('renovate-config-somepackage:webapp') ).toMatchSnapshot(); }); - it('returns non-scoped package name with params', async () => { + it('returns non-scoped package name with params', () => { expect( presets.parsePreset('somepackage:webapp(param1)') ).toMatchSnapshot(); diff --git a/test/platform/github.spec.js b/test/platform/github.spec.js index 5b32618cff..b6b3a2ed11 100644 --- a/test/platform/github.spec.js +++ b/test/platform/github.spec.js @@ -15,7 +15,7 @@ describe('platform/github', () => { github = require('../../lib/platform/github'); }); - async function getRepos(...args) { + function getRepos(...args) { // repo info get.mockImplementationOnce(() => ({ body: [ @@ -52,7 +52,7 @@ describe('platform/github', () => { }); }); - async function initRepo(...args) { + function initRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -119,7 +119,7 @@ describe('platform/github', () => { ); }); it('should rebase', async () => { - async function squashInitRepo(...args) { + function squashInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -152,7 +152,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should squash', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -185,7 +185,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should merge', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -218,7 +218,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should not guess at merge', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -248,7 +248,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should detect repoForceRebase', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -278,7 +278,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should ignore repoForceRebase 404', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -308,7 +308,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should ignore repoForceRebase 403', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -338,7 +338,7 @@ describe('platform/github', () => { expect(config).toMatchSnapshot(); }); it('should throw repoForceRebase non-404', async () => { - async function mergeInitRepo(...args) { + function mergeInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { @@ -1168,7 +1168,7 @@ describe('platform/github', () => { }); describe('mergePr(prNo) - autodetection', () => { beforeEach(async () => { - async function guessInitRepo(...args) { + function guessInitRepo(...args) { // repo info get.mockImplementationOnce(() => ({ body: { diff --git a/test/platform/gitlab.spec.js b/test/platform/gitlab.spec.js index 91acfedb84..efbf3f9279 100644 --- a/test/platform/gitlab.spec.js +++ b/test/platform/gitlab.spec.js @@ -16,7 +16,7 @@ describe('platform/gitlab', () => { }); describe('getRepos', () => { - async function getRepos(...args) { + function getRepos(...args) { // repo info get.mockImplementationOnce(() => ({ body: [ @@ -63,7 +63,7 @@ describe('platform/gitlab', () => { }); }); - async function initRepo(...args) { + function initRepo(...args) { // projects/${config.repoName get.mockImplementationOnce(() => ({ body: { diff --git a/test/workers/branch/lock-files.spec.js b/test/workers/branch/lock-files.spec.js index 7bbcdabe93..9f3cd7582f 100644 --- a/test/workers/branch/lock-files.spec.js +++ b/test/workers/branch/lock-files.spec.js @@ -23,7 +23,7 @@ describe('workers/branch/lock-files', () => { logger, }; }); - it('returns true if found and true', async () => { + it('returns true if found and true', () => { config.packageFiles = [ { packageFile: 'package.json', @@ -32,7 +32,7 @@ describe('workers/branch/lock-files', () => { ]; expect(hasPackageLock(config, 'package.json')).toBe(true); }); - it('returns false if found and false', async () => { + it('returns false if found and false', () => { config.packageFiles = [ { packageFile: 'package.json', @@ -44,7 +44,7 @@ describe('workers/branch/lock-files', () => { ]; expect(hasPackageLock(config, 'backend/package.json')).toBe(false); }); - it('throws error if not found', async () => { + it('throws error if not found', () => { config.packageFiles = [ { packageFile: 'package.json', @@ -71,7 +71,7 @@ describe('workers/branch/lock-files', () => { logger, }; }); - it('returns true if found and true', async () => { + it('returns true if found and true', () => { config.packageFiles = [ { packageFile: 'package.json', @@ -80,7 +80,7 @@ describe('workers/branch/lock-files', () => { ]; expect(hasYarnLock(config, 'package.json')).toBe(true); }); - it('returns false if found and false', async () => { + it('returns false if found and false', () => { config.packageFiles = [ { packageFile: 'package.json', @@ -92,7 +92,7 @@ describe('workers/branch/lock-files', () => { ]; expect(hasYarnLock(config, 'backend/package.json')).toBe(false); }); - it('throws error if not found', async () => { + it('throws error if not found', () => { config.packageFiles = [ { packageFile: 'package.json', diff --git a/test/workers/repository/onboarding/pr/config-description.spec.js b/test/workers/repository/onboarding/pr/config-description.spec.js index 074a9f8e89..fe5597bc0f 100644 --- a/test/workers/repository/onboarding/pr/config-description.spec.js +++ b/test/workers/repository/onboarding/pr/config-description.spec.js @@ -15,7 +15,7 @@ describe('workers/repository/onboarding/pr/config-description', () => { logger, }; }); - it('returns empty', async () => { + it('returns empty', () => { delete config.description; const res = getConfigDesc(config); expect(res).toMatchSnapshot(); diff --git a/test/workers/repository/onboarding/pr/errors-warnings.spec.js b/test/workers/repository/onboarding/pr/errors-warnings.spec.js index 2c29778268..7148af490a 100644 --- a/test/workers/repository/onboarding/pr/errors-warnings.spec.js +++ b/test/workers/repository/onboarding/pr/errors-warnings.spec.js @@ -16,7 +16,7 @@ describe('workers/repository/onboarding/pr/errors-warnings', () => { logger, }; }); - it('returns warning text', async () => { + it('returns warning text', () => { config.warnings = [ { depName: 'foo', @@ -36,7 +36,7 @@ describe('workers/repository/onboarding/pr/errors-warnings', () => { logger, }; }); - it('returns error text', async () => { + it('returns error text', () => { config.errors = [ { depName: 'renovate.json', diff --git a/test/workers/repository/onboarding/pr/pr-list.spec.js b/test/workers/repository/onboarding/pr/pr-list.spec.js index 369fece57d..136d30c3c5 100644 --- a/test/workers/repository/onboarding/pr/pr-list.spec.js +++ b/test/workers/repository/onboarding/pr/pr-list.spec.js @@ -15,7 +15,7 @@ describe('workers/repository/onboarding/pr/pr-list', () => { logger, }; }); - it('has special lock file maintenance description', async () => { + it('has special lock file maintenance description', () => { config.branches = [ { prTitle: 'Lock file maintenance', @@ -31,7 +31,7 @@ describe('workers/repository/onboarding/pr/pr-list', () => { const res = getPrList(config); expect(res).toMatchSnapshot(); }); - it('handles multiple', async () => { + it('handles multiple', () => { config.branches = [ { prTitle: 'Pin dependencies', -- GitLab