Skip to content

Commit

Permalink
Fix the remaining linting errors
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
thgreasi committed Nov 8, 2023
1 parent a90119c commit 2ef89b2
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 68 deletions.
1 change: 1 addition & 0 deletions lib/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default class Builder {
const fn = hooks[hook];
if (typeof fn === 'function') {
// Spread the arguments onto the callback function
// eslint-disable-next-line prefer-spread -- TS complains fn's signature not supporting rest params
return await fn.apply(null, args);
}
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions lib/emulate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const getTarEntryHandler = (
dockerfileName: string,
opts: TransposeOptions,
) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const streamToPromise = require('stream-to-promise');
return (
header: tar.Headers,
Expand Down Expand Up @@ -239,6 +240,7 @@ export function transposeTarStream(
export function getBuildThroughStream(
opts: TransposeOptions,
): NodeJS.ReadWriteStream {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const es = require('event-stream');
// Regex to match against 'Step 1/5:', 'Step 1/5 :' 'Step 1:' 'Step 1 :'
// and all lower case versions.
Expand Down
2 changes: 2 additions & 0 deletions lib/multibuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export async function runBuildTask(
const taskResolved = task.resolvedPromise || Promise.resolve();

return new Promise((resolve, reject) => {
// TODO: narrow the new Promise and properly await this.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
taskResolved.then(() => {
if (task.buildStream == null) {
reject(
Expand Down
6 changes: 5 additions & 1 deletion lib/parse/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function normalizeObjectToComposition(
case SchemaVersion.v1:
// FIXME: perform attribute migration
c = { version: DEFAULT_SCHEMA_VERSION, services: c };
case DEFAULT_SCHEMA_VERSION:
// eslint-disable-next-line no-fallthrough
case DEFAULT_SCHEMA_VERSION: {
// Normalise volumes
if (c.volumes) {
c.volumes = _.mapValues(c.volumes, normalizeVolume);
Expand Down Expand Up @@ -199,6 +200,7 @@ function normalizeObjectToComposition(
})
.fromPairs()
.value();
}
}

c.version = DEFAULT_SCHEMA_VERSION;
Expand Down Expand Up @@ -680,7 +682,9 @@ async function readAndNormalizeExpandEnvFile(
envFile: string,
fileResolverCb: (path: string) => Promise<Readable>,
): Promise<Dict<string>> {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const readline = require('readline');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { once } = require('events');
const intermediateEnv: Dict<string> = {};
let readableError;
Expand Down
2 changes: 1 addition & 1 deletion lib/release/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ReleaseAttributesBase {
contract?: string;
}

// tslint:disable-next-line no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ReleaseImageAttributesBase {
// empty
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resolve/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const emptyHook = (_contents: string): Promise<void> => {
const emptyHook = (): Promise<void> => {
return Promise.resolve();
};

Expand Down
2 changes: 1 addition & 1 deletion lib/resolve/resolvers/dockerfileTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class DockerfileTemplateResolver implements Resolver {
);
}

public isSatisfied(_bundle: Bundle): boolean {
public isSatisfied(): boolean {
return this.hasDockerfileTemplate;
}

Expand Down
9 changes: 3 additions & 6 deletions lib/resolve/resolvers/nodeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,11 @@ export class NodeResolver implements Resolver {
);
}

public isSatisfied(_bundle: Bundle): boolean {
public isSatisfied(): boolean {
return this.packageJsonContent != null;
}

public async resolve(
bundle: Bundle,
_specifiedDockerfilePath?: string,
): Promise<FileInfo> {
public async resolve(bundle: Bundle): Promise<FileInfo> {
// Generate a dockerfile which will run the file
// Use latest node base image. Don't use the slim image just in case
// TODO: Find out which apt-get packages are installed mostly with node
Expand Down Expand Up @@ -172,7 +169,7 @@ export class NodeResolver implements Resolver {
};
}

public getCanonicalName(_specifiedPath: string): string {
public getCanonicalName(): string {
throw new Error('getCanonicalName called on unsupported resolver NodeJS');
}
}
Expand Down
33 changes: 22 additions & 11 deletions test/build/all.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'mocha';

import * as Dockerode from 'dockerode';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import * as url from 'url';

Expand Down Expand Up @@ -61,7 +60,7 @@ const docker = new Dockerode(dockerOpts);
// sucessHooks: for when we want the buildSuccess hook to be called
const getSuccessHooks = (done: (error?: Error) => void): BuildHooks => {
const hooks: BuildHooks = {
buildSuccess: (id, layers) => {
buildSuccess: () => {
done();
},
buildFailure: (err) => {
Expand All @@ -76,7 +75,7 @@ const getSuccessHooks = (done: (error?: Error) => void): BuildHooks => {
// failureHooks: for when we want the failure hook to be called
const getFailureHooks = (done: (error?: Error) => void): BuildHooks => {
const hooks: BuildHooks = {
buildSuccess: (id, layers) => {
buildSuccess: () => {
done(new Error('Expected error, got success'));
},
buildFailure: (err) => {
Expand All @@ -97,6 +96,7 @@ describe('Directory build', () => {
const builder = Builder.fromDockerode(docker);
const hooks = getSuccessHooks(done);

// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder
.buildDir(`${TEST_FILE_PATH}/directory-successful-build`, {}, hooks)
.then((stream) => {
Expand Down Expand Up @@ -139,6 +139,7 @@ describe('Directory build', () => {
};

const builder = Builder.fromDockerode(docker);
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder
.buildDir(`${TEST_FILE_PATH}/directory-successful-build`, {}, hooks)
.then((stream) => {
Expand All @@ -154,6 +155,7 @@ describe('Directory build', () => {
const builder = Builder.fromDockerode(docker);
const hooks = getFailureHooks(done);

// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder
.buildDir(`${TEST_FILE_PATH}/directory-no-dockerfile`, {}, hooks)
.then((stream) => {
Expand All @@ -169,6 +171,7 @@ describe('Directory build', () => {
const builder = Builder.fromDockerode(docker);
const hooks = getFailureHooks(done);

// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder
.buildDir(`${TEST_FILE_PATH}/directory-invalid-dockerfile`, {}, hooks)
.then((stream) => {
Expand All @@ -191,6 +194,7 @@ describe('Directory build', () => {
};

const builder = Builder.fromDockerode(docker);
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder.buildDir(`${TEST_FILE_PATH}/directory-successful-build`, {}, hooks);
});

Expand All @@ -206,6 +210,7 @@ describe('Directory build', () => {
};

const builder = Builder.fromDockerode(docker);
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- we are using the done callback
builder.buildDir(
`${TEST_FILE_PATH}/directory-invalid-dockerfile`,
{},
Expand All @@ -229,7 +234,7 @@ describe('Tar stream build', () => {
stream.pipe(process.stdout);
}
},
buildSuccess: (id, layers) => {
buildSuccess: () => {
done();
},
buildFailure: (err) => {
Expand All @@ -241,6 +246,7 @@ describe('Tar stream build', () => {
};

const builder = Builder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});

Expand All @@ -258,7 +264,7 @@ describe('Tar stream build', () => {
stream.pipe(process.stdout);
}
},
buildSuccess: (id, layers) => {
buildSuccess: () => {
done(new Error('Expected build failure, got success hook'));
},
buildFailure: (err) => {
Expand All @@ -270,6 +276,7 @@ describe('Tar stream build', () => {
};

const builder = Builder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});

Expand All @@ -284,7 +291,7 @@ describe('Tar stream build', () => {
buildSuccess: () => {
reject(new Error('Success failed on failing build'));
},
buildFailure: (error, layers) => {
buildFailure: (_error, layers) => {
const expected = 2;
if (layers.length !== expected) {
reject(
Expand All @@ -304,6 +311,7 @@ describe('Tar stream build', () => {
},
};
const builder = Builder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});
});
Expand All @@ -328,7 +336,7 @@ describe('Tar stream build', () => {
buildSuccess: () => {
reject(new Error('Incorrect success report on failing build'));
},
buildFailure: (error, layers) => {
buildFailure: (_error, layers) => {
const expected = 0;
if (layers.length !== expected) {
reject(
Expand All @@ -350,6 +358,7 @@ describe('Tar stream build', () => {

const RewiredBuilder = builderMod.default;
const builder = RewiredBuilder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});
});
Expand All @@ -364,7 +373,7 @@ describe('Error handler', () => {
buildSuccess: () => {
reject(new Error('Incorrect success report on handler error'));
},
buildFailure: (error, layers) => {
buildFailure: (_error, layers) => {
const expected = 0;
if (layers.length !== expected) {
reject(
Expand All @@ -376,13 +385,14 @@ describe('Error handler', () => {
resolve();
}
},
buildStream: (stream) => {
buildStream: () => {
throw new Error(
'Synchronous buildStream error should have been caught',
);
},
};
const builder = Builder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});
});
Expand All @@ -395,7 +405,7 @@ describe('Error handler', () => {
buildSuccess: () => {
reject(new Error('Incorrect success report on handler error'));
},
buildFailure: (error, layers) => {
buildFailure: (_error, layers) => {
const expected = 0;
if (layers.length !== expected) {
reject(
Expand All @@ -407,13 +417,14 @@ describe('Error handler', () => {
resolve();
}
},
buildStream: (stream) => {
buildStream: () => {
return Promise.reject(
new Error('Asynchronous buildStream error should have been caught'),
);
},
};
const builder = Builder.fromDockerode(docker);

builder.createBuildStream({}, hooks);
});
});
Expand Down
1 change: 0 additions & 1 deletion test/build/build_stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/
import { assert } from 'chai';
import * as _ from 'lodash';
import { Readable, Stream, Writable } from 'stream';

import * as proxyquire from 'proxyquire';
Expand Down
7 changes: 1 addition & 6 deletions test/multibuild/build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import * as Dockerode from 'dockerode';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as Path from 'path';
import * as Stream from 'stream';
import * as tar from 'tar-stream';
Expand All @@ -41,14 +40,10 @@ export function getDocker(extraOpts?: any): Dockerode {
function getDockerOpts(extraOpts?: any): Dockerode.DockerOptions {
let dockerOpts: Dockerode.DockerOptions = {};
if (process.env.CIRCLECI != null) {
let ca: string;
let cert: string;
let key: string;

const certs = ['ca.pem', 'cert.pem', 'key.pem'].map((f) =>
Path.join(process.env.DOCKER_CERT_PATH!, f),
);
[ca, cert, key] = certs.map((c) => fs.readFileSync(c, 'utf-8'));
const [ca, cert, key] = certs.map((c) => fs.readFileSync(c, 'utf-8'));
const parsed = Url.parse(process.env.DOCKER_HOST!);

dockerOpts = {
Expand Down
23 changes: 17 additions & 6 deletions test/multibuild/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ describe('External images', () => {

describe('Specifying a dockerfile', () => {
it('should allow specifying a dockerfile', async () => {
const composeObj = require('./test-files/stream/docker-compose-specified-dockerfile.json');
const composeObj = await import(
'./test-files/stream/docker-compose-specified-dockerfile.json'
);
const comp = Compose.normalize(composeObj);

const stream = fs.createReadStream(
Expand Down Expand Up @@ -527,7 +529,9 @@ describe('Specifying a dockerfile', () => {
});

it('should allow specifying a dockerfile.template', async () => {
const composeObj = require('./test-files/stream/docker-compose-specified-dockerfile-template.json');
const composeObj = await import(
'./test-files/stream/docker-compose-specified-dockerfile-template.json'
);
const comp = Compose.normalize(composeObj);

const stream = fs.createReadStream(
Expand Down Expand Up @@ -562,7 +566,9 @@ describe('Specifying a dockerfile', () => {

describe('Specifying a dockerfile hook', () => {
it('should allow preprocessing of dockerfile', async () => {
const composeObj = require('./test-files/stream/docker-compose-specified-dockerfile.json');
const composeObj = await import(
'./test-files/stream/docker-compose-specified-dockerfile.json'
);
const comp = Compose.normalize(composeObj);

const stream = fs.createReadStream(
Expand Down Expand Up @@ -607,9 +613,14 @@ describe('Specifying a dockerfile hook', () => {
});
});

describe('Specifying build options', () => {
const composeObj = require('./test-files/stream/docker-compose-build-options.json');
const comp = Compose.normalize(composeObj);
describe('Specifying build options', async () => {
let comp: Compose.Composition;
before(async function () {
const composeObj = await import(
'./test-files/stream/docker-compose-build-options.json'
);
comp = Compose.normalize(composeObj);
});

it('should correctly apply "extra_hosts" configuration', async () => {
const stream = fs.createReadStream(
Expand Down
1 change: 0 additions & 1 deletion test/multibuild/registry-secrets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
import { expect } from 'chai';
import * as fs from 'fs';
import * as _ from 'lodash';

import { normalize } from '../../lib/parse';

Expand Down
Loading

0 comments on commit 2ef89b2

Please sign in to comment.