Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Configuring lints (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarishmaBothara authored and jordy25519 committed Dec 9, 2019
1 parent 041ec4d commit aa2b078
Show file tree
Hide file tree
Showing 12 changed files with 2,440 additions and 154 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
59 changes: 59 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": ["airbnb", "prettier", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended"],
"parserOptions": {
"ecmaVersion": 10,
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"settings": {
"import/resolver": {
"babel-module": {}
}
},
"plugins": ["prettier", "import"],
"globals": {
"shallow": true,
"var2": false
},
"rules": {
"no-nested-ternary": 0,
"no-unused-vars": 0,
"react/prop-types": 0,
"func-names": 0,
"arrow-body-style": 0,
"arrow-parens": 0,
"consistent-return": 0,
"import/no-extraneous-dependencies": 0,
"import/no-cycle": 1,
"import/prefer-default-export": 0,
"linebreak-style": 0,
"max-len": 0,
"no-confusing-arrow": 0,
"no-console": [
"error",
{
"allow": ["warn", "error"]
}
],
"no-underscore-dangle": 0,
"prefer-promise-reject-errors": 0,
"no-plusplus": 0,
"prefer-template": 0,
"prefer-destructuring": 1,
"no-return-await": 0,
"lines-between-class-members": 0,
"no-unused-expressions": 0,
"no-return-assign": 0,
"no-restricted-syntax": 0,
"no-script-url": 0
}
}
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/CHANGELOG.md
**/node_modules/**
**/.*/**
**/coverage/**
**/dist/**
*.d.ts
**/.DS_Store
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"trailingComma": "es5",
"tabWidth": 2,
"singleQuote": true,
"bracketSpacing": true
}
27 changes: 25 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"devDependencies": {
"@polkadot/api": "^0.95.2"
"@polkadot/api": "^0.95.2",
"@typescript-eslint/eslint-plugin": "^2.9.0",
"@typescript-eslint/parser": "^2.9.0",
"eslint": "^6.7.1",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.3",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.1.0",
"lint-staged": "^9.4.2",
"prettier": "^1.19.1",
"pretty-quick": "^1.11.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -19,5 +31,16 @@
"bugs": {
"url": "https://github.com/plugblockchain/plug-api-types/issues"
},
"homepage": "https://github.com/plugblockchain/plug-api-types#readme"
"homepage": "https://github.com/plugblockchain/plug-api-types#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged -r 'types/*'"
}
},
"lint-staged": {
"*.ts": [
"eslint --fix",
"git add"
]
}
}
38 changes: 19 additions & 19 deletions types/Doughnut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {AnyU8a, Codec} from '@polkadot/types/types';
import Bytes from '@polkadot/types/primitive/Bytes';
import Compact from '@polkadot/types/codec/Compact';
import U8a from '@polkadot/types/codec/U8a';
import Bytes from '@polkadot/types/primitive/Bytes';
import { AnyU8a, Codec } from '@polkadot/types/types';

