Skip to content

Commit

Permalink
build(deps): migrate to ESLint+Prettier
Browse files Browse the repository at this point in the history
TSLint has been deprecated for quite a while. We kept it going
as long as we could but now with the onboarding of a few new
people issues are coming up with it not working as well as it
could so it was time to make the move to ESLint finally.

There's hundrds of warnings emitted by ESLint (mostly not errors
because we nerfed the errors down to warnings for now just to
keep it easier to accomplish the task without having to rewrite
a thousand lines of code all at once).

Follow-up tasks can be created for the existing warnings so that
eventually we can turn off the --quiet flag on ESLint which for
the moment makes it so that when you run the lint task you are
only seeing the errors in the output and not the warnings.

The biggest gain from ESLint here is that the IDE support will
hopefully work on everyone's dev machines not just the person
who originally configured it.

Fixes #518

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Feb 2, 2021
1 parent 9dbb10d commit 8854039
Show file tree
Hide file tree
Showing 136 changed files with 1,066 additions and 538 deletions.
16 changes: 16 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# !packages/cactus-*/**
# !examples/cactus-*/**

# examples/cartrade/
# packages/business-logic-plugin/
# packages/ledger-plugin/
# packages/routing-interface/
# packages/config/

# **/dist/**
# **/node_modules/**
# **/build/**
# **/coverage/**

# typings/**
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"no-prototype-builtins": "error",
"@typescript-eslint/no-var-requires": "warn",
"no-dupe-class-members": "off",
"no-unused-vars": [
"warn",
{
vars: "all",
args: "after-used",
ignoreRestSiblings: false,
},
],
indent: ["off"],
semi: ["error", "always"],
"new-cap": ["off"],
"comma-dangle": ["warn", "always-multiline"],
},
};
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
useTabs: false,
semi: true,
printWidth: 80,
tabWidth: 2,
trailingComma: "all",
singleQuote: false,
};
6 changes: 0 additions & 6 deletions .prettierrc.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SupplyChainAppDummyInfrastructure {
}

