Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add code linting and prettify #1350

Merged
merged 25 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
952c1aa
feat: add eslint and prettier config
alexforsyth Jul 8, 2020
860ac2a
fix: auto lint fixes
alexforsyth Jul 8, 2020
716b289
fix: manual configuration and code updates for eslint
alexforsyth Jul 9, 2020
ac0a1e4
fix: automatically fixed by eslint
alexforsyth Jul 9, 2020
3ed0d03
fix: properly build, tighten eslint rules
alexforsyth Jul 9, 2020
df9de13
fix: tslint building properly
alexforsyth Jul 9, 2020
22c318d
fix: manual linter fixes
alexforsyth Jul 9, 2020
c146f6f
fix: merge-commit
alexforsyth Jul 9, 2020
0823304
fix: merge conflict + lint
alexforsyth Jul 9, 2020
69a231b
feat: add prettify command
alexforsyth Jul 9, 2020
a525b24
feat: prettify codebase
alexforsyth Jul 9, 2020
64584cc
fix: clean up tsconfig
alexforsyth Jul 10, 2020
1be752d
fix: remove prettier from scripts
alexforsyth Jul 10, 2020
7963f82
Revert "feat: prettify codebase"
alexforsyth Jul 10, 2020
107863f
chore: merging in files
alexforsyth Jul 10, 2020
3d2b012
fix: automatic linting fixes
alexforsyth Jul 10, 2020
0061a72
fix: manual resolution of linter errors and warnings
alexforsyth Jul 10, 2020
9f14d9c
fix: automatic linter fixes round 2
alexforsyth Jul 10, 2020
1fb7062
feat: manual resolution of eslint errors
alexforsyth Jul 10, 2020
93a2beb
fix: clients update from upstream
alexforsyth Jul 10, 2020
7450229
fix: lint fix protocol_tests
alexforsyth Jul 10, 2020
a71b037
fix: use exact versions package.json
alexforsyth Jul 10, 2020
33eb6a7
fix: unprettify hooks
alexforsyth Jul 10, 2020
bc4ea50
fix: lockfile update
alexforsyth Jul 13, 2020
528597c
Merge branch 'master' into alexforsyth/common-linter
trivikr Jul 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
},
extends: [
// Uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:@typescript-eslint/recommended"
],
plugins: ["@typescript-eslint", "simple-import-sort"],
rules: {
/** Turn off strict enforcement */
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"prefer-rest-params": "off",
"@typescript-eslint/no-non-null-assertion": "off",

/** Warnings */
"@typescript-eslint/no-namespace": "warn",

/** Errors */
"simple-import-sort/sort": "error"
}
};
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"$schema": "http://json.schemastore.org/prettierrc",
"arrowParens": "avoid",
"endOfLine": "auto",
"semi": true,
"printWidth": 120,
alexforsyth marked this conversation as resolved.
Show resolved Hide resolved
"trailingComma": "none"
}
131 changes: 50 additions & 81 deletions features/extra/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ const isType = (obj, type) => {
return Object.prototype.toString.call(obj) === "[object " + type + "]";
alexforsyth marked this conversation as resolved.
Show resolved Hide resolved
};

const {
Before,
Given,
Then,
When,
setDefaultTimeout,
setWorldConstructor
} = require("cucumber");
const { Before, Given, Then, When, setDefaultTimeout, setWorldConstructor } = require("cucumber");

