Skip to content

Commit

Permalink
Update dependencies, replace tslint with eslint, migrate to pnpm (#259)
Browse files Browse the repository at this point in the history
* chore: remove unused dependencies

* chore: upgrade ts to 5.5.0

* fix dtslint errors

* use `typescript-eslint` and `eslint-plugin-expect-type` instead of `dtslint`, `tslint`

* migrate to pnpm

* chore: add comment about eslint-plugin-expect-type

* chore: rm tslint from vscode extension recommendations
  • Loading branch information
DiamondMofeng authored Jul 20, 2024
1 parent 5a93dc1 commit 89807e5
Show file tree
Hide file tree
Showing 20 changed files with 1,599 additions and 6,630 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
- [ ] Test passed
- [ ] Coding style (indentation, etc)
- [ ] Edits have been made to `src/` files not `index.d.ts`
- [ ] Run `npm run dtslint` to update `index.d.ts`
- [ ] Run `npm run compile` to update `index.d.ts`
33 changes: 16 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@ name: CI
on:
pull_request:
push:
branches: [ "master" ]
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8

- name: Install dependencies
run: npm ci
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Lint
run: npm run lint:test

# this has been covered in the prepare script

# - name: Dtslint test
# run: npm run test
- name: Install dependencies
run: pnpm i

- name: Lint
run: pnpm lint
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node_modules/
.editorconfig
.gitattributes
tsconfig.json
tslint.json
eslint.config.*

src/
dist/screeps.ts
Expand Down
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["ms-vscode.vscode-typescript-tslint-plugin", "EditorConfig.EditorConfig", "esbenp.prettier-vscode"]
"recommendations": [
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
]
}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.rulers": [140],
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ npm install @types/screeps

# yarn
yarn add @types/screeps

