Skip to content

Commit

Permalink
fix: 修复 lint 错误
Browse files Browse the repository at this point in the history
  • Loading branch information
LokiSharp committed Oct 9, 2023
1 parent b21f2e2 commit d9c445b
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extends:
- "plugin:@typescript-eslint/recommended"
- "plugin:@typescript-eslint/recommended-requiring-type-checking"
- "plugin:prettier/recommended"
- "prettier/@typescript-eslint"
- "prettier"
- "plugin:import/errors"
- "plugin:import/warnings"
- "plugin:import/typescript"
Expand All @@ -34,6 +34,7 @@ rules:
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/space-within-parens": ["off", "never"],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/no-unused-vars": "warn",
"arrow-parens": ["off", "as-needed"],
camelcase: "error",
complexity: "off",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [windows-2019]
node-version: [10.x, 12.x]
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]

runs-on: ${{ matrix.os }}

Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://github.com/LokiSharp/ScreepsScript#readme",
"engines": {
"node": "10.x || 12.x"
"node": "10.x || 12.x || 14.x || 16.x || 18.x"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
Expand All @@ -47,23 +47,23 @@
"@types/lodash": "3.10.2",
"@types/node": "^14.14.10",
"@types/screeps": "^3.3.4",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"@typescript-eslint/typescript-estree": "^4.9.0",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"@typescript-eslint/typescript-estree": "^6.7.4",
"commitizen": "^4.2.2",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "3.3.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-deprecation": "^1.2.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-prettier": "^5.0.0",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"jest-environment-jsdom-fifteen": "^1.0.2",
"lodash": "^3.10.1",
"prettier": "^2.2.1",
"prettier": "^3.0.3",
"rollup": "^2.34.2",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-clear": "^2.0.7",
Expand All @@ -79,12 +79,14 @@
"dependencies": {
"source-map": "~0.6.1"
},
"resolutions": {
"screeps-server-mockup/**/isolated-vm": "^4.6.0",
"screeps-server-mockup/**/nan": "^2.18.0",
"screeps-server-mockup/**/node-gyp": "^9.4.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"volta": {
"node": "10.24.0"
}
}
3 changes: 2 additions & 1 deletion src/modules/framework/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class App {
next();
} catch (e) {
console.log(`<span style="color:#ef9a9a">${e as string}</sapn>`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Game.notify(e);
}
};
Expand Down Expand Up @@ -201,7 +202,7 @@ export default class App {
* @param gameItem 要调用入口方法的游戏对象
*/
private doWithCatcher(gameItem): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
this._catcher(gameItem[MOUNT_ENTRY_FUNCTION].bind(gameItem));
}
}
1 change: 1 addition & 0 deletions src/modules/room/RoomAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class RoomAccessor<MemoryType> {
// 房间内存不存在,使用默认内存
if (!Game.rooms[this.roomName].memory[this.memoryKey]) this._memory = this.defaultMemory;
// 存在,使用 memory 中的数据
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
else this._memory = JSON.parse(Game.rooms[this.roomName].memory[this.memoryKey]) as MemoryType;

return this._memory;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/room/power/taskHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const PowerTasks: PowerTaskConfigs = {
if (creep.store[RESOURCE_OPS] < POWER_INFO[PWR_OPERATE_EXTENSION].ops) return ERR_NOT_ENOUGH_RESOURCES;

// 获取能量来源
let sourceStructure;
let sourceStructure: RoomObject;
// 只有 storage 的话就用 storage
if (creep.room.storage && !creep.room.terminal) sourceStructure = creep.room.storage;
// 两个都存在的话就比较那个能量多
Expand Down
1 change: 1 addition & 0 deletions src/modules/room/shortcut/centerLinkGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import { getStructureWithMemory } from "./getStructureWithMemory";
* 中央 link 访问器
*/
export function centerLinkGetter(): StructureLink {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return getStructureWithMemory<StructureLink>(this, "centerLinkCache", "centerLinkId");
}
3 changes: 2 additions & 1 deletion src/modules/room/shortcut/getStructureWithMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export function getStructureWithMemory<TargetStructure extends ObjectWithId>(
if (!room.memory[memoryKey]) return undefined;

// 从 id 获取建筑并缓存
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,
const target: TargetStructure = Game.getObjectById(room.memory[memoryKey]);

// 如果保存的 id 失效的话,就移除缓存
Expand Down
1 change: 1 addition & 0 deletions src/modules/room/shortcut/setShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function setShortcut(isSingle: boolean) {
return (type: AllRoomShortcut): void => {
Object.defineProperty(Room.prototype, type, {
get() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const structures = getStructureWithCache(this, type);
return isSingle ? structures[0] : structures;
},
Expand Down
1 change: 1 addition & 0 deletions src/modules/room/spawn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class RoomSpawnController extends RoomAccessor<SpawnTask[]> {
* @param task 新的孵化任务
* @returns 当前任务在队列中的排名
*/
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
public addTask(task: SpawnTask): number | ERR_NAME_EXISTS {
// 先检查下任务是不是已经在队列里了
if (!this.hasTask(task.name)) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/creep/calcBodyPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export default function calcBodyPart(bodySet: BodySet): BodyPartConstant[] {
// 把身体配置项拓展成如下形式的二维数组
// [ [ TOUGH ], [ WORK, WORK ], [ MOVE, MOVE, MOVE ] ]
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const bodys = Object.keys(bodySet).map(type => Array(bodySet[type]).fill(type) as BodySet[]);
// 把二维数组展平
return [].concat(...bodys) as BodyPartConstant[];
Expand Down
5 changes: 2 additions & 3 deletions src/utils/creep/createBodyGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ export default function createBodyGetter(
.find(level => {
// 先通过等级粗略判断,再加上 dryRun 精确验证
const availableEnergyCheck = Number(level) <= room.energyAvailable;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const dryCheck = spawn.spawnCreep(bodyConfig[level], "bodyTester", { dryRun: true }) === OK;

return availableEnergyCheck && dryCheck;
});
if (!targetLevel) return [];

// 获取身体部件
const bodys: BodyPartConstant[] = bodyConfig[targetLevel as EnergyLevel];

return bodys;
return bodyConfig[targetLevel as EnergyLevel];
};
}
4 changes: 2 additions & 2 deletions src/utils/global/ErrorMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { SourceMapConsumer } from "source-map";
import colorful from "@/utils/console/colorful";

// 缓存 SourceMap
let consumer = null;
let consumer: SourceMapConsumer = null;

// 第一次报错时创建 sourceMap
const getConsumer = function (): SourceMapConsumer {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-var-requires
if (consumer == null) consumer = new SourceMapConsumer(require("main.js.map"));
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return consumer;
};

Expand Down

0 comments on commit d9c445b

Please sign in to comment.