constructor(
public readonly options: ISupplyChainAppDummyInfrastructureOptions
public readonly options: ISupplyChainAppDummyInfrastructureOptions,
) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export async function launchApp(cliOpts?: any): Promise<void> {
try {
await supplyChainApp.start();
} catch (ex) {
// tslint:disable-next-line: no-console
console.error(`SupplyChainApp crashed. Existing...`, ex);
await supplyChainApp.stop();
process.exit(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class SupplyChainApp {
httpApiA,
httpApiB,
keyPairA,
keyPairB
keyPairB,
);
const consortiumPrettyJson = JSON.stringify(consortiumDatabase, null, 4);
this.log.info(`Created Consortium definition: %o`, consortiumPrettyJson);
Expand Down Expand Up @@ -220,7 +220,7 @@ export class SupplyChainApp {
serverA: Server,
serverB: Server,
keyPairA: JWK.ECKey,
keyPairB: JWK.ECKey
keyPairB: JWK.ECKey,
): ConsortiumDatabase {
const consortiumName = "Example Supply Chain Consortium";
const consortiumId = uuidv4();
Expand Down Expand Up @@ -301,7 +301,7 @@ export class SupplyChainApp {
public async startNode(
httpServerApi: Server,
httpServerCockpit: Server,
pluginRegistry: PluginRegistry
pluginRegistry: PluginRegistry,
): Promise<ApiServer> {
const addressInfo = httpServerApi.address() as AddressInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable-next-line: no-var-requires
const tap = require("tap");
import * as publicApi from "../../../main/typescript/public-api";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export class SupplyChainCactusPlugin
Checks.truthy(options.contracts, `${fnTag} arg options.contracts`);
Checks.truthy(
options.web3SigningCredential,
`${fnTag} arg options.web3SigningCredential`
`${fnTag} arg options.web3SigningCredential`,
);
Checks.truthy(
options.quorumApiClient,
`${fnTag} arg options.quorumApiClient`
`${fnTag} arg options.quorumApiClient`,
);

const level = this.options.logLevel || "INFO";
Expand All @@ -65,7 +65,7 @@ export class SupplyChainCactusPlugin
}

public async installWebServices(
expressApp: any
expressApp: any,
): Promise<IWebServiceEndpoint[]> {
const insertBambooHarvest = new InsertBambooHarvestEndpoint({
contractAddress: this.options.contracts.bambooHarvestRepository.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint {
Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`);
Checks.nonBlankString(
opts.contractAddress,
`${fnTag} options.contractAddress`
`${fnTag} options.contractAddress`,
);

const level = this.opts.logLevel || "INFO";
Expand Down Expand Up @@ -79,7 +79,7 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint {
async handleRequest(
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
): Promise<void> {
const tag = `${this.getVerbLowerCase().toUpperCase()} ${this.getPath()}`;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class InsertBookshelfEndpoint implements IWebServiceEndpoint {
Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`);
Checks.nonBlankString(
opts.contractAddress,
`${fnTag} options.contractAddress`
`${fnTag} options.contractAddress`,
);

const level = this.opts.logLevel || "INFO";
Expand Down Expand Up @@ -79,7 +79,7 @@ export class InsertBookshelfEndpoint implements IWebServiceEndpoint {
async handleRequest(
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
): Promise<void> {
const tag = `${this.getVerbLowerCase().toUpperCase()} ${this.getPath()}`;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ListBambooHarvestEndpoint implements IWebServiceEndpoint {
Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`);
Checks.nonBlankString(
opts.contractAddress,
`${fnTag} options.contractAddress`
`${fnTag} options.contractAddress`,
);

const level = this.opts.logLevel || "INFO";
Expand Down Expand Up @@ -78,7 +78,7 @@ export class ListBambooHarvestEndpoint implements IWebServiceEndpoint {
async handleRequest(
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
): Promise<void> {
const tag = `${this.getVerbLowerCase().toUpperCase()} ${this.getPath()}`;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ListBookshelfEndpoint implements IWebServiceEndpoint {
Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`);
Checks.nonBlankString(
opts.contractAddress,
`${fnTag} options.contractAddress`
`${fnTag} options.contractAddress`,
);

const level = this.opts.logLevel || "INFO";
Expand Down Expand Up @@ -78,7 +78,7 @@ export class ListBookshelfEndpoint implements IWebServiceEndpoint {
async handleRequest(
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
): Promise<void> {
const tag = `${this.getVerbLowerCase().toUpperCase()} ${this.getPath()}`;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable-next-line: no-var-requires
const tap = require("tap");
import * as publicApi from "../../../main/typescript/public-api";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const routes: Routes = [
path: "bamboo-harvest-list",
loadChildren: () =>
import("./bamboo-harvest/bamboo-harvest.module").then(
(m) => m.BambooHarvestPageModule
(m) => m.BambooHarvestPageModule,
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar
private statusBar: StatusBar,
) {
this.initializeApp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class BambooHarvestDetailPage implements OnInit {
private readonly baseClient: ApiClient,
public readonly modalController: ModalController,
public readonly formBuilder: FormBuilder,
@Inject(QUORUM_DEMO_LEDGER_ID) private readonly quorumLedgerId: string
@Inject(QUORUM_DEMO_LEDGER_ID) private readonly quorumLedgerId: string,
) {
this.log = LoggerProvider.getOrCreate({ label: "BambooHarvestDetailPage" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BambooHarvestListPage implements OnInit {
constructor(
private readonly baseClient: ApiClient,
private readonly modalController: ModalController,
@Inject(QUORUM_DEMO_LEDGER_ID) private readonly quorumLedgerId: string
@Inject(QUORUM_DEMO_LEDGER_ID) private readonly quorumLedgerId: string,
) {
this.bambooHarvests = [];
this.log = LoggerProvider.getOrCreate({ label: "BambooHarvestListPage" });
Expand All @@ -43,7 +43,7 @@ export class BambooHarvestListPage implements OnInit {
async ngOnInit(): Promise<void> {
this._supplyChainApi = await this.baseClient.ofLedger(
this.quorumLedgerId,
SupplyChainApi
SupplyChainApi,
);
await this.loadData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class BookshelfDetailPage implements OnInit {
private readonly baseClient: ApiClient,
@Inject(QUORUM_DEMO_LEDGER_ID) private readonly quorumLedgerId: string,
public readonly modalController: ModalController,
public readonly formBuilder: FormBuilder
public readonly formBuilder: FormBuilder,
) {
this.log = LoggerProvider.getOrCreate({ label: "BookshelfDetailPage" });
}
Expand All @@ -51,7 +51,7 @@ export class BookshelfDetailPage implements OnInit {

this._supplyChainApi = await this.baseClient.ofLedger(
this.quorumLedgerId,
SupplyChainApi
SupplyChainApi,
);

if (!this.bookshelf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class BookshelfListPage implements OnInit {
constructor(
private readonly baseClient: ApiClient,
private readonly modalController: ModalController,
@Inject(BESU_DEMO_LEDGER_ID) private readonly ledgerId: string
@Inject(BESU_DEMO_LEDGER_ID) private readonly ledgerId: string,
) {
this.bookshelves = [];
this.log = LoggerProvider.getOrCreate({ label: "BookshelfListPage" });
Expand All @@ -41,7 +41,7 @@ export class BookshelfListPage implements OnInit {
async ngOnInit(): Promise<void> {
this._supplyChainApi = await this.baseClient.ofLedger(
this.ledgerId,
SupplyChainApi
SupplyChainApi,
);
await this.loadData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { InjectionToken } from "@angular/core";

export const CACTUS_API_URL = new InjectionToken<string>("CACTUS_API_URL");
export const QUORUM_DEMO_LEDGER_ID = new InjectionToken<string>(
"QUORUM_DEMO_LEDGER_ID"
"QUORUM_DEMO_LEDGER_ID",
);
export const BESU_DEMO_LEDGER_ID = new InjectionToken<string>(
"BESU_DEMO_LEDGER_ID"
"BESU_DEMO_LEDGER_ID",
);
Loading

0 comments on commit 8854039

Please sign in to comment.