Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
update typescript/lint config and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Dec 14, 2021
1 parent 672af9a commit 5c25589
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'guard-for-in': 'off',
'prefer-rest-params': 'off',
Expand Down
12 changes: 11 additions & 1 deletion src/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export function nameWithProperty(name: string, lo: { property?: string }): strin
* @param {Layout} layout - the {@link Layout} instance used to encode
* instances of `Class`.
*/
// `Class` must be a constructor Function, but the assignment of a `layout_` property to it makes it difficult to type
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function bindConstructorLayout<T>(Class: any, layout: Layout<T>): void {
if ('function' !== typeof Class) {
throw new TypeError('Class must be constructor');
Expand Down Expand Up @@ -1424,6 +1426,8 @@ export class UnionLayoutDiscriminator extends UnionDiscriminator<number> {
* @augments {Layout}
*/
export class Union extends Layout<LayoutObject> {
// `property` is assigned in the Layout constructor
// @ts-ignore
property: string;
discriminator: UnionDiscriminator;
usesPrefixDiscriminator: boolean;
Expand Down Expand Up @@ -1644,6 +1648,8 @@ export class Union extends Layout<LayoutObject> {
}
dest = this.makeDestinationObject();
dest[dlo.property] = discr;
// defaultLayout.property can be undefined, but this is allowed by buffer-layout
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dest[defaultLayout!.property!] = defaultLayout!.decode(b, offset + contentOffset);
} else {
dest = clo.decode(b, offset);
Expand All @@ -1662,13 +1668,15 @@ export class Union extends Layout<LayoutObject> {
if (undefined === vlo) {
const dlo = this.discriminator;
// this.defaultLayout is not undefined when vlo is undefined
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const clo = this.defaultLayout!;
let contentOffset = 0;
if (this.usesPrefixDiscriminator) {
contentOffset = (dlo as UnionLayoutDiscriminator).layout.span;
}
dlo.encode(src[dlo.property], b, offset);
// clo.property is not undefined when vlo is undefined
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return contentOffset + clo.encode(src[clo.property!], b, offset + contentOffset);
}
return vlo.encode(src, b, offset);
Expand Down Expand Up @@ -1748,6 +1756,8 @@ export class Union extends Layout<LayoutObject> {
* @augments {Layout}
*/
export class VariantLayout extends Layout<LayoutObject> {
// `property` is assigned in the Layout constructor
// @ts-ignore
property: string;
union: Union;
variant: number;
Expand Down Expand Up @@ -2029,10 +2039,10 @@ export class BitStructure extends Layout<LayoutObject> {
* Layout#property|property}.
*
* @return {Boolean} */
// `Boolean` conflicts with the native primitive type
// eslint-disable-next-line @typescript-eslint/ban-types
addBoolean(property: string): Boolean {
// This is my Boolean, not the Javascript one.
// eslint-disable-next-line no-new-wrappers
const bf = new Boolean(this, property);
this.fields.push(bf);
return bf;
Expand Down
20 changes: 12 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"outDir": "lib",
"declaration": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"sourceMap": true,
"strictNullChecks": true,
"outDir": "lib",
"noEmitOnError": true,
"stripInternal": true,
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2020"],
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src"],
"exclude": ["node_modules", "**/*.spec.ts"]
"exclude": ["node_modules"]
}

0 comments on commit 5c25589

Please sign in to comment.