/**
* An encoded, signed v0 Doughnut certificate
**/
export default class Doughnut extends U8a implements Codec {
public get encodedLength (): number {
return this.toU8a().length;
}
public get encodedLength(): number {
return this.toU8a().length;
}

constructor(value?: AnyU8a) {
// This function is used as both a constructor and a decoder
// Doughnut has its own codec but it must be length prefixed to support the SCALE codec used by the extrinsic
constructor(value?: AnyU8a) {
// This function is used as both a constructor and a decoder
// Doughnut has its own codec but it must be length prefixed to support the SCALE codec used by the extrinsic

// Failure to decode indicates a call as a constructor
const decoded = new Bytes(value);
if (decoded.length > 0) {
super(decoded);
} else {
super(value);
}
// Failure to decode indicates a call as a constructor
const decoded = new Bytes(value);
if (decoded.length > 0) {
super(decoded);
} else {
super(value);
}
}

toU8a(isBare?: boolean): Uint8Array {
// Encode the doughnut with length prefix to support SCALE codec
return isBare ? (this as Uint8Array) : Compact.addLengthPrefix(this);
}
toU8a(isBare?: boolean): Uint8Array {
// Encode the doughnut with length prefix to support SCALE codec
return isBare ? (this as Uint8Array) : Compact.addLengthPrefix(this);
}
}
37 changes: 22 additions & 15 deletions types/Extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ This file is a copy of `@polkadot/types/primitive/Extrinsic/v4/Extrinsic`
It has had its payload and signature type changed to use Plug versions.
**/
import { Address, Call } from '@polkadot/types/interfaces/runtime';
import { ExtrinsicPayloadValue, IExtrinsicImpl, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
import { ExtrinsicOptions } from '@polkadot/types/primitive/Extrinsic/types';
import { ExtrinsicPayloadValue, IExtrinsicImpl, IKeyringPair, SignatureOptions } from '@polkadot/types/types';

import { isU8a } from '@polkadot/util';

import { createType, ClassOf } from '@polkadot/types/codec/create';
import { ClassOf, createType } from '@polkadot/types/codec/create';
import Struct from '@polkadot/types/codec/Struct';
import PlugExtrinsicSignatureV1 from './ExtrinsicSignature';

Expand All @@ -30,14 +30,17 @@ export interface ExtrinsicValueV4 {
* It is lightly modified [[ExtrinsicV4]] from `@polkadot/types`
*/
export default class PlugExtrinsicV1 extends Struct implements IExtrinsicImpl {
public constructor (value?: Uint8Array | ExtrinsicValueV4 | Call, { isSigned }: Partial<ExtrinsicOptions> = {}) {
super({
signature: PlugExtrinsicSignatureV1,
method: 'Call'
}, PlugExtrinsicV1.decodeExtrinsic(value, isSigned));
public constructor(value?: Uint8Array | ExtrinsicValueV4 | Call, { isSigned }: Partial<ExtrinsicOptions> = {}) {
super(
{
signature: PlugExtrinsicSignatureV1,
method: 'Call',
},
PlugExtrinsicV1.decodeExtrinsic(value, isSigned)
);
}

public static decodeExtrinsic (value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 {
public static decodeExtrinsic(value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 {
if (!value) {
return {};
} else if (value instanceof PlugExtrinsicV1) {
Expand All @@ -51,7 +54,7 @@ export default class PlugExtrinsicV1 extends Struct implements IExtrinsicImpl {

return {
method,
signature
signature,
};
}

Expand All @@ -61,35 +64,39 @@ export default class PlugExtrinsicV1 extends Struct implements IExtrinsicImpl {
/**
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
public get encodedLength(): number {
return this.toU8a().length;
}

/**
* @description The [[Call]] this extrinsic wraps
*/
public get method (): Call {
public get method(): Call {
return this.get('method') as Call;
}

/**
* @description The [[PlugExtrinsicSignatureV1]]
*/
public get signature (): PlugExtrinsicSignatureV1 {
public get signature(): PlugExtrinsicSignatureV1 {
return this.get('signature') as PlugExtrinsicSignatureV1;
}

/**
* @description The version for the signature
*/
public get version (): number {
public get version(): number {
return TRANSACTION_VERSION;
}

/**
* @description Add an [[PlugExtrinsicSignatureV1]] to the extrinsic (already generated)
*/
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): PlugExtrinsicV1 {
public addSignature(
signer: Address | Uint8Array | string,
signature: Uint8Array | string,
payload: ExtrinsicPayloadValue | Uint8Array | string
): PlugExtrinsicV1 {
this.signature.addSignature(signer, signature, payload);

return this;
Expand All @@ -98,7 +105,7 @@ export default class PlugExtrinsicV1 extends Struct implements IExtrinsicImpl {
/**
* @description Sign the extrinsic with a specific keypair
*/
public sign (account: IKeyringPair, options: SignatureOptions): PlugExtrinsicV1 {
public sign(account: IKeyringPair, options: SignatureOptions): PlugExtrinsicV1 {
this.signature.sign(this.method, account, options);

return this;
Expand Down
Loading

0 comments on commit aa2b078

Please sign in to comment.