# pnpm
pnpm add @types/screeps
```

## Differences from **[Screeps-Typescript-Declarations](https://github.com/screepers/Screeps-Typescript-Declarations)**
Expand Down
2 changes: 1 addition & 1 deletion build/header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
// Kieran Carnegie <https://github.com/kotarou>
// Mofeng <https://github.com/DiamondMofeng>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 4.6
// TypeScript Version: 5.5

// Please contribute types to https://github.com/screepers/typed-screeps
8 changes: 8 additions & 0 deletions dist/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"@definitelytyped/no-any-union": "off",
"@definitelytyped/no-unnecessary-generics": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-misused-new": "off"
}
}
5 changes: 1 addition & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Kieran Carnegie <https://github.com/kotarou>
// Mofeng <https://github.com/DiamondMofeng>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 4.6
// TypeScript Version: 5.5

// Please contribute types to https://github.com/screepers/typed-screeps

Expand Down Expand Up @@ -1919,7 +1919,6 @@ interface FindPathOpts {
* @param costMatrix The current CostMatrix
* @returns The new CostMatrix to use
*/
// tslint:disable-next-line: invalid-void
costCallback?: (roomName: string, costMatrix: CostMatrix) => void | CostMatrix;

/**
Expand Down Expand Up @@ -2739,8 +2738,6 @@ type PowerConstant =
| PWR_OPERATE_EXTENSION
| PWR_OPERATE_OBSERVER
| PWR_OPERATE_TERMINAL
| PWR_OPERATE_SPAWN
| PWR_OPERATE_TOWER
| PWR_DISRUPT_SPAWN
| PWR_DISRUPT_TOWER
| PWR_DISRUPT_SOURCE
Expand Down
22 changes: 6 additions & 16 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// If you open this file and see no red squiggly lines, then you're good!
// Feel free to add more test cases in the form of a sample code.

// `$ExpectType` is supported by the linter, you can use it to check the type of an expression or a variable.
// See https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type for more details.

// TODO: add more test cases.

// Sample inputs
Expand Down Expand Up @@ -237,7 +240,6 @@ function resources(o: GenericStore): ResourceConstant[] {
{
const exits = Game.map.describeExits("W8N3");
if (exits) {
// tslint:disable-next-line:newline-per-chained-call
keys(exits).map((exitKey) => {
const nextRoom = exits[exitKey];
const exitDir = +exitKey as ExitConstant;
Expand Down Expand Up @@ -304,7 +306,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const parsed = /^[WE]([0-9]+)[NS]([0-9]+)$/.exec(roomName);
if (parsed !== null) {
const isHighway = parseInt(parsed[1], 10) % 10 === 0 || parseInt(parsed[2], 10) % 10 === 0;
const isMyRoom = Game.rooms[roomName] && Game.rooms[roomName].controller && Game.rooms[roomName].controller!.my;
const isMyRoom = Game.rooms[roomName] && Game.rooms[roomName].controller && Game.rooms[roomName].controller?.my;
if (isHighway || isMyRoom) {
return 1;
} else {
Expand Down Expand Up @@ -451,7 +453,6 @@ function resources(o: GenericStore): ResourceConstant[] {
{
const pfCreep = Game.creeps.John;

// tslint:disable-next-line:newline-per-chained-call
const goals = pfCreep.room.find(FIND_SOURCES).map((source) => {
// We can't actually walk on sources-- set `range` to 1
// so we path next to it.
Expand All @@ -474,7 +475,6 @@ function resources(o: GenericStore): ResourceConstant[] {
}
const costs = new PathFinder.CostMatrix();

// tslint:disable-next-line:newline-per-chained-call
curRoom.find(FIND_STRUCTURES).forEach((struct) => {
if (struct.structureType === STRUCTURE_ROAD) {
// Favor roads over plain tiles
Expand All @@ -489,7 +489,6 @@ function resources(o: GenericStore): ResourceConstant[] {
});

// Avoid creeps in the room
// tslint:disable-next-line:newline-per-chained-call
curRoom.find(FIND_CREEPS).forEach((thisCreep) => {
costs.set(thisCreep.pos.x, thisCreep.pos.y, 0xff);
});
Expand Down Expand Up @@ -539,7 +538,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const interShardData = JSON.parse(RawMemory.interShardSegment);
if (interShardData.creeps[creep.name]) {
creep.memory = interShardData[creep.name];
delete interShardData.creeps[creep.name]; // tslint:disable-line no-dynamic-delete
delete interShardData.creeps[creep.name];
}
RawMemory.interShardSegment = JSON.stringify(interShardData);

Expand Down Expand Up @@ -658,7 +657,6 @@ function resources(o: GenericStore): ResourceConstant[] {

const tower = creep.pos.findClosestByPath<StructureTower>(FIND_HOSTILE_STRUCTURES, {
// ? s should be AnyOwnedStructure in the future
// $ExpectType (structure: AnyStructure) => boolean
filter: (structure) => {
return structure.structureType === STRUCTURE_TOWER;
},
Expand Down Expand Up @@ -697,7 +695,6 @@ function resources(o: GenericStore): ResourceConstant[] {

const rampart = creep.pos.findClosestByRange<StructureRampart>(FIND_HOSTILE_STRUCTURES, {
// ? s should be AnyOwnedStructure in the future
// $ExpectType (structure: AnyStructure) => boolean
filter: (structure) => {
return structure.structureType === STRUCTURE_RAMPART;
},
Expand All @@ -706,13 +703,12 @@ function resources(o: GenericStore): ResourceConstant[] {
rampart.isPublic;
}

// Should have type Creep[]
// $ExpectType Creep[]
const hostileCreeps = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 10);
hostileCreeps[0].saying;

const labs = creep.pos.findInRange<StructureLab>(FIND_MY_STRUCTURES, 4, {
// ? s should be AnyOwnedStructure in the future
// $ExpectType (structure: AnyStructure) => boolean
filter: (structure) => {
return structure.structureType === STRUCTURE_LAB;
},
Expand All @@ -722,32 +718,26 @@ function resources(o: GenericStore): ResourceConstant[] {

// Should be able to automatically infer the type of params in the filter function
creep.pos.findClosestByPath(FIND_STRUCTURES, {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

creep.pos.findClosestByPath([] as AnyStructure[], {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

creep.pos.findClosestByRange(FIND_STRUCTURES, {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

creep.pos.findClosestByRange([] as AnyStructure[], {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

creep.pos.findInRange(FIND_STRUCTURES, 10, {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

creep.pos.findInRange([] as AnyStructure[], 10, {
// $ExpectType (s: AnyStructure) => boolean
filter: (s) => s.structureType === STRUCTURE_EXTENSION,
});

Expand Down
14 changes: 0 additions & 14 deletions dist/tslint.json

This file was deleted.

25 changes: 25 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-check
import tseslint, { parser } from 'typescript-eslint';
import expectType from "eslint-plugin-expect-type/configs/recommended";

export const sharedOpts = tseslint.config(
tseslint.configs.base,
expectType,
// global ignore
{ ignores: ["build/*", "eslint.config.*"], },
);

export default tseslint.config(
...sharedOpts,
{ files: ['src/**/*.ts', 'dist/screeps-tests.ts'], },
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
parserOptions: {
parser: parser,
project: ["./tsconfig.json", './dist/tsconfig.json'],
},
},
},
)
19 changes: 19 additions & 0 deletions eslint.config.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check
// only used for 'dist/screeps-tests.ts'
import tseslint, { parser } from 'typescript-eslint';
import { sharedOpts } from "./eslint.config.mjs";

export default tseslint.config(
...sharedOpts,
{ files: ['dist/screeps-tests.ts'], },
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
parserOptions: {
parser: parser,
project: ['./dist/tsconfig.json'],
},
},
},
)
Loading

0 comments on commit 89807e5

Please sign in to comment.