Skip to content

Commit

Permalink
use typescript-eslint and eslint-plugin-expect-type instead of `d…
Browse files Browse the repository at this point in the history
…tslint`, `tslint`
  • Loading branch information
DiamondMofeng committed Jul 19, 2024
1 parent a70e203 commit e9f15db
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 60 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ jobs:
cache: "npm"

- name: Install dependencies
run: npm ci
run: npm i

- name: Lint
run: npm run lint:test

# this has been covered in the prepare script

# - name: Dtslint test
# run: npm run test
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
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"
}
}
1 change: 0 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
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
6 changes: 1 addition & 5 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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 @@ -451,7 +450,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 +472,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 +486,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 +535,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
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'],
},
},
},
)
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
"dist/index.d.ts"
],
"scripts": {
"compile:dtslint": "node ./build/concat.js && node ./build/prependHeader.js",
"compile": "npm run compile:dtslint && node ./build/prependDescription.js",
"dtslint": "npm run compile:dtslint && dtslint dist",
"compile": "node ./build/concat.js && node ./build/prependHeader.js && node ./build/prependDescription.js",
"format": "npm run format:build && npm run format:src",
"format:build": "prettier --write 'build/**/*.js'",
"format:src": "prettier --write 'src/**/*.ts'",
"lint": "tslint -p tsconfig.json 'src/**/*.ts'",
"lint:test": "tslint -p dist/tsconfig.json dist/screeps-tests.ts",
"lint": "eslint -c eslint.config.mjs",
"lint:test": "eslint -c eslint.config.test.mjs dist/screeps-tests.ts",
"pre-commit": "npm run compile && git add dist/index.d.ts",
"prepare": "husky install && npm test",
"test": "npm run dtslint"
"prepare": "husky install && npm test"
},
"keywords": [
"Screeps",
Expand All @@ -29,15 +26,13 @@
"author": "Marko Sulamagi <[email protected]>",
"license": "MIT",
"devDependencies": {
"@definitelytyped/dtslint": "^0.0.111",
"eslint": "^9.7.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.8",
"prepend": "^1.0.2",
"prettier": "^2.6.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^5.5.0"
"typescript": "^5.5.0",
"typescript-eslint": "^7.16.1"
},
"lint-staged": {
"*.{ts,tsx}": [
Expand Down
1 change: 0 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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
2 changes: 0 additions & 2 deletions src/literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,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
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"newLine": "LF",
"removeComments": false
},
"include": ["./src/**/*.ts"],
"exclude": ["node_modules", "dist"]
"include": [
"./src/**/*.ts"
],
"exclude": [
"node_modules",
"dist",
],
}
15 changes: 0 additions & 15 deletions tslint.json

This file was deleted.

0 comments on commit e9f15db

Please sign in to comment.