Skip to content

Commit

Permalink
Run the linter that has always been there...
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 15, 2023
1 parent c5c34ec commit bd4849f
Show file tree
Hide file tree
Showing 52 changed files with 641 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:node/recommended'],
rules: {
'node/no-unpublished-require': 0,
'indent': ['warn', 2]
indent: ['warn', 2]
}
};
12 changes: 4 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
module.exports = function (api) {
api.cache(true)
api.cache(true);
return {
presets: [
[
'@babel/preset-env',
{
targets: {
'browsers': [
'> 2%',
'not ie 11',
'not op_mini all'
]
browsers: ['> 2%', 'not ie 11', 'not op_mini all']
}
}
]
]
}
}
};
};
5 changes: 4 additions & 1 deletion examples/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as XDR from '../src';
let xdr = XDR.config((xdr) => {
xdr.union('Result', {
switchOn: xdr.lookup('ResultType'),
switches: [['ok', xdr.void()], ['error', 'message']],
switches: [
['ok', xdr.void()],
['error', 'message']
],
// defaultArm: xdr.void(),
arms: {
message: xdr.string(100)
Expand Down
9 changes: 5 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const webpack = require('webpack')
const webpack = require('webpack');

module.exports = function (config) {
config.set({
Expand All @@ -16,13 +16,14 @@ module.exports = function (config) {
mode: 'development',
module: {
rules: [
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' }
]
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
})]
Buffer: ['buffer', 'Buffer']
})
]
},

webpackMiddleware: {
Expand Down
6 changes: 3 additions & 3 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
arrowParens: "always",
arrowParens: 'always',
bracketSpacing: true,
jsxBracketSameLine: false,
printWidth: 80,
proseWrap: "always",
proseWrap: 'always',
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: "none",
trailingComma: 'none',
useTabs: false
};
18 changes: 11 additions & 7 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
es2020: true,
es2022: true
},
parserOptions: {ecmaVersion: 13},
parserOptions: { ecmaVersion: 13 },
extends: ['airbnb-base', 'prettier'],
plugins: ['prettier', 'prefer-import'],
rules: {
Expand All @@ -27,7 +27,7 @@ module.exports = {

// WARN
'prefer-import/prefer-import-over-require': [1],
'no-console': ['warn', {allow: ['assert']}],
'no-console': ['warn', { allow: ['assert'] }],
'no-debugger': 1,
'no-unused-vars': 1,
'arrow-body-style': 1,
Expand All @@ -43,7 +43,7 @@ module.exports = {
'max-classes-per-file': ['warn', 3], // do not block imports from other classes

// ERROR
'no-unused-expressions': [2, {allowTaggedTemplates: true}],
'no-unused-expressions': [2, { allowTaggedTemplates: true }],

// we're redefining this without the Math.pow restriction
// (since we don't want to manually add support for it)
Expand Down Expand Up @@ -94,19 +94,23 @@ module.exports = {
message: 'Please use Object.defineProperty instead.'
}
],
'no-restricted-syntax': [ // override basic rule to allow ForOfStatement
'no-restricted-syntax': [
// override basic rule to allow ForOfStatement
'error',
{
selector: 'ForInStatement',
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.'
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.'
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.'
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions src/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class Array extends XdrCompositeType {
throw new XdrWriterError(`value is not array`);

if (value.length !== this._length)
throw new XdrWriterError(`got array of size ${value.length}, expected ${this._length}`);
throw new XdrWriterError(
`got array of size ${value.length}, expected ${this._length}`
);

for (const child of value) {
this._childType.write(child, writer);
Expand All @@ -45,8 +47,7 @@ export class Array extends XdrCompositeType {
}

for (const child of value) {
if (!this._childType.isValid(child))
return false;
if (!this._childType.isValid(child)) return false;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ export class Bool extends XdrPrimitiveType {
static isValid(value) {
return typeof value === 'boolean';
}
}
}
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,4 @@ export function config(fn, types = {}) {
}

return types;
}
}
3 changes: 1 addition & 2 deletions src/double.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export class Double extends XdrPrimitiveType {
* @inheritDoc
*/
static write(value, writer) {
if (typeof value !== 'number')
throw new XdrWriterError('not a number');
if (typeof value !== 'number') throw new XdrWriterError('not a number');

writer.writeDoubleBE(value);
}
Expand Down
15 changes: 9 additions & 6 deletions src/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class Enum extends XdrPrimitiveType {
const intVal = Int.read(reader);
const res = this._byValue[intVal];
if (res === undefined)
throw new XdrReaderError(`unknown ${this.enumName} member for value ${intVal}`);
throw new XdrReaderError(
`unknown ${this.enumName} member for value ${intVal}`
);
return res;
}

Expand Down Expand Up @@ -57,13 +59,14 @@ export class Enum extends XdrPrimitiveType {
static fromValue(value) {
const result = this._byValue[value];
if (result === undefined)
throw new TypeError(`${value} is not a value of any member of ${this.enumName}`);
return result;
throw new TypeError(
`${value} is not a value of any member of ${this.enumName}`
);
return result;
}

static create(context, name, members) {
const ChildEnum = class extends Enum {
};
const ChildEnum = class extends Enum {};

ChildEnum.enumName = name;
context.results[name] = ChildEnum;
Expand All @@ -80,4 +83,4 @@ export class Enum extends XdrPrimitiveType {

return ChildEnum;
}
}
}
6 changes: 4 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class XdrDefinitionError extends TypeError {

export class XdrNotImplementedDefinitionError extends XdrDefinitionError {
constructor() {
super(`method not implemented, it should be overloaded in the descendant class.`);
super(
`method not implemented, it should be overloaded in the descendant class.`
);
}
}
}
3 changes: 1 addition & 2 deletions src/float.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export class Float extends XdrPrimitiveType {
* @inheritDoc
*/
static write(value, writer) {
if (typeof value !== 'number')
throw new XdrWriterError('not a number');
if (typeof value !== 'number') throw new XdrWriterError('not a number');

writer.writeFloatBE(value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hyper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Hyper extends LargeInt {
}

get low() {
return Number(this._value & 0xFFFFFFFFn) << 0;
return Number(this._value & 0xffffffffn) << 0;
}

get high() {
Expand Down
6 changes: 2 additions & 4 deletions src/int.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export class Int extends XdrPrimitiveType {
* @inheritDoc
*/
static write(value, writer) {
if (typeof value !== 'number')
throw new XdrWriterError('not a number');
if (typeof value !== 'number') throw new XdrWriterError('not a number');

if ((value | 0) !== value)
throw new XdrWriterError('invalid i32 value');
if ((value | 0) !== value) throw new XdrWriterError('invalid i32 value');

writer.writeInt32BE(value);
}
Expand Down
36 changes: 25 additions & 11 deletions src/large-int.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { XdrPrimitiveType } from './xdr-type';
import { calculateBigIntBoundaries, encodeBigIntFromBits, sliceBigInt } from './bigint-encoder';
import {
calculateBigIntBoundaries,
encodeBigIntFromBits,
sliceBigInt
} from './bigint-encoder';
import { XdrNotImplementedDefinitionError, XdrWriterError } from './errors';

export class LargeInt extends XdrPrimitiveType {
Expand Down Expand Up @@ -43,7 +47,7 @@ export class LargeInt extends XdrPrimitiveType {
}

toJSON() {
return {_value: this._value.toString()}
return { _value: this._value.toString() };
}

toBigInt() {
Expand All @@ -54,10 +58,13 @@ export class LargeInt extends XdrPrimitiveType {
* @inheritDoc
*/
static read(reader) {
const {size} = this.prototype;
if (size === 64)
return new this(reader.readBigUInt64BE());
return new this(...Array.from({length: size / 64}, () => reader.readBigUInt64BE()).reverse());
const { size } = this.prototype;
if (size === 64) return new this(reader.readBigUInt64BE());
return new this(
...Array.from({ length: size / 64 }, () =>
reader.readBigUInt64BE()
).reverse()
);
}

/**
Expand All @@ -66,10 +73,14 @@ export class LargeInt extends XdrPrimitiveType {
static write(value, writer) {
if (value instanceof this) {
value = value._value;
} else if (typeof value !== 'bigint' || value > this.MAX_VALUE || value < this.MIN_VALUE)
} else if (
typeof value !== 'bigint' ||
value > this.MAX_VALUE ||
value < this.MIN_VALUE
)
throw new XdrWriterError(`${value} is not a ${this.name}`);

const {unsigned, size} = this.prototype;
const { unsigned, size } = this.prototype;
if (size === 64) {
if (unsigned) {
writer.writeBigUInt64BE(value);
Expand All @@ -91,7 +102,7 @@ export class LargeInt extends XdrPrimitiveType {
* @inheritDoc
*/
static isValid(value) {
return typeof value === 'bigint' || (value instanceof this);
return typeof value === 'bigint' || value instanceof this;
}

/**
Expand All @@ -112,8 +123,11 @@ export class LargeInt extends XdrPrimitiveType {
* @return {void}
*/
static defineIntBoundaries() {
const [min, max] = calculateBigIntBoundaries(this.prototype.size, this.prototype.unsigned);
const [min, max] = calculateBigIntBoundaries(
this.prototype.size,
this.prototype.unsigned
);
this.MIN_VALUE = min;
this.MAX_VALUE = max;
}
}
}
6 changes: 4 additions & 2 deletions src/opaque.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export class Opaque extends XdrCompositeType {
* @inheritDoc
*/
write(value, writer) {
const {length} = value;
const { length } = value;
if (length !== this._length)
throw new XdrWriterError(`got ${value.length} bytes, expected ${this._length}`);
throw new XdrWriterError(
`got ${value.length} bytes, expected ${this._length}`
);
writer.write(value, length);
}

Expand Down
2 changes: 1 addition & 1 deletion src/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export class Option extends XdrPrimitiveType {
}
return this._childType.isValid(value);
}
}
}
4 changes: 3 additions & 1 deletion src/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { XdrDefinitionError } from './errors';
export class Reference extends XdrPrimitiveType {
/* jshint unused: false */
resolve() {
throw new XdrDefinitionError('"resolve" method should be implemented in the descendant class');
throw new XdrDefinitionError(
'"resolve" method should be implemented in the descendant class'
);
}
}
Loading

0 comments on commit bd4849f

Please sign in to comment.