Repository navigation
Card Script Linting
The card-script linter checks card scripts against the engine code: whether each API, trigger mode and replacement event exists, and whether the engine actually reads each param a script sets. It runs on pull requests, where it comments on the changed lines, in the Card Workshop, and on request against any card or folder.
Check your scripts before you open a pull request. The pull request runs the same checks again and comments on what it finds, but it is a review step, not a place to test scripts.
Check before opening a pull request. You need a clone of the repository, a JDK and Maven. From the repository root, run:
mvn -pl forge-gui-desktop -am test "-Dtest=CardScriptLinterTest#checkCards" "-Dsurefire.failIfNoSpecifiedTests=false" "-Dcardscript.path=forge-gui/res/cardsfolder/upcoming"
cardscript.path can be a single file, a folder, or all of forge-gui/res/cardsfolder, in the repository or anywhere else. The output lists every finding:
Findings in ...\forge-gui\res\cardsfolder\upcoming:
test_bolt.txt:4: [ERROR] KEY-TYPO `NumDmgg$` -> `NumDmg$`
test_bolt.txt:4: [ERROR] REF-UNDEF `SubAbility$ DBDraw` -> no such SVar on this face
test_bolt.txt:4: [ERROR] MISSING-KEY `DealDamage` needs `NumDmg$`
1 script(s), 3 error(s), 0 warning(s)
Each line shows the file, the line number, the severity, a code, and what to change. If there are errors, the run ends in BUILD FAILURE and Maven's failure summary at the end of the output lists them again. Warnings don't fail the run, so with only warnings it ends in BUILD SUCCESS and the warnings are in the list above.
Review on the pull request. When the PR build finishes, a bot comments on the lines your PR changes. For example:
PreCostDesc$→PrecostDesc$(params are case-sensitive)
(warning)
NumCards$→ not used by LoseLife
Types
Sorcery→Instant
The last comment comes from comparing the card with its printed version on Scryfall. That comparison covers the name, type line, P/T, mana cost and loyalty. Cards that Scryfall doesn't list yet are skipped.
The review also adds a "Card-script review" row to the PR's checks. It shows a green tick when the changed cards have no findings, and a neutral mark when they do or when the build stopped before the linter ran. Its Details page lists every finding in the changed cards, including those on lines the PR didn't change.
- Error: the engine ignores this part of the script or fails on it, so the card doesn't work as written. A PR build fails if one of its changed lines has an error.
- Warning: probably a mistake, but check before you change it. Some params are read by shared engine code that the linter can't attribute to one API yet, so a correct param is sometimes reported as not used.
| Code | Severity | Meaning | Usual fix |
|---|---|---|---|
KEY-TYPO |
error | Not a param, but a similar one exists. | Use the suggested name. |
KEY-CASE |
error | The right name in the wrong case. Params are case-sensitive. | Use the suggested case. |
UNKNOWN-KEY |
error | No engine code reads this param. | Check the spelling, or remove it. |
MISSING-KEY |
error | The ability needs this param. | Add it. |
API-UNKNOWN |
error | The API, trigger mode, replacement event or static mode doesn't exist. | Check the spelling. |
REF-UNDEF |
error |
SubAbility$, Execute$ or a similar param names an SVar that this face doesn't define, or NextRoom$ names a room that isn't on the K:Dungeon: line. |
Fix the name, or move the SVar to this face. |
DUP-PARAM |
error, or warning if both values are the same | The param appears twice on one line. The engine uses the last one. | Remove one of them. |
COST |
error | A cost the engine doesn't recognise. It would be treated as free. | Check the cost syntax. |
MANA |
error | Not a mana symbol, or a repeated letter such as WW. |
Write each symbol separately, e.g. W W. |
NO-MANACOST |
error | A card that isn't a land has no ManaCost line. |
Add one. |
TYPE-TYPO |
error | A word on the Types line is miscased or one letter off a known type. |
Use the suggested type. |
LEX-PREFIX |
error | A line starts with a prefix the card reader doesn't recognise, e.g. Oracel:. |
Fix the prefix. |
LEX-DOLLAR |
error, or warning for a param name | A param without $, or a $ without a param name. The engine reads a bare param name as that param with an empty value, and ignores anything else. |
Add the $, e.g. NumDmg$ 3. |
LEX-DELIM |
error | A list uses the wrong separator: & instead of ,, or the reverse. |
Use the separator the message names. |
CASE |
error | A zone or Defined$ value in the wrong case, e.g. self. |
Use the suggested case. |
TRIG-CTX |
error | A Triggered... value on an A: line. An activated ability has no trigger to refer to. |
Move it to the trigger's SVar. |
LOYALTY |
error | A loyalty ability without Planeswalker$ True. |
Add it. |
WRONG-KEY |
warning | A real param, but this API doesn't read it. | Remove it, or check whether it belongs on another line. |
INTERNAL-KEY |
warning | A param the engine sets itself. Scripts shouldn't set it. | Remove it. |
TYPE-UNKNOWN |
warning | A word on the Types line that isn't in the type lists. The engine accepts it, but choices of a creature type won't offer it. |
Fix the word, or add the type to res/lists/TypeLists.txt or its edition file. |
ORPHAN |
warning | An SVar ability that nothing refers to. | Remove it, or add the missing reference. |
LEX-PIPE, LEX-DBLSPACE, LEX-NOSPACE, LEX-CURLY
|
warning | Spacing around | or $, or a curly apostrophe. |
Fix as the message says. |
DESC-COST |
warning |
SpellDescription$ repeats the activation cost. |
Remove the cost from the description. |
The linter doesn't yet check param values (Defined$, Valid*$, values that must be True), keyword (K:) lines, or whether the script matches the Oracle text.
| Step | What it does | Where | Runs in |
|---|---|---|---|
| 1. Param declarations | Classes list the params they read (see below). | IHasForgeParams |
— |
| 2. Declaration check | Reads the compiled engine code to find every param passed to getParam, hasParam and similar methods. Fails if the declarations don't match. |
CardScriptParamDeclarationTest |
test suite |
| 3. Lint | Checks card and token scripts (see the codes above). |
CardScriptLinter, CardScriptLinterTest
|
CI on PRs, Card Workshop, checkCards
|
| 4. Scryfall check | Compares each changed card with its printed version. | .github/scripts/card_script_review.py |
CI on PRs |
| 5. PR comments | Posts the results of steps 3 and 4 on the lines a PR changes, and as a check run. | .github/workflows/card-script-review.yml |
CI on PRs |
A class lists the params it reads in public static final fields:
public class DamageDealEffect extends DamageBaseEffect {
public static final String[] OPTIONAL_PARAMS = { "DamageSource", "DivideEvenly", ... };
public static final String[][] REQUIRED_PARAMS = {{"NumDmg"}}; // each group: one of these-
Framework classes (listed in
CardScriptParams.FRAMEWORK, such asAbilityFactory,CardTraitBaseandSpellAbility) declare the params that any ability can use. Each param is declared once, in the class that reads it. - Effects declare the params their API uses in addition to those. This includes params that the effect's helper methods read for it.
-
AI classes declare the params that only the AI reads, such as
AIExpectAmountonDamageDealAi. An effect that declares needs its AI class to declare too, if the AI reads anything more. -
INTERNAL_PARAMSlists params that the engine sets itself, for example when it builds keyword abilities. Framework classes, effects and AI classes can declare them. A script that sets one gets a warning.
Effects are being declared in batches. Until an effect declares its params, CI checks them against the compiled code instead, and the Card Workshop doesn't check them.
If you add a param read to the engine, CardScriptParamDeclarationTest fails until the param is declared. The message names the class and gives the array to paste:
card-script param declarations are out of sync with the code:
DrawEffect: reads [Defined] without declaring them
DrawEffect wants
public static final String[] OPTIONAL_PARAMS = {
"Defined", "IfDesc", "NumCards", "NumCardsDesc", "OptionalDecider", "Reveal", "Upto",
};
A param read by an effect goes in that effect's OPTIONAL_PARAMS. A param read by a framework class goes in that class's array.
The check also follows method calls. A param read in a helper method belongs to the effects that call the helper. If shared code starts to call the helper, the param belongs to every ability instead. So an engine change can make the check fail for a class you didn't edit. The message still names the class and the fix.
A read made on another ability doesn't count for the class that makes it. For example, TokenAi reads SacValid$ from the ability on top of the stack, so SacValid$ belongs to Sacrifice, not Token. The check counts a read as the class's own when it is made on one of the method's parameters, or on the root or targeting ability of one. A param that is only ever read on other abilities is accepted on every ability.
This command prints an array ready to paste for every effect that hasn't declared yet:
mvn -pl forge-gui-desktop -am test "-Dtest=CardScriptParamDeclarationTest" "-Dsurefire.failIfNoSpecifiedTests=false" "-DsuggestParams=true"
It also lists the shared code that still has to declare, and candidates for REQUIRED_PARAMS and INTERNAL_PARAMS. A required-param candidate is a param that 99.5% of an API's abilities in the card corpus set. Check the effect's code before declaring it required: a param with a default value isn't required.
| CI on a PR | checkCards |
Card Workshop | |
|---|---|---|---|
| Error | fails the build if on a changed line; commented | fails the run | highlighted |
| Warning | commented | printed | not shown |
On a PR, CI passes the PR's git diff -U0 to lintCorpus as -Dcardscript.diff. It lints every script but only fails on errors in the lines the PR changes, so existing errors in other cards don't block it. It also writes every finding to forge-gui-desktop/target/card-script-findings.json, which the review workflow posts as comments. Without a diff, as in a local test run, lintCorpus is skipped.
An error on a line the PR didn't change doesn't fail the build, even if the PR caused it: for example, deleting an SVar that an unchanged line still refers to.
The Card Workshop only knows declared params. Until an API declares its params, the Workshop doesn't flag param typos on that API's lines.
A PR build's log shows which kinds of lines the lint checked and which it skipped.
Adding known mistakes to copies of real scripts showed that the linter reports over 99% of misspelt param names, and about 63% of params set on an API that doesn't read them. It misses the rest because shared engine code reads those params for any ability.
Trigger, replacement and static params are only checked in CI until their classes declare.
Most card PRs come from forks. A pull_request build of a fork PR has a read-only token, so it can't post comments. Instead the build saves its results as an artifact. card-script-review.yml runs after the build with a token that can comment. It checks that the artifact belongs to the PR's latest commit, then posts the comments. It treats the artifact as data and never runs code from the PR. GitHub only runs this workflow from the default branch, so it can't be tested on a PR before merge.
mvn -pl forge-gui-desktop -am test "-Dtest=CardScript*Test" "-Dsurefire.failIfNoSpecifiedTests=false"
This runs the linter's unit tests and the declaration check. lintCorpus and checkCards are skipped unless given -Dcardscript.diff or -Dcardscript.path.
-
Adventure Mode
-
Gameplay Guide
-
Tutorials
-
-
Development
-
Customization & Themes