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 23 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"
}
};
9 changes: 8 additions & 1 deletion 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 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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sep } from "path";
import * as ts from "typescript";
import { ConverterComponent, Component } from "typedoc/dist/lib/converter/components";
import { Converter } from "typedoc/dist/lib/converter";
import { Component, ConverterComponent } from "typedoc/dist/lib/converter/components";
import { Context } from "typedoc/dist/lib/converter/context";
import { SourceFile } from "typedoc/dist/lib/models";
import * as ts from "typescript";

const basePathsToIgnore = ["model"];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import * as ts from "typescript";
import { ReferenceType } from "typedoc/dist/lib/models";
import { DeclarationReflection, Reflection, ReflectionKind } from "typedoc/dist/lib/models/reflections";
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
import {
Reflection,
ProjectReflection,
ReflectionKind,
DeclarationReflection,
} from "typedoc/dist/lib/models/reflections";
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";
import { PageEvent } from "typedoc/dist/lib/output/events";
import { ReferenceType } from "typedoc/dist/lib/models";
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";

@Component({ name: "SdkClientTocPlugin" })
export class SdkClientTocPlugin extends RendererComponent {
Expand Down Expand Up @@ -124,7 +118,7 @@ export class SdkClientTocPlugin extends RendererComponent {
this.commandToNavigationItems.set(commandName, item);
}
} else if (this.isException(child)) {
const item = NavigationItem.create(child, this.exceptionsNavigationItem, true);
NavigationItem.create(child, this.exceptionsNavigationItem, true);
} else if (
this.isUnion(child) &&
(child as any).type.types.every((type: ReferenceType) => {
Expand All @@ -133,11 +127,11 @@ export class SdkClientTocPlugin extends RendererComponent {
) {
// get command from name
const commandName = child.name.replace("ExceptionsUnion", "").toLowerCase() + "command";
const item = NavigationItem.create(child, this.commandToNavigationItems.get(commandName), true);
NavigationItem.create(child, this.commandToNavigationItems.get(commandName), true);
} else if (this.isInputOrOutput(child)) {
// get command from name
const commandName = child.name.replace(/Input|Output/, "").toLowerCase() + "command";
const item = NavigationItem.create(child, this.commandToNavigationItems.get(commandName), true);
NavigationItem.create(child, this.commandToNavigationItems.get(commandName), true);
} else if (child.name.startsWith("_")) {
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/config-resolver/src/EndpointsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Provider, UrlParser, Endpoint, RegionInfoProvider, RegionInfo } from "@aws-sdk/types";
import { Endpoint, Provider, RegionInfo,RegionInfoProvider, UrlParser } from "@aws-sdk/types";

export function normalizeEndpoint(
endpoint?: string | Endpoint | Provider<Endpoint>,
Expand Down
2 changes: 1 addition & 1 deletion packages/config-resolver/src/RegionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface RegionResolvedConfig {
region: Provider<string>;
}
export function resolveRegionConfig<T>(input: T & RegionInputConfig & PreviouslyResolved): T & RegionResolvedConfig {
let region = input.region || input.regionDefaultProvider(input as any);
const region = input.region || input.regionDefaultProvider(input as any);
return {
...input,
region: normalizeRegion(region),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logins } from "./Logins";
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";

import { Logins } from "./Logins";

export interface CognitoProviderParameters {
/**
* The SDK client with which the credential provider will contact the Amazon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class IndexedDbStorage implements Storage {
reject(new Error("Unable to access DB"));
};

openDbRequest.onupgradeneeded = (event) => {
openDbRequest.onupgradeneeded = () => {
const db = openDbRequest.result;
db.onerror = () => {
reject(new Error("Failed to create object store"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fromCognitoIdentity } from "./fromCognitoIdentity";
import { ProviderError } from "@aws-sdk/property-provider";
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
import { ProviderError } from "@aws-sdk/property-provider";

import { fromCognitoIdentity } from "./fromCognitoIdentity";

describe("fromCognitoIdentity", () => {
const identityId = "id";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
import { ProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider, Credentials } from "@aws-sdk/types";

import { CognitoProviderParameters } from "./CognitoProviderParameters";
import { resolveLogins } from "./resolveLogins";
import { ProviderError } from "@aws-sdk/property-provider";
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
import { Credentials, CredentialProvider } from "@aws-sdk/types";

/**
* Retrieves temporary AWS credentials using Amazon Cognito's
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fromCognitoIdentityPool } from "./fromCognitoIdentityPool";
import { ProviderError } from "@aws-sdk/property-provider";
import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
import { ProviderError } from "@aws-sdk/property-provider";

import { fromCognitoIdentityPool } from "./fromCognitoIdentityPool";

jest.mock("./fromCognitoIdentity", () => {
const promiseFunc = jest.fn().mockResolvedValue({
Expand All @@ -23,8 +24,8 @@ jest.mock("./localStorage", () => {
},
};
});
import { localStorage } from "./localStorage";
import { InMemoryStorage } from "./InMemoryStorage";
import { localStorage } from "./localStorage";

describe("fromCognitoIdentityPool", () => {
const identityPoolId = "poolId";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
import { ProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";

import { CognitoProviderParameters } from "./CognitoProviderParameters";
import { fromCognitoIdentity } from "./fromCognitoIdentity";
import { localStorage } from "./localStorage";
import { resolveLogins } from "./resolveLogins";
import { Storage } from "./Storage";
import { ProviderError } from "@aws-sdk/property-provider";
import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
import { CredentialProvider } from "@aws-sdk/types";

/**
* Retrieves or generates a unique identifier using Amazon Cognito's `GetId`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localStorage as storage } from "./localStorage";
import { InMemoryStorage } from "./InMemoryStorage";
import { localStorage as storage } from "./localStorage";

describe("localStorage", () => {
// set store and restore indexedDB and localStorage before and after the test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localStorage } from "./localStorage";
import { IndexedDbStorage } from "./IndexedDbStorage";
import { localStorage } from "./localStorage";

describe("localStorage", () => {
const storageAtInit: Storage | undefined = window?.localStorage;
Expand Down
3 changes: 2 additions & 1 deletion packages/credential-provider-env/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ProviderError } from "@aws-sdk/property-provider";
import { ENV_KEY, ENV_SECRET, ENV_SESSION, ENV_EXPIRATION, fromEnv } from "./";

import { ENV_EXPIRATION, ENV_KEY, ENV_SECRET, ENV_SESSION, fromEnv } from "./";

const akid = process.env[ENV_KEY];
const secret = process.env[ENV_SECRET];
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-provider-env/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialProvider } from "@aws-sdk/types";
import { ProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";

export const ENV_KEY = "AWS_ACCESS_KEY_ID";
export const ENV_SECRET = "AWS_SECRET_ACCESS_KEY";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("fromContainerMetadata", () => {
});

it("should retry responses that receive invalid response values", async () => {
for (let key of Object.keys(creds)) {
for (const key of Object.keys(creds)) {
const invalidCreds: any = { ...creds };
delete invalidCreds[key];
mockHttpRequest.mockReturnValueOnce(Promise.resolve(JSON.stringify(invalidCreds)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";
import { RemoteProviderInit, providerConfigFromInit } from "./remoteProvider/RemoteProviderInit";
import { RequestOptions } from "http";
import { parse } from "url";

import { httpRequest } from "./remoteProvider/httpRequest";
import { fromImdsCredentials, isImdsCredentials } from "./remoteProvider/ImdsCredentials";
import { providerConfigFromInit, RemoteProviderInit } from "./remoteProvider/RemoteProviderInit";
import { retry } from "./remoteProvider/retry";
import { ProviderError } from "@aws-sdk/property-provider";
import { parse } from "url";
import { RequestOptions } from "http";

export const ENV_CMDS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
export const ENV_CMDS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
Expand Down
Loading