Merge pull request #1369 from bitcoinjs/lint

ci: add a tslint rule to require type definitions
This commit is contained in:
Jonathan Underwood 2019-03-22 12:44:01 +09:00 committed by GitHub
commit 63d6d94d8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 39 additions and 32 deletions

View file

@ -1,13 +1,14 @@
sudo: false
language: node_js
node_js:
- "8"
- "lts/*"
- "9"
- "10"
matrix:
include:
- node_js: "lts/*"
env: TEST_SUITE=format:ci
- node_js: "lts/*"
env: TEST_SUITE=lint
- node_js: "lts/*"
env: TEST_SUITE=coverage
env:

View file

@ -2,12 +2,12 @@ export function prop(object: {}, name: string, f: () => any): void {
Object.defineProperty(object, name, {
configurable: true,
enumerable: true,
get() {
get(): any {
const _value = f.call(this);
this[name] = _value;
return _value;
},
set(_value) {
set(_value: any): void {
Object.defineProperty(this, name, {
configurable: true,
enumerable: true,

View file

@ -28,7 +28,7 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
throw new TypeError('Not enough data');
opts = Object.assign({ validate: true }, opts || {});
function isAcceptableSignature(x: Buffer | number) {
function isAcceptableSignature(x: Buffer | number): boolean {
return (
bscript.isCanonicalScriptSignature(x as Buffer) ||
(opts!.allowIncomplete && (x as number) === OPS.OP_0) !== undefined

View file

@ -26,7 +26,7 @@ function isPushOnlyChunk(value: number | Buffer): boolean {
return types.Buffer(value) || isOPInt(value as number);
}
export function isPushOnly(value: Stack) {
export function isPushOnly(value: Stack): boolean {
return types.Array(value) && value.every(isPushOnlyChunk);
}

View file

@ -26,6 +26,6 @@ export function check(
bscript.isCanonicalScriptSignature,
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'multisig input';
};

View file

@ -28,6 +28,6 @@ export function check(
const keys = chunks.slice(1, -2) as Buffer[];
return keys.every(bscript.isCanonicalPubKey);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'multi-sig output';
};

View file

@ -7,7 +7,7 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length > 1 && buffer[0] === OPS.OP_RETURN;
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'null data output';
};

View file

@ -11,6 +11,6 @@ export function check(script: Buffer | Stack): boolean {
bscript.isCanonicalScriptSignature(chunks[0] as Buffer)
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'pubKey input';
};

View file

@ -13,6 +13,6 @@ export function check(script: Buffer | Stack): boolean {
chunks[1] === OPS.OP_CHECKSIG
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'pubKey output';
};

View file

@ -12,6 +12,6 @@ export function check(script: Buffer | Stack): boolean {
bscript.isCanonicalPubKey(chunks[1] as Buffer)
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'pubKeyHash input';
};

View file

@ -15,6 +15,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
buffer[24] === OPS.OP_CHECKSIG
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'pubKeyHash output';
};

View file

@ -56,6 +56,6 @@ export function check(
return false;
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'scriptHash input';
};

View file

@ -13,6 +13,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
buffer[22] === OPS.OP_EQUAL
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'scriptHash output';
};

View file

@ -19,7 +19,7 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'Witness commitment output';
};

View file

@ -16,6 +16,6 @@ export function check(script: Buffer | Stack): boolean {
isCompressedCanonicalPubKey(chunks[1] as Buffer)
);
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'witnessPubKeyHash input';
};

View file

@ -8,6 +8,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length === 22 && buffer[0] === OPS.OP_0 && buffer[1] === 0x14;
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'Witness pubKeyHash output';
};

View file

@ -42,6 +42,6 @@ export function check(chunks: Buffer[], allowIncomplete?: boolean): boolean {
return false;
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'witnessScriptHash input';
};

View file

@ -8,6 +8,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length === 34 && buffer[0] === OPS.OP_0 && buffer[1] === 0x20;
}
check.toJSON = () => {
check.toJSON = (): string => {
return 'Witness scriptHash output';
};

View file

@ -497,17 +497,17 @@ export class Transaction {
return this.__toBuffer(buffer, initialOffset, true);
}
toHex() {
toHex(): string {
return this.toBuffer(undefined, undefined).toString('hex');
}
setInputScript(index: number, scriptSig: Buffer) {
setInputScript(index: number, scriptSig: Buffer): void {
typeforce(types.tuple(types.Number, types.Buffer), arguments);
this.ins[index].script = scriptSig;
}
setWitness(index: number, witness: Buffer[]) {
setWitness(index: number, witness: Buffer[]): void {
typeforce(types.tuple(types.Number, [types.Buffer]), arguments);
this.ins[index].witness = witness;
@ -548,33 +548,33 @@ export class Transaction {
offset += slice.copy(buffer!, offset);
}
function writeUInt8(i: number) {
function writeUInt8(i: number): void {
offset = buffer!.writeUInt8(i, offset);
}
function writeUInt32(i: number) {
function writeUInt32(i: number): void {
offset = buffer!.writeUInt32LE(i, offset);
}
function writeInt32(i: number) {
function writeInt32(i: number): void {
offset = buffer!.writeInt32LE(i, offset);
}
function writeUInt64(i: number) {
function writeUInt64(i: number): void {
offset = bufferutils.writeUInt64LE(buffer!, i, offset);
}
function writeVarInt(i: number) {
function writeVarInt(i: number): void {
varuint.encode(i, buffer, offset);
offset += varuint.encode.bytes;
}
function writeVarSlice(slice: Buffer) {
function writeVarSlice(slice: Buffer): void {
writeVarInt(slice.length);
writeSlice(slice);
}
function writeVector(vector: Buffer[]) {
function writeVector(vector: Buffer[]): void {
writeVarInt(vector.length);
vector.forEach(writeVarSlice);
}

View file

@ -192,7 +192,7 @@ export class TransactionBuilder {
hashType: number,
witnessValue: number,
witnessScript: Buffer,
) {
): void {
// TODO: remove keyPair.network matching in 4.0.0
if (keyPair.network && keyPair.network !== this.network)
throw new TypeError('Inconsistent network');

View file

@ -8,7 +8,7 @@ export function UInt31(value: number): boolean {
export function BIP32Path(value: string): boolean {
return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/);
}
BIP32Path.toJSON = () => {
BIP32Path.toJSON = (): string => {
return 'BIP32 derivation path';
};

View file

@ -22,6 +22,12 @@
"no-unused-expression": false,
"object-literal-sort-keys": false,
"quotemark": [true, "single"],
"typedef": [
true,
"call-signature",
"arrow-call-signature",
"property-declaration"
],
"variable-name": [
true,
"ban-keywords",