Skip to content

Commit

Permalink
Merge pull request #276 from CoinageCrypto/task/bump-prettier
Browse files Browse the repository at this point in the history
Bump prettier dependency, reformat code to match new default style.
  • Loading branch information
thekevinbrown authored Aug 10, 2020
2 parents 706b756 + dc0f919 commit 32b86e6
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 55 deletions.
25 changes: 16 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"copy:configs": "cp -R ./src/eosio-config ./lib/eosio-config",
"clean": "rm -rf ./lib",
"docs": "typedoc --out api-docs ./src",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"format": "prettier --write \"src/**/*.ts\"",
"lamington:init": "lamington init",
"prepublishOnly": "npm test",
"prepare": "npm run build",
Expand Down Expand Up @@ -62,7 +62,7 @@
"auto-changelog": "1.16.2",
"eosjs": "20.0.3",
"eosjs-ecc": "4.0.7",
"prettier": "1.19.1",
"prettier": "2.0.5",
"ts-node": "8.6.2",
"typedoc": "0.16.10",
"typescript": "3.9.7"
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const accountNameFromPublicKey = (publicKey: string) => hashToEOSName(ecc
export const hashToEOSName = (data: string) =>
`l${data
.substring(0, 11)
.replace(digitPattern, match => digitMapping[match])
.replace(digitPattern, (match) => digitMapping[match])
.toLowerCase()}`;

export type EosioAction = {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/lamington-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const run = async () => {
}
};

run().catch(async error => {
run().catch(async (error) => {
process.exitCode = 1;
console.log(error);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/lamington-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const run = async () => {
);
};

run().catch(error => {
run().catch((error) => {
process.exitCode = 1;
console.log(error);
});
2 changes: 1 addition & 1 deletion src/cli/lamington-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const run = async () => {
await startEos();
};

run().catch(error => {
run().catch((error) => {
process.exitCode = 1;
console.log(error);
});
2 changes: 1 addition & 1 deletion src/cli/lamington-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const run = async () => {
await stopContainer();
};

run().catch(error => {
run().catch((error) => {
process.exitCode = 1;
console.log(error);
});
2 changes: 1 addition & 1 deletion src/cli/lamington-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const run = async () => {
}
};

run().catch(async error => {
run().catch(async (error) => {
process.exitCode = 1;
console.log(error);

Expand Down
10 changes: 5 additions & 5 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export const runTests = async () => {

// Run the tests.
await new Promise((resolve, reject) =>
mocha.run(failures => {
mocha.run((failures) => {
if (failures) return reject(failures);
return resolve();
})
Expand Down Expand Up @@ -350,7 +350,7 @@ export const buildAll = async (match?: string[]) => {
};

const onlyMatches = (paths: string[], matches: string[] = []) => {
return paths.filter(filePath => {
return paths.filter((filePath) => {
return matches.reduce<boolean>((result, str) => {
const pattern = new RegExp(str, 'gi');
return result || pattern.test(filePath);
Expand All @@ -359,7 +359,7 @@ const onlyMatches = (paths: string[], matches: string[] = []) => {
};

const includeMatches = (paths: string[]) => {
return paths.filter(filePath => {
return paths.filter((filePath) => {
return ConfigManager.include.reduce<boolean>((result, match) => {
const pattern = new RegExp(match, 'gi');
return result || pattern.test(filePath);
Expand All @@ -368,7 +368,7 @@ const includeMatches = (paths: string[]) => {
};

const filterMatches = (paths: string[]) => {
return paths.filter(filePath => {
return paths.filter((filePath) => {
return !ConfigManager.exclude.reduce<boolean>((result, match) => {
const pattern = new RegExp(match, 'gi');
return result || pattern.test(filePath);
Expand Down Expand Up @@ -462,7 +462,7 @@ export const compileContract = async (contractPath: string) => {
contractPath
)}" "${outputPath}" "${basename}" ${buildFlags}`
)
.catch(err => {
.catch((err) => {
spinner.fail('Failed to compile');
console.log(` --> ${err}`);
throw err;
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Contract implements EOSJSContract {
this.types = types;
// Set up all the actions as methods on the contract.
for (const action of actions.values()) {
(this as any)[action.name] = function() {
(this as any)[action.name] = function () {
const data: { [key: string]: any } = {};

// Copy the params across for the call.
Expand Down Expand Up @@ -141,7 +141,7 @@ export class Contract implements EOSJSContract {
}
// And now the tables.
for (const table of abi.tables) {
(this as any)[camelCase(table.name) + 'Table'] = function() {
(this as any)[camelCase(table.name) + 'Table'] = function () {
return this.getTableRows(table.name, arguments[0]);
};
}
Expand Down Expand Up @@ -182,14 +182,14 @@ export class Contract implements EOSJSContract {
// This mapping will always be limited to just the types we do special
// things with in Lamington world, and will always match the generated
// types for table rows. Other values will pass through untouched.
const tableAbi = this._abi.tables.find(tableAbi => tableAbi.name === table);
const tableAbi = this._abi.tables.find((tableAbi) => tableAbi.name === table);
if (!tableAbi) throw new Error(`Could not find ABI for table ${table}`);
const tableRowType = this.types.get(tableAbi.type);
if (!tableRowType) throw new Error(`Could not find table row type for table ${table}`);

// Bool is the only type we need to fiddle with at the moment, so only do this if
// there's a field with a bool type in it.
const booleanFields = tableRowType.fields.filter(field => field.typeName === 'bool');
const booleanFields = tableRowType.fields.filter((field) => field.typeName === 'bool');

if (booleanFields.length > 0) {
// Map all `bool` fields from numbers to booleans
Expand All @@ -208,7 +208,7 @@ export class Contract implements EOSJSContract {
}
}

const dateFields = tableRowType.fields.filter(field => field.typeName === 'time_point_sec');
const dateFields = tableRowType.fields.filter((field) => field.typeName === 'time_point_sec');

if (dateFields.length > 0) {
// Map all `time_point_sec` fields from numbers to Date
Expand Down
34 changes: 17 additions & 17 deletions src/contracts/typeGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ const stringNumberTypes = [
'table_name',
];

describe('type generator', function() {
context('map parameter types', function() {
it(`should map 'string' to 'string'`, function() {
describe('type generator', function () {
context('map parameter types', function () {
it(`should map 'string' to 'string'`, function () {
assert.equal(
mapParameterType({ eosType: 'string' }),
'string',
`'string' types should map to 'string'`
);
});

it(`should map 'bool' to 'boolean'`, function() {
it(`should map 'bool' to 'boolean'`, function () {
assert.equal(mapParameterType({ eosType: 'bool' }), 'boolean');
});

context('eos types', function() {
it(`should map name types to 'string|number'`, function() {
stringNumberTypes.map(eosType =>
context('eos types', function () {
it(`should map name types to 'string|number'`, function () {
stringNumberTypes.map((eosType) =>
assert.equal(
mapParameterType({ eosType }),
'string|number',
Expand All @@ -65,7 +65,7 @@ describe('type generator', function() {
);
});

it(`should map 'checksum' to 'string'`, function() {
it(`should map 'checksum' to 'string'`, function () {
assert.equal(
mapParameterType({ eosType: 'checksum' }),
'string',
Expand All @@ -74,9 +74,9 @@ describe('type generator', function() {
});
});

context('big numbers', function() {
numberTypes.forEach(eosType => {
it(`should map '${eosType}' to 'number'`, function() {
context('big numbers', function () {
numberTypes.forEach((eosType) => {
it(`should map '${eosType}' to 'number'`, function () {
assert.equal(
mapParameterType({ eosType }),
'number',
Expand All @@ -86,12 +86,12 @@ describe('type generator', function() {
});
});

context('complex types', function() {
it(`should handle array types`, function() {
context('complex types', function () {
it(`should handle array types`, function () {
assert.equal(mapParameterType({ eosType: 'bool[]' }), 'Array<boolean>');
});

it(`should handle custom types from the contract`, function() {
it(`should handle custom types from the contract`, function () {
assert.equal(
mapParameterType({
eosType: 'pair_uint8_string',
Expand All @@ -102,7 +102,7 @@ describe('type generator', function() {
);
});

it(`should handle custom types in containers`, function() {
it(`should handle custom types in containers`, function () {
assert.equal(
mapParameterType({
eosType: 'pair_uint8_string[]',
Expand Down Expand Up @@ -302,8 +302,8 @@ describe('type generator', function() {
});
});

context('type generation integration tests', function() {
before(async function() {
context('type generation integration tests', function () {
before(async function () {
// This can take a long time.
this.timeout(400000);

Expand Down
7 changes: 4 additions & 3 deletions src/contracts/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ export const generateTypesFromString = async (
// Generate tables
const generatedTables = contractTables.map(
(table: any) =>
`${camelCase(table.name) +
'Table'}(options?: GetTableRowsOptions): Promise<TableRowsResult<${pascalCase(
`${
camelCase(table.name) + 'Table'
}(options?: GetTableRowsOptions): Promise<TableRowsResult<${pascalCase(
contractName
)}${pascalCase(table.type)}>>;`
);
Expand Down Expand Up @@ -215,7 +216,7 @@ const saveInterface = async (contractIdentifier: string, interfaceContent: strin
// Open a write stream to file
const file = fs.createWriteStream(`${contractIdentifier}.ts`);

file.write(interfaceContent, error => {
file.write(interfaceContent, (error) => {
if (error) {
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export const pascalCase = (value: string) => {
const snakePattern = /[_.]+./g;
const upperFirst = value[0].toUpperCase() + value.slice(1);
return upperFirst.replace(snakePattern, match => match[match.length - 1].toUpperCase());
return upperFirst.replace(snakePattern, (match) => match[match.length - 1].toUpperCase());
};

/**
Expand All @@ -18,5 +18,5 @@ export const pascalCase = (value: string) => {
*/
export const camelCase = (value: string) => {
const snakePattern = /[_.]+./g;
return value.replace(snakePattern, match => match[match.length - 1].toUpperCase());
return value.replace(snakePattern, (match) => match[match.length - 1].toUpperCase());
};
4 changes: 2 additions & 2 deletions src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export class EOSManager {

return await eos
.transact(transaction, flattenedOptions)
.then(value => {
.then((value) => {
logOutput(chalk.green('Succeeded: ') + JSON.stringify(value, null, 4));
return value;
})
.catch(error => {
.catch((error) => {
logOutput(
chalk.red('Threw error: ') +
error +
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const untilBlocknumber = async (number: number) => {
* @param delayInMs Process sleep duration
*/
export const sleep = async (delayInMs: number) =>
new Promise(resolve => setTimeout(resolve, delayInMs));
new Promise((resolve) => setTimeout(resolve, delayInMs));

/**
* Pauses the current process for the 500ms EOS block time
Expand Down Expand Up @@ -206,7 +206,7 @@ export const assertEOSErrorIncludesMessage = async (
const eosErrorName = errorName || 'eosio_assert_message_exception';
// Execute operation and handle exceptions
if (
!(await assertExpectedEOSError(operation, eosErrorName, error => {
!(await assertExpectedEOSError(operation, eosErrorName, (error) => {
let errorMessage = error.json.error.details[0].message;

if (!errorMessage) {
Expand Down Expand Up @@ -256,7 +256,7 @@ export async function debugPromise<T>(
: debugPrefix + 'error - ' + successMessage + ': ';
const promiseTimer = timer();
return promise
.then(value => {
.then((value) => {
if (ConfigManager.debugLevelVerbose || ConfigManager.debugLevelMin) {
console.log(chalk.green(successString) + chalk.blue(' (%s)'), promiseTimer.ms);
}
Expand All @@ -265,7 +265,7 @@ export async function debugPromise<T>(
}
return value;
})
.catch(err => {
.catch((err) => {
assert.fail(errorString + err);
});
}
Expand Down

0 comments on commit 32b86e6

Please sign in to comment.