Skip to content

feat: add code linting and prettify #1350

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

Merged
merged 25 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 20 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
The table of contents is too big for display.
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"
}
};
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 + "]";
};

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
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"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"
},
"repository": {
"type": "git",
Expand All @@ -42,10 +43,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 +73,7 @@
"lerna": "3.22.1",
"lint-staged": "^10.0.1",
"mocha": "^8.0.1",
"prettier": "2.0.5",
"prettier": "^2.0.5",
"puppeteer": "^4.0.0",
"ts-loader": "^7.0.5",
"typescript": "~3.9.3",
Expand Down
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
5 changes: 3 additions & 2 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 Down
4 changes: 2 additions & 2 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 Down
9 changes: 5 additions & 4 deletions packages/body-checksum-node/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { bodyChecksumGenerator } from ".";
import { Sha256 } from "@aws-crypto/sha256-js";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { fromUtf8 } from "@aws-sdk/util-utf8-node";
import { Sha256 } from "@aws-crypto/sha256-js";
import { join } from "path";
import { tmpdir } from "os";
import { createReadStream, mkdtempSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
import { Readable } from "stream";

import { bodyChecksumGenerator } from ".";

function createTemporaryFile(contents: string | Buffer): string {
const folder = mkdtempSync(join(tmpdir(), "add-glacier-checksum-headers-node-"));
const fileLoc = join(folder, "test.txt");
Expand Down
8 changes: 4 additions & 4 deletions packages/body-checksum-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createReadStream } from "fs";
import { TreeHash } from "@aws-sdk/sha256-tree-hash";
import { Decoder, HttpRequest, HashConstructor } from "@aws-sdk/types";
import { streamReader } from "@aws-sdk/chunked-stream-reader-node";
import { isArrayBuffer } from "@aws-sdk/is-array-buffer";
import { TreeHash } from "@aws-sdk/sha256-tree-hash";
import { Decoder, HashConstructor, HttpRequest } from "@aws-sdk/types";
import { toHex } from "@aws-sdk/util-hex-encoding";
import { streamReader } from "@aws-sdk/chunked-stream-reader-node";
import { createReadStream } from "fs";

export async function bodyChecksumGenerator(
request: HttpRequest,
Expand Down
1 change: 1 addition & 0 deletions packages/chunked-stream-reader-node/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PassThrough } from "stream";

import { streamReader } from "./index";
import { ReadFromBuffers } from "./readable.fixture";

Expand Down
2 changes: 1 addition & 1 deletion packages/chunked-stream-reader-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from "stream";
export function streamReader(
stream: Readable,
onChunk: (chunk: Uint8Array) => void,
chunkSize: number = 1048576 // 1 MiB
chunkSize = 1048576 // 1 MiB
): Promise<void> {
return new Promise((resolve, reject) => {
let temporaryBuffer: Uint8Array | undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/chunked-stream-reader-node/src/readable.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ReadFromBuffersOptions extends ReadableOptions {

export class ReadFromBuffers extends Readable {
private buffersToRead: Buffer[];
private numBuffersRead: number = 0;
private numBuffersRead = 0;

private errorAfter: number;
constructor(options: ReadFromBuffersOptions) {
Expand All @@ -16,7 +16,7 @@ export class ReadFromBuffers extends Readable {
this.errorAfter = typeof options.errorAfter === "number" ? options.errorAfter : -1;
}

_read(size: number) {
_read() {
if (this.errorAfter !== -1 && this.errorAfter === this.numBuffersRead) {
this.emit("error", new Error("Mock Error"));
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/client-documentation-generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConverterComponent } from "typedoc/dist/lib/converter/components";
import { PluginHost } from "typedoc/dist/lib/utils";
import { SdkClientTocPlugin } from "./sdk-client-toc-plugin";
import { SdkClientSourceUpdatePlugin } from "./sdk-client-source-update";

import { SdkClientRenameGlobalPlugin } from "./sdk-client-rename-global";
import { SdkClientSourceUpdatePlugin } from "./sdk-client-source-update";
import { SdkClientTocPlugin } from "./sdk-client-toc-plugin";

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "typescript";
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
import { RendererEvent } from "typedoc/dist/lib/output/events";
import { NavigationPlugin } from "typedoc/dist/lib/output/plugins";
Expand All @@ -13,7 +12,7 @@ export class SdkClientRenameGlobalPlugin extends RendererComponent {
});
}

onRenderedBegin(event: RendererEvent) {
onRenderedBegin() {
const navigationItem = this.navigationPlugin.navigation;
if (!navigationItem) {
return;
Expand Down
Loading