setDefaultTimeout(300 * 1000);
setWorldConstructor(require("./world.js").World);
Expand All @@ -28,12 +21,8 @@ Before(function (scenario, callback) {
Given("I create a shared bucket", function (callback) {
if (this.sharedBucket) return callback();

const bucket = (this.sharedBucket = this.uniqueName(
"aws-sdk-js-shared-integration"
));
this.request("s3", "createBucket", { Bucket: this.sharedBucket }, function (
err
) {
const bucket = (this.sharedBucket = this.uniqueName("aws-sdk-js-shared-integration"));
this.request("s3", "createBucket", { Bucket: this.sharedBucket }, function (err) {
this.cacheBucketName(this.sharedBucket);
if (err) {
callback(err);
Expand All @@ -48,10 +37,7 @@ Given("I create a shared bucket", function (callback) {

Given("I create a bucket", function (callback) {
const bucket = (this.bucket = this.uniqueName("aws-sdk-js-integration"));
this.request("s3", "createBucket", { Bucket: this.bucket }, function (
err,
data
) {
this.request("s3", "createBucket", { Bucket: this.bucket }, function (err, data) {
if (err) {
return callback(err);
}
Expand All @@ -77,11 +63,7 @@ Given("I run the {string} operation", function (operation, callback) {
this.request(null, operation, {}, callback, false);
});

Given("I run the {string} operation with params:", function (
operation,
params,
callback
) {
Given("I run the {string} operation with params:", function (operation, params, callback) {
this.request(null, operation, JSON.parse(params), callback, false);
});

Expand All @@ -92,28 +74,19 @@ Then("the request should be successful", function (callback) {

Then("the value at {string} should be a list", function (path, callback) {
const value = jmespath.search(this.data, path);
this.assert.ok(
Array.isArray(value),
"expected " + util.inspect(value) + " to be a list"
);
this.assert.ok(Array.isArray(value), "expected " + util.inspect(value) + " to be a list");
callback();
});

Then("the value at {string} should be a number", function (path, callback) {
const value = jmespath.search(this.data, path);
this.assert.ok(
typeof value === "number",
"expected " + util.inspect(value) + " to be a number"
);
this.assert.ok(typeof value === "number", "expected " + util.inspect(value) + " to be a number");
callback();
});

Then("the value at {string} should be a string", function (path, callback) {
const value = jmespath.search(this.data, path);
this.assert.ok(
typeof value === "string",
"expected " + util.inspect(value) + " to be a string"
);
this.assert.ok(typeof value === "string", "expected " + util.inspect(value) + " to be a string");
callback();
});

Expand Down Expand Up @@ -148,46 +121,44 @@ Then("I should get the error:", function (table, callback) {
callback();
});

Given("I have a {string} service in the {string} region", function (
svc,
region,
callback
) {
Given("I have a {string} service in the {string} region", function (svc, region, callback) {
this.service = new this.service.constructor({ region: region });
callback();
});

Given(
/^I paginate the "([^"]*)" operation(?: with limit (\d+))?(?: and max pages (\d+))?$/,
function (operation, limit, maxPages, callback) {
limit = parseInt(limit);
if (maxPages) maxPages = parseInt(maxPages);
Given(/^I paginate the "([^"]*)" operation(?: with limit (\d+))?(?: and max pages (\d+))?$/, function (
operation,
limit,
maxPages,
callback
) {
limit = parseInt(limit);
if (maxPages) maxPages = parseInt(maxPages);

const world = this;
this.numPages = 0;
this.numMarkers = 0;
this.operation = operation;
this.paginationConfig = this.service.paginationConfig(operation);
this.params = this.params || {};
const world = this;
this.numPages = 0;
this.numMarkers = 0;
this.operation = operation;
this.paginationConfig = this.service.paginationConfig(operation);
this.params = this.params || {};

const marker = this.paginationConfig.outputToken;
if (this.paginationConfig.limitKey) {
this.params[this.paginationConfig.limitKey] = limit;
}
this.service[operation](this.params).eachPage(function (err, data) {
if (err) callback(err);
else if (data === null) callback();
else if (maxPages && world.numPages === maxPages) {
callback();
return false;
} else {
if (data[marker]) world.numMarkers++;
world.numPages++;
world.data = data;
}
});
const marker = this.paginationConfig.outputToken;
if (this.paginationConfig.limitKey) {
this.params[this.paginationConfig.limitKey] = limit;
}
);
this.service[operation](this.params).eachPage(function (err, data) {
if (err) callback(err);
else if (data === null) callback();
else if (maxPages && world.numPages === maxPages) {
callback();
return false;
} else {
if (data[marker]) world.numMarkers++;
world.numPages++;
world.data = data;
}
});
});

Then("I should get more than one page", function (callback) {
this.assert.compare(this.numPages, ">", 1);
Expand Down Expand Up @@ -215,23 +186,21 @@ Then("the last page should not contain a marker", function (callback) {
callback();
});

Then(
"the result at {word} should contain a property {word} with a(n) {word}",
function (wrapper, property, type, callback) {
if (type === "Array" || type === "Date") {
this.assert.equal(isType(this.data[wrapper][property], type), true);
} else {
this.assert.equal(typeof this.data[wrapper][property], type);
}
callback();
}
);

Then("the result should contain a property {word} with a(n) {word}", function (
Then("the result at {word} should contain a property {word} with a(n) {word}", function (
wrapper,
property,
type,
callback
) {
if (type === "Array" || type === "Date") {
this.assert.equal(isType(this.data[wrapper][property], type), true);
} else {
this.assert.equal(typeof this.data[wrapper][property], type);
}
callback();
});

Then("the result should contain a property {word} with a(n) {word}", function (property, type, callback) {
if (type === "Array" || type === "Date") {
this.assert.equal(isType(this.data[property], type), true);
} else {
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"test:integration-legacy": "cucumber-js --fail-fast",
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",
"test:protocols": "yarn build:protocols && lerna run test --scope '@aws-sdk/aws-*'",
"local-publish": "node ./scripts/verdaccio-publish/index.js"
"local-publish": "node ./scripts/verdaccio-publish/index.js",
"lint": "eslint 'packages/**/src/*.ts' --fix",
"prettify": "prettier --write './packages/**/src/*.ts'"
alexforsyth marked this conversation as resolved.
Show resolved Hide resolved
},
"repository": {
"type": "git",
Expand All @@ -42,10 +44,16 @@
"@types/chai-as-promised": "^7.1.2",
"@types/fs-extra": "^8.0.1",
"@types/jest": "^26.0.4",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"codecov": "^3.4.0",
"cucumber": "^6.0.5",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-simple-import-sort": "^5.0.3",
"fs-extra": "^9.0.0",
"generate-changelog": "^1.7.1",
"husky": "^4.2.3",
Expand All @@ -66,7 +74,7 @@
"lerna": "3.22.1",
"lint-staged": "^10.0.1",
"mocha": "^8.0.1",
"prettier": "2.0.5",
"prettier": "^2.0.5",
alexforsyth marked this conversation as resolved.
Show resolved Hide resolved
"puppeteer": "^4.0.0",
"ts-loader": "^7.0.5",
"typescript": "~3.8.3",
Expand Down Expand Up @@ -97,4 +105,4 @@
"lint-staged": {
"**/*.{ts,js,md,json}": "prettier --write"
}
}
}
1 change: 1 addition & 0 deletions packages/abort-controller/src/AbortController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbortController as IAbortController } from "@aws-sdk/types";

import { AbortSignal } from "./AbortSignal";

export class AbortController implements IAbortController {
Expand Down
1 change: 0 additions & 1 deletion packages/abort-controller/src/AbortSignal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AbortController } from "./AbortController";
import { AbortSignal } from "./AbortSignal";

describe("AbortSignal", () => {
it("should report aborted to be false until the signal is aborted", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/abort-controller/src/AbortSignal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbortSignal as IAbortSignal, AbortHandler } from "@aws-sdk/types";
import { AbortHandler, AbortSignal as IAbortSignal } from "@aws-sdk/types";

export class AbortSignal implements IAbortSignal {
public onabort?: AbortHandler;
Expand Down
35 changes: 10 additions & 25 deletions packages/body-checksum-browser/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { bodyChecksumGenerator } from ".";
import { Sha256 } from "@aws-crypto/sha256-js";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
import { Sha256 } from "@aws-crypto/sha256-js";
import { Readable } from "stream";

import { bodyChecksumGenerator } from ".";

describe("bodyChecksumGenerator for browser", () => {
const sharedRequest = {
method: "POST",
Expand All @@ -26,17 +27,10 @@ describe("bodyChecksumGenerator for browser", () => {
body: blob
});

const [contentHash, treeHash] = await bodyChecksumGenerator(
request,
options
);
const [contentHash, treeHash] = await bodyChecksumGenerator(request, options);

expect(contentHash).toBe(
"733cf513448ce6b20ad1bc5e50eb27c06aefae0c320713a5dd99f4e51bc1ca60"
);
expect(treeHash).toBe(
"a3a82dbe3644dd6046be472f2e3ec1f8ef47f8f3adb86d0de4de7a254f255455"
);
expect(contentHash).toBe("733cf513448ce6b20ad1bc5e50eb27c06aefae0c320713a5dd99f4e51bc1ca60");
expect(treeHash).toBe("a3a82dbe3644dd6046be472f2e3ec1f8ef47f8f3adb86d0de4de7a254f255455");
});

it("will calculate sha256 hashes when request body is a string", async () => {
Expand All @@ -45,17 +39,10 @@ describe("bodyChecksumGenerator for browser", () => {
body: "bar"
});

const [contentHash, treeHash] = await bodyChecksumGenerator(
request,
options
);
const [contentHash, treeHash] = await bodyChecksumGenerator(request, options);

expect(contentHash).toBe(
"fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
);
expect(treeHash).toBe(
"fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
);
expect(contentHash).toBe("fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9");
expect(treeHash).toBe("fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9");
});

it("will reject when request body is a non-blob stream", async () => {
Expand All @@ -67,9 +54,7 @@ describe("bodyChecksumGenerator for browser", () => {
try {
await bodyChecksumGenerator(request, options);
} catch (e) {
expect(e).toEqual(
new Error("Unable to calculate checksums for non-blob streams.")
);
expect(e).toEqual(new Error("Unable to calculate checksums for non-blob streams."));
}
});
});
9 changes: 3 additions & 6 deletions packages/body-checksum-browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { blobReader } from "@aws-sdk/chunked-blob-reader";
import { TreeHash } from "@aws-sdk/sha256-tree-hash";
import { Decoder, HttpRequest, HashConstructor } from "@aws-sdk/types";
import { Decoder, HashConstructor, HttpRequest } from "@aws-sdk/types";
import { toHex } from "@aws-sdk/util-hex-encoding";
import { blobReader } from "@aws-sdk/chunked-blob-reader";

const MiB = 1024 * 1024;

Expand All @@ -19,10 +19,7 @@ export async function bodyChecksumGenerator(
contentHash.update(body);
treeHash.update(body);
} else {
if (
Boolean(body) &&
Object.prototype.toString.call(body) === "[object Blob]"
) {
if (Boolean(body) && Object.prototype.toString.call(body) === "[object Blob]") {
await blobReader(
body,
(chunk: any) => {
Expand Down
Loading