Commit Graph

23 Commits

Author SHA1 Message Date
Slayer95
4b8c6a4d6d
Refactor startup (#11346)
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
This minimizes side effects of import/require across the codebase,
and lets the caller be responsible of initializing child processeses,
as well as other async logic, such as restoring saved battles.
2025-10-17 19:37:47 -07:00
Slayer95
018ea4abef
Support running PS in a single process again (#11331)
Some checks are pending
Node.js CI / build (18.x) (push) Waiting to run
2025-08-07 00:29:18 -07:00
Guangcong Luo
78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00
Mia
5052a2a797 Team-validator: Log userids in debug info 2023-10-03 11:27:39 -05:00
Leonard Craft III
ef1e7fb483 Fix team validator process debug information logging 2023-08-29 20:31:07 -05:00
Mia
3cab566d85 Fix build 2023-06-12 16:08:40 -05:00
Mia
6aa206e6e6 Team-validator: Time out queries that last longer than 2 minutes 2023-06-12 13:21:09 -05:00
Mia
840ad204e4 Team-validator: Reject teams over 25kb raw 2023-06-12 13:17:41 -05:00
Guangcong Luo
13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00
Guangcong Luo
d4b6ba4c0f Allow passing teams to random formats
The team validator will now complain if try to bring a team to a random
format. Also, if you bypass the validator (such as with
`/importinputlog` or using the JS API directly), you can now use custom
teams in random formats.

Fixes #8144
2021-03-29 10:28:00 -07:00
Guangcong Luo
5ace098eb5 Fix validator crash reporting
Validator crashes weren't being reported to the dev room. This fixes that.
2021-01-28 20:35:30 -05:00
Guangcong Luo
c9759954b9 Remove sim/global-variables.d.ts
The sim no longer uses any global variables, so this can and should be
removed.

`server/global-variables` has also been cleaned up, since I'm working
on this.
2020-10-27 22:03:14 +00:00
Guangcong Luo
e8451f8104 Clean up imports
A lot of our code for child processes doesn't really follow our
original standards. This refactors them back to work the way they
were intended to.
2020-10-24 22:12:35 +01:00
Guangcong Luo
3d68248efa Update to latest eslint
We're skipping two major typescript-eslint versions, so there are a
bunch of changes here, including:

- it's catching a lot of things it didn't catch in the past, for
  reasons unclear to me

- no-unused-vars has to be explicitly disabled in global-types now

- a lot of `ts-ignore`s were never necessary and have been fixed

- Crashlogger can now handle being thrown things that aren't errors.
  This has never been a problem in the past, but to satisfy TypeScript
	we might as well not die in a fire on the off chance someone tries to
	`throw null` or something.
2020-09-29 15:28:08 -07:00
Mia
deeed6c789
Remove sim/ and data/'s globals (#7091) 2020-08-07 06:44:15 -07:00
Guangcong Luo
7e5d841739 Improve validator crash phrasing 2020-05-01 13:22:16 -07:00
Guangcong Luo
e091679408 Support Config.debugvalidatorprocesses
Like Config.debugsimprocesses, this can be used to track down queries causing
infinite loops.
2020-04-25 15:55:05 -04:00
Guangcong Luo
125fe31d06 Improve eslintrc
Fixed some more code style, allowing these rules to be enabled:

- `comma-dangle`
- `function-paren-newline`
- `member-delimiter-style`
- `no-eval`
- `no-fallthrough`
- `no-misused-promises`
- `no-unused-vars`
- `operator-linebreak`
2020-03-06 22:35:55 -08:00
Waleed Hassan
8aa4f053bb
Use optional chaining and linter improvements (#6422)
This is mostly just a follow up to #6342.

`prefer-optional-chaining` was turned on and fixed in every location it
complained in. The transformed function [0] looks expensive from a
glance but from skimming through the replaced sites it doesn't appear
to be ran in any important place, so it should be OK.

The linter improvements are:
- Increase linter performance
	- Make `full-lint` and `lint` write to different caches so we
	  avoid overwriting their caches since they're different configs
	- Change husky's hook to `npm run lint` so as to write to the
	  same cache
	- Remove `@typescript-eslint/eslint-plugin-tslint` which is
	  essentially a wrapper to TSLint because the rules aren't worth
	  running another linter
- Convert `.eslintrc.json` and `.eslintrc-syntax.json` to two spaces
  rather than four tabs to respect PS' `.editorconfig`
- Rename `fulllint` to `full-lint` to ease spelling it

[0] - https://pastie.io/mmtxpf.js (prettified)
2020-03-06 11:44:32 -08:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
Kris Johnson
9aaab2c57b
Typescript Help Tickets and Modlog and fix warnings (#6352) 2020-02-12 21:48:03 -08:00
HoeenHero
77b76a5b09 Fix mistake in ae28a960b (toId -> toID) 2020-01-04 14:54:09 -05:00
not_a_seagull
ae28a960be Convert index.js and team-validator-async.js to typescript (#5987) 2020-01-04 07:11:54 -05:00