Skip to content

Commit

Permalink
fix: automatic lint fixes (#11636)
Browse files Browse the repository at this point in the history
* fix: automatic lint fixes

* fix: coerce type

* fix: api extract

* fix: double not

* fix: api extract

* fix: added prettierrc

* fix: adjust prettierrc
  • Loading branch information
sdstolworthy authored Dec 21, 2022
1 parent 71693cf commit 0e7f70b
Show file tree
Hide file tree
Showing 119 changed files with 496 additions and 493 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion packages/amplify-app/src/call-amplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const callNodeAmplify = async (args, opts) => {

const callPkgAmplify = isWin ? callPkgAmplifyWin : callPkgAmplifyNix;

const callAmplify = !!process.pkg ? callPkgAmplify : callNodeAmplify;
const callAmplify = !process.pkg ? callNodeAmplify : callPkgAmplify;

module.exports = {
callAmplify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function nullIfEmpty(obj: object): object | null {
return Object.keys(obj).length === 0 ? null : obj;
}

export function unmarshall(raw, isRaw: boolean = true) {
export function unmarshall(raw, isRaw = true) {
const content = isRaw ? Converter.unmarshall(raw) : raw;
// Because of the funky set type used in the aws-sdk, we need to further unwrap
// to find if there is a set that needs to be unpacked into an array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class AppSyncPipelineResolver extends AppSyncBaseResolver {
}

let prevResult = result;
for (let fnName of this.config.functions) {
for (const fnName of this.config.functions) {
const fnResolver = this.simulatorContext.getFunction(fnName);
({ result: prevResult, stash, hadException, args } = await fnResolver.resolve(source, args, stash, prevResult, context, info));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const phoneValidator = (ast, options) => {
throw new GraphQLError(`Query error: Can only parse strings got a: ${kind}`, [ast]);
}

let isValid = isValidNumber(value, country);
const isValid = isValidNumber(value, country);
if (!isValid) {
throw new GraphQLError('Query error: Not a valid phone number', [ast]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse, URLSearchParams } from 'url';
export function decodeHeaderFromQueryParam(rawUrl: string, paramName: string = 'header'): Record<string, any> {
export function decodeHeaderFromQueryParam(rawUrl: string, paramName = 'header'): Record<string, any> {
const url = parse(rawUrl);
const params = new URLSearchParams(url.query);
const base64Header = params.get(paramName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ElasticsearchUtils from "./elasticsearch-utils";
import ElasticsearchUtils from './elasticsearch-utils';

class ElasticsearchHelper {
private static readonly ES_UTILS: ElasticsearchUtils = new ElasticsearchUtils();

private static readonly ERROR_FORMAT: string = "Could not construct an Elasticsearch Query DSL from {0} and {1}";
private static readonly ERROR_FORMAT: string = 'Could not construct an Elasticsearch Query DSL from {0} and {1}';


/**
Expand Down Expand Up @@ -66,20 +66,20 @@ class ElasticsearchHelper {
*
*/
public getQueryDSL(filterInput: any): any {
let results: any[] = this.getQueryDSLRecursive(filterInput);
const results: any[] = this.getQueryDSLRecursive(filterInput);

return this.getOrAndSubexpressions(results)
}

public getScalarQueryDSL(fieldName: string, conditions: any): any[] {
let results: any[] = [];
let keys: string[] = Object.keys(conditions);
const results: any[] = [];
const keys: string[] = Object.keys(conditions);

keys.forEach((key: string) => {
const condition: string = key;
const value: any = conditions[key];

if ("range" === condition) {
if ('range' === condition) {
if (value.length && value.length < 1) {
return
}
Expand All @@ -89,43 +89,43 @@ class ElasticsearchHelper {
}

switch (condition) {
case "eq":
case 'eq':
results.push(ElasticsearchHelper.ES_UTILS.toEqExpression(fieldName, value));
break;
case "ne":
case 'ne':
results.push(ElasticsearchHelper.ES_UTILS.toNeExpression(fieldName, value));
break;
case "match":
case 'match':
results.push(ElasticsearchHelper.ES_UTILS.toMatchExpression(fieldName, value));
break;
case "matchPhrase":
case 'matchPhrase':
results.push(ElasticsearchHelper.ES_UTILS.toMatchPhraseExpression(fieldName, value));
break;
case "matchPhrasePrefix":
case 'matchPhrasePrefix':
results.push(ElasticsearchHelper.ES_UTILS.toMatchPhrasePrefixExpression(fieldName, value));
break;
case "multiMatch":
case 'multiMatch':
results.push(ElasticsearchHelper.ES_UTILS.toMultiMatchExpression(fieldName, value));
break;
case "exists":
case 'exists':
results.push(ElasticsearchHelper.ES_UTILS.toExistsExpression(fieldName, value));
break;
case "wildcard":
case 'wildcard':
results.push(ElasticsearchHelper.ES_UTILS.toWildcardExpression(fieldName, value));
break;
case "regexp":
case 'regexp':
results.push(ElasticsearchHelper.ES_UTILS.toRegularExpression(fieldName, value));
break;
case "gt":
case 'gt':
results.push(ElasticsearchHelper.ES_UTILS.toGtExpression(fieldName, value));
break;
case "gte":
case 'gte':
results.push(ElasticsearchHelper.ES_UTILS.toGteExpression(fieldName, value));
break;
case "lt":
case 'lt':
results.push(ElasticsearchHelper.ES_UTILS.toLTExpression(fieldName, value));
break;
case "lte":
case 'lte':
results.push(ElasticsearchHelper.ES_UTILS.toLTEExpression(fieldName, value));
break;
default:
Expand All @@ -137,28 +137,28 @@ class ElasticsearchHelper {
}

private getQueryDSLRecursive(filterInputFields: any): any[] {
let results: any[] = [];
let keys: string[] = Object.keys(filterInputFields);
const results: any[] = [];
const keys: string[] = Object.keys(filterInputFields);

keys.forEach((key: string) => {
const values: any = filterInputFields[key];
if (["and", "or"].includes(key.toLowerCase())) {
if (['and', 'or'].includes(key.toLowerCase())) {
const subexpressions: any[] = [];

values.forEach((value: any) => {
let siblingChildExpressions: any[] = this.getQueryDSLRecursive(value);
const siblingChildExpressions: any[] = this.getQueryDSLRecursive(value);
subexpressions.push(this.getOrAndSubexpressions(siblingChildExpressions));
});

if ("and" === (key.toLowerCase())) {
if ('and' === (key.toLowerCase())) {
results.push(ElasticsearchHelper.ES_UTILS.toAndExpression(subexpressions));
} else {
results.push(ElasticsearchHelper.ES_UTILS.toOrExpression(subexpressions));
}

} else if ("not" === (key.toLowerCase())) {
} else if ('not' === (key.toLowerCase())) {

let combinedDSLQuery: any[] = this.getQueryDSLRecursive(values);
const combinedDSLQuery: any[] = this.getQueryDSLRecursive(values);
results.push(ElasticsearchHelper.ES_UTILS.toNotExpression(this.getOrAndSubexpressions(combinedDSLQuery)));

} else {
Expand All @@ -180,7 +180,7 @@ class ElasticsearchHelper {

private format(format: string, args: any[]): string {
if (!args) {
return "";
return '';
}

return format.replace(/{(\d+)}/g, function (match, number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
*/
class ElasticsearchUtils {
private static readonly ONE: number = 1;
private static readonly BOOL: string = "bool";
private static readonly MUST: string = "must";
private static readonly MUST_NOT: string = "must_not";
private static readonly SHOULD: string = "should";
private static readonly MATCH: string = "match";
private static readonly MATCH_PHRASE: string = "match_phrase";
private static readonly MATCH_PHRASE_PREFIX: string = "match_phrase_prefix";
private static readonly MULTI_MATCH: string = "multi_match";
private static readonly EXISTS: string = "exists";
private static readonly WILDCARD: string = "wildcard";
private static readonly REGEXP: string = "regexp";
private static readonly RANGE: string = "range";
private static readonly GT: string = "gt";
private static readonly GTE: string = "gte";
private static readonly LT: string = "lt";
private static readonly LTE: string = "lte";
private static readonly MINIMUM_SHOULD_MATCH: string = "minimum_should_match";
private static readonly FIELD: string = "field";
private static readonly BOOL: string = 'bool';
private static readonly MUST: string = 'must';
private static readonly MUST_NOT: string = 'must_not';
private static readonly SHOULD: string = 'should';
private static readonly MATCH: string = 'match';
private static readonly MATCH_PHRASE: string = 'match_phrase';
private static readonly MATCH_PHRASE_PREFIX: string = 'match_phrase_prefix';
private static readonly MULTI_MATCH: string = 'multi_match';
private static readonly EXISTS: string = 'exists';
private static readonly WILDCARD: string = 'wildcard';
private static readonly REGEXP: string = 'regexp';
private static readonly RANGE: string = 'range';
private static readonly GT: string = 'gt';
private static readonly GTE: string = 'gte';
private static readonly LT: string = 'lt';
private static readonly LTE: string = 'lte';
private static readonly MINIMUM_SHOULD_MATCH: string = 'minimum_should_match';
private static readonly FIELD: string = 'field';

/**
* Convert a field and a value into Elasticsearch "match" expression.
Expand All @@ -37,7 +37,7 @@ class ElasticsearchUtils {
return null;
}

const updatedFieldName: string = ((typeof value) === "string") ? (fieldName + ".keyword") : fieldName;
const updatedFieldName: string = ((typeof value) === 'string') ? (fieldName + '.keyword') : fieldName;

return this.toMatchExpression(updatedFieldName, value);
}
Expand Down Expand Up @@ -381,7 +381,7 @@ class ElasticsearchUtils {
return null;
}

let andExpression: any = {
const andExpression: any = {
[ElasticsearchUtils.BOOL]: {
[ElasticsearchUtils.MUST]: filterClauses
}
Expand All @@ -403,7 +403,7 @@ class ElasticsearchUtils {
return null;
}

let andExpression: any = {
const andExpression: any = {
[ElasticsearchUtils.BOOL]: {
[ElasticsearchUtils.SHOULD]: filterClauses,
[ElasticsearchUtils.MINIMUM_SHOULD_MATCH]: ElasticsearchUtils.ONE
Expand All @@ -426,7 +426,7 @@ class ElasticsearchUtils {
return null;
}

let andExpression: any = {
const andExpression: any = {
[ElasticsearchUtils.BOOL]: {
[ElasticsearchUtils.MUST_NOT]: expression
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const time = () => ({
return null;
}
},
epochMilliSecondsToFormatted(timestamp: number, format: string, timezone: string = 'UTC'): string | null {
epochMilliSecondsToFormatted(timestamp: number, format: string, timezone = 'UTC'): string | null {
try {
return moment(timestamp)
.tz(timezone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const transformUtils = {
const queryDSL: $TSObject = elasticsearchHelper.getQueryDSL(filter.toJSON());
return JSON.stringify(queryDSL);
} catch (err) {
printer.error("Error when constructing the Elasticsearch Query DSL using the model transform utils. {}");
printer.error('Error when constructing the Elasticsearch Query DSL using the model transform utils. {}');
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getProviderPlugin = (context: $TSContext): ProviderUtils => {

async function loadResourceParametersLegacyCode(authResourceName: string): Promise<UserPoolMessageConfiguration> {
const legacyParameters = await stateManager.getResourceParametersJson(undefined, 'auth', authResourceName);
let userPoolMessageConfig: UserPoolMessageConfiguration = {
const userPoolMessageConfig: UserPoolMessageConfiguration = {
mfaConfiguration: legacyParameters.mfaConfiguration,
mfaTypes: legacyParameters.mfaTypes,
usernameAttributes: legacyParameters.usernameAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { printer } from 'amplify-prompts';
* A factory function that returns a function that prints the "success message" after adding auth
* @param print The amplify print object
*/
export const getPostAddAuthMessagePrinter = (resourceName: string, skipNextSteps: boolean = false) => {
export const getPostAddAuthMessagePrinter = (resourceName: string, skipNextSteps = false) => {
printer.success(`Successfully added auth resource ${resourceName} locally`);

if (!skipNextSteps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function getResourceCfnOutputAttributes(category: string, resourceName: s
const { cfnTemplate } = readCFNTemplate(cfnFilePath);
if (cfnTemplate && cfnTemplate.Outputs) {
const allOutputs: $TSObject = cfnTemplate.Outputs;
let outputsWithoutConditions: any = {};
const outputsWithoutConditions: any = {};

for (const key in allOutputs) {
if (!allOutputs[key]['Condition']) {
Expand All @@ -84,7 +84,7 @@ export function getAllResources() {
const allResources: $TSObject = {};

for (const category of categories) {
let resourcesList = category in meta ? Object.keys(meta[category]) : [];
const resourcesList = category in meta ? Object.keys(meta[category]) : [];

if (_.isEmpty(resourcesList)) {
continue;
Expand Down Expand Up @@ -251,7 +251,7 @@ export async function addCFNResourceDependency(context: $TSContext, customResour
selectedResources = _.concat(resourcesList);
}

for (let resourceName of selectedResources) {
for (const resourceName of selectedResources) {
// In case of some resources they are not in the meta file so check for resource existence as well
const isMobileHubImportedResource = _.get(amplifyMeta, [selectedCategory, resourceName, 'mobileHubMigrated'], false);
if (isMobileHubImportedResource) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function showUsageInformation(resources: AmplifyDependentResourceDefinition[]) {
}

function generateInputParametersForDependencies(resources: AmplifyDependentResourceDefinition[]) {
let parameters: $TSObject = {};
const parameters: $TSObject = {};

for (const resource of resources) {
for (const attribute of resource.attributes || []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function printLayerSuccessMessages(context: $TSContext, parameters: LayerParamet
if (parameters.runtimes.length !== 0) {
print.info('Move your libraries to the following folder:');
for (const runtime of parameters.runtimes) {
let runtimePath = path.join(relativeDirPath, 'lib', runtime.layerExecutablePath);
const runtimePath = path.join(relativeDirPath, 'lib', runtime.layerExecutablePath);
print.info(`[${runtime.name}]: ${runtimePath}`);
}
print.info('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function createLayerWalkthrough(
.getProjectDetails()
.projectConfig.projectName.toLowerCase()
.replace(/[^a-zA-Z0-9]/gi, '');
let { layerName } = await inquirer.prompt(layerNameQuestion(projectName));
const { layerName } = await inquirer.prompt(layerNameQuestion(projectName));
parameters.layerName = `${projectName}${layerName}`; // prefix with project name

const runtimeReturn = await runtimeWalkthrough(context, parameters);
Expand Down
Loading

0 comments on commit 0e7f70b

Please sign in to comment.