Skip to content

Commit

Permalink
fix(various): Upgrade eslint to use typescript-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
vanthome committed Oct 19, 2024
1 parent 4917199 commit 8a9ce59
Show file tree
Hide file tree
Showing 47 changed files with 4,971 additions and 7,209 deletions.
11,338 changes: 4,537 additions & 6,801 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"homepage": "https://github.com/restorecommerce/libs#readme",
"devDependencies": {
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.1",
"typescript-eslint": "8.10.0",
"cz-conventional-changelog": "^3.3.0",
"@eslint/js": "^9.12.0",
"eslint": "^9.12.0",
"@eslint/js": "9.13.0",
"eslint": "9.13.0",
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
"lerna": "^8.1.8",
"nx": "20.0.0",
"nx": "20.0.3",
"tar": "^7.4.3"
},
"workspaces": [
Expand Down
19 changes: 11 additions & 8 deletions packages/acs-client/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"compilerOptions": {
"outDir": "test"
},
"extends": "./tsconfig.json",
"include": [
"./test/**/*.ts"
]
}
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "test"
},
"types": [
"@types/jest"
],
"include": [
"test/**/*.ts"
]
}
22 changes: 22 additions & 0 deletions packages/cart/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

import eslint from '@eslint/js';
import { RuleTester } from 'eslint';
import tseslint from 'typescript-eslint';

const rules = tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);

rules.push(
{
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"prefer-rest-params": "off",
}
}
);

export default rules;
27 changes: 13 additions & 14 deletions packages/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@
"store": "^2.0.12"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/node": "^20.8.2",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.4",
"@types/should": "^13.0.0",
"@types/store": "^2.0.5",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/eslint-plugin-tslint": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.50.0",
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
"i18n-iso-countries": "^7.7.0",
"eslint": "^9.12.0",
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
"i18n-iso-countries": "^7.12.0",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"nyc": "^17.1.0",
"should": "^13.2.3",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"ts-jest": "^29.2.5",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.1"
},
"scripts": {
"test": "jest --runInBand --testTimeout=30000",
"lint": "eslint src --ext .ts",
"build:tsc": "tsc -p tsconfig.lib.json",
"build:tsc": "tsc -d",
"build:tsc:watch": "tsc -d --watch",
"build:clean": "rimraf lib",
"build": "npm-run-all lint build:clean build:tsc",
"test": "jest --runInBand --testTimeout=30000",
"lint": "eslint src",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions packages/cart/src/model/impl/Cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Cart implements ICart {
taxes.vat_standard.netPrice = new Decimal(0);
taxes.vat_reduced.netPrice = new Decimal(0);

for (let item of items) {
for (const item of items) {
taxes[item.taxType].netPrice = Decimal.add(taxes[item.taxType].netPrice, Decimal.mul(item.price, typeof item.quantity === 'undefined' ? 1 : item.quantity));
}

Expand All @@ -224,7 +224,7 @@ export class Cart implements ICart {
netPrice: new Decimal('0.00')
};

for (let taxType in taxes) {
for (const taxType in taxes) {
vatFree.netPrice = Decimal.add(vatFree.netPrice, taxes[taxType].netPrice);
}

Expand All @@ -238,8 +238,8 @@ export class Cart implements ICart {

getTotalNet(): Decimal {
let sum = new Decimal(0);
for (let item of this._items) {
let itemNet = Decimal.mul(item.price.toString(), item.quantity.toString());
for (const item of this._items) {
const itemNet = Decimal.mul(item.price.toString(), item.quantity.toString());
sum = Decimal.add(sum, itemNet);
}

Expand All @@ -254,7 +254,7 @@ export class Cart implements ICart {
const taxes = this.getTaxes(true);

let sum = new Decimal(0);
for (let taxType in taxes) {
for (const taxType in taxes) {
const itemGrand = Decimal.mul(taxes[taxType].netPrice.toString(), taxes[taxType].rate.toString());
sum = Decimal.add(sum, itemGrand);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/cart/src/model/impl/LocalSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class LocalSerializer implements ISerializer {
try {
return JSON.parse(str);
} catch (e) {
console.log('Failed to parse', e);
}

return undefined;
Expand All @@ -42,8 +43,8 @@ export class LocalSerializer implements ISerializer {
} else {
if ('_items' in data) {
// Make sure all numerical values are not strings
for (let item of data._items) {
for (let key of numericItemKeys) {
for (const item of data._items) {
for (const key of numericItemKeys) {
if (key in item && typeof(item[key]) != 'number') {
item[key] = parseFloat(item[key].toString());
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cart/src/model/impl/bin/Box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Box extends Dimension {
* @return this instance
*/
public rotate3D(): Box {
let height = this.height;
const height = this.height;

this.height = this.width;
this.width = this.depth;
Expand Down Expand Up @@ -202,7 +202,7 @@ export class Box extends Dimension {
*/

rotate2D(): Box {
let depth = this.depth;
const depth = this.depth;

this.depth = this.width;
this.width = depth;
Expand All @@ -225,7 +225,7 @@ export class Box extends Dimension {
// width -> depth -> width;
// depth -> height;

let depth = this.depth;
const depth = this.depth;

this.depth = this.height;
this.height = depth;
Expand Down
18 changes: 9 additions & 9 deletions packages/cart/src/model/impl/bin/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ export class Container extends Box {
* @return list of containers in all 6 rotations.
*/
rotations(): Container[] {
let result: Container[] = [];
const result: Container[] = [];
let box = this.clone();
let square0 = box.isSquare2D();
const square0 = box.isSquare2D();

result.push(box);

if (!box.isSquare3D()) {

box = box.clone().rotate3D();
let square1 = box.isSquare2D();
const square1 = box.isSquare2D();

result.push(box);

box = box.clone().rotate3D();
let square2 = box.isSquare2D();
const square2 = box.isSquare2D();

result.push(box);

Expand Down Expand Up @@ -114,7 +114,7 @@ export class Container extends Box {
}

addLevel(): Level {
let level = new Level();
const level = new Level();
this.add(level);
return level;
}
Expand All @@ -130,15 +130,15 @@ export class Container extends Box {
if (this.levels.length == 0) {
return this;
}
let remainder = this.height - this.getStackHeight();
const remainder = this.height - this.getStackHeight();
if (remainder < 0) {
throw new Error('Remaining free space is negative at ' + remainder + ' for ' + this);
}
return new Dimension('', this.width, this.depth, remainder);
}

getFreeWeight(): number {
let remainder = this.weight - this.getStackWeight();
const remainder = this.weight - this.getStackWeight();
if (remainder < 0) {
throw new Error('Remaining weight is negative at ' + remainder);
}
Expand Down Expand Up @@ -216,7 +216,7 @@ export class Container extends Box {
}

removeLevel(index: number) {
let level = this.levels.splice(index, 1)[0];
const level = this.levels.splice(index, 1)[0];
if (index != this.levels.length) {
this.stackHeight -= level.getHeight();
this.stackWeight -= level.getWeight();
Expand All @@ -243,7 +243,7 @@ export class Container extends Box {
if (count == limit) {
// see if we can keep the last level
// if so there must be no free space in it
let level = this.levels[i];
const level = this.levels[i];

let v = (this.volume / this.height) * level.getHeight();
for (const p of level) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cart/src/model/impl/bin/Dimension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Dimension {
return this.name;
}

public equals(obj: Object): boolean {
public equals(obj: object): boolean {
if (this == obj)
return true;
if (obj == null)
Expand Down
Loading

0 comments on commit 8a9ce59

Please sign in to comment.