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.
* Use value rules for timer
* lint
* fix rule overrides
* fix the "boolean" value rules
* add limits for number based rules
* Realized that you don't need boolean value rules
* oops
* fix checks for lower bounds
* Use base forme names in banlists where possible
This allows you use e.g. 'Arceus-Normal' instead of 'Arceus-Base'.
Also includes some aliases so that all known base forme names actually work.
* Update formats.ts
---------
Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com>
* Use base forme names in banlists where possible
This allows you use e.g. 'Arceus-Normal' instead of 'Arceus-Base'.
Also includes some aliases so that all known base forme names actually work.
* Update formats.ts
* Update config/formats.ts
* Update config/formats.ts
* Update config/formats.ts
* Apply suggestions from code review
---------
Co-authored-by: Kris Johnson <11083252+KrisXV@users.noreply.github.com>
TypeScript 4.8+ supports Lowercase for lowercase strings, which isn't
exactly what ID is, but can be used to type IDs in object keys and data
entries that previously required string. I'm calling it IDEntry in places
where it should be an ID but TypeScript doesn't support that.
Very conveniently, no additional casts will be needed when using ID
where IDEntry is expected.
It's caught at least a few bugs, which is also why I'm PRing: I didn't
write the code for the bugs it found, and don't know if it's the right
way to fix them.
This ballooned into several other type refactors.
This replaces some pretty jank code with much cleaner code.
Anything that would be more cleanly implemented by iterating the
players array is now done by iterating the players array.
Some instances of p1/p2 are lying around but we should slowly deprecate
them.
Changes relevant to our codebase:
- TypeScript now knows that `typeof id === 'string'`! A bunch of casts
on `User | ID` or `Room | RoomID` are no longer necessary!!!
- `override` will protect against certain typoes, and we'll adopt it
(and `--noImplicitOverride`) as soon as sucrase comes in
- `declare` is now required for properties we want to narrow the type
of without directly overwriting - a good thing to use going forward,
but very annoying to fix all our old code for
defaultLevel should not be set to maxLevel if this would make teams break
maxTotalLevel.
Fixes a bug where level 100 pokemon were automatically set to higher
levels in cases where it didn't make sense.
"EV Limit = 510" is now its own rule which can be changed separately
from the rest of Obtainable Misc.
The rest of Obtainable Misc doesn't seem useful to break up, so I
haven't bothered.
`no item` is now a fake item meaning "not holding an item", for the
purposes of the team validator. This means that `-no item` will force
all pokemon to carry items.
`all items` no longer includes not holding an item, so `-all items`
will now work as expected.
It turns out rules need to be added before sides are initialized,
so that they can hook `ModifySpecies` during side initialization.
The proper way to fix this is pretty complex so this is just a hack.
Also stop enforcing 4 moves limit and 6 pokemon limit in `-Nonstandard`,
for the same reason we stopped enforcing the level 100 limit; any format
that explicitly wants it higher should automatically override it.
In format events:
`onFieldTeamPreview` has been renamed back to `onTeamPreview`. It's now
a custom event (like `onBegin`), rather than a field event.
Team Preview data has been entirely moved from `onBegin` into
`onTeamPreview`.
`onFieldStart` for formats/rules now happens after Team Preview, rather
than before. Use `onBegin` for things that happen before Team Preview.
`teamLength`, `maxLevel`, `cupLevelLimit`, and `minSourceGen` no longer
exist as properties of `Format`. Instead, they're value rules that
become properties of `RuleTable`, and can be specified as custom rules
and inherited through rulesets like anything else.
See the PR for a full reckoning of changes:
https://github.com/smogon/pokemon-showdown/pull/8267
`maxTeamSize` is a bad variable name (not that `teamLength.battle` is
any better, but that'll get fixed in a future refactor).
- Rename `maxTeamSize` to `chosenTeamSize`, to better indicate that
this is the size after Team Preview, and that it is also the minimum
size after Team Preview.
- Don't limit team sizes to 6 if `teamLength.battle` isn't specified.
This removes an unnecessary `teamLength.battle` requirement in all
Custom Game formats.
- Stop requiring `maxTeamSize` as a parameter for `battle.getRequests`.
It's not even used except as a hint to the Preact client, and was
never state in the first place.
- Stop supporting partial `side.chooseTeam`. This is an unused feature
and removing it massively simplifies the code and fixes a bug in
`cupLevelLimit` which definitely was not written with the
understanding that `chooseTeam` could be partial.
- Fix a bug in #7929 which seemed to misunderstand what `teamsize` was
for.
Previously, the validator had its own hardcoded tag system. This
removes the hardcoding and makes it so any pokemon tag in `tags.ts`
can be banned or unbanned.
For side conditions, `onStart`/`onRestart`/`onResidual`/`onEnd`
have been renamed `onSideStart`/`onSideRestart`/`onSideResidual`/`onSideEnd`,
with the `onResidualOrder` properties renamed `onSideResidualOrder`.
For field conditions, `onStart`/`onRestart`/`onResidual`/`onEnd`
have been renamed `onFieldStart`/`onFieldRestart`/`onFieldResidual`/`onFieldEnd`,
with the `onResidualOrder` properties renamed `onFieldResidualOrder`.
(The `onField` and `onSide` part helps make it clear to the type system
that the first argument is a Field or Side, not a Pokemon.)
Side and field conditions can now use `onResidual` to tick separately
on each pokemon in Speed order. `onResidualOrder` (the per-pokemon
tick) can be timed separate from `onSideResidualOrder` (the
per-condition tick), allowing conditions to end at a different priority
than they tick per-pokemon.
Relatedly, `onTeamPreview` and `onStart` in formats now need to be
`onFieldTeamPreview` and `onFieldStart`.
Unrelatedly, `effectData` has been renamed `effectState`, and the
corresponding state containers (`pokemon.statusData`,
`pokemon.speciesData`, `pokemon.itemData`, `pokemon.abilityData`,
`field.weatherData`, `field.terrainData`) have been similarly renamed. I
renamed the types a while ago, but I was holding off renaming the fields
because it would be a breaking change. But this is a breaking change
anyway, so we might as well do it now.
Note: `onResidual` will tick even on `onSideEnd` turns, although
`onSideResidual` won't. When refactoring weather, remember to
check `this.state.duration` so you don't deal weather damage on the
ending turn.
Intended as a better fix for #8216