Skip to content

Commit 7233962

Browse files
committed
refactor: sort all require statements alphabetically
- Sorted imports in all Lua files alphabetically - Maintained logical grouping where blank lines existed - Special handling for control.lua: kept Logger init at top - Fixed Logger initialization order issue - 32 files modified for consistent import organization
1 parent 61c9189 commit 7233962

33 files changed

Lines changed: 104 additions & 136 deletions

claude-task.md

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Task: analyze LLM-generated issue plans and execute on them.
1+
# Task: fix import styling
22

33
## Character
44

@@ -9,65 +9,32 @@ write code accordingly. It is fair to assume a deep knowledge of Lua.
99

1010
## What
1111

12-
This is a two-phase task. *DO NOT WRITE CODE AT THIS TIME*. It is also open ended. Take initiative for decision-making
13-
but not when writing code.
14-
15-
The codebase has some closely related common antipatterns. The Factorio API at LuaObject has a `.valid` property which must be checked across ticks. Because of this, the codebase is full of code like this:
12+
We have two styles of import:
1613

1714
```
18-
function do_something(whatever)
19-
if not whatever.valid then return nil end
20-
21-
-- really do it
22-
end
23-
24-
function use_the_thing(pindex)
25-
local player = game.get_player(pindex)
26-
-- Player is valid, we just got one.
27-
local target = player.selected
28-
-- Selected is valid, we just got one.
29-
do_something(target)
30-
end
15+
local fa_whatever = require("whatever")
3116
```
3217

33-
What's wrong is the extra check. Because *every caller* of do_something gets the object from the API without crossing a tick boundary, the validity check is not required. We also have another antipattern:
18+
and:
3419

3520
```
36-
-- Handle mining
37-
function kb_mine(player)
38-
-- Not important
39-
end
40-
41-
function kb_destroy_ghosts(player)
42-
if player.valid and player.selected and player.selected.valid and player.selected.is_ghost then
43-
-- Get rid of ghosts.
44-
end
45-
end
46-
47-
function kb_x(pindex)
48-
-- Player is valid.
49-
local player = game.get_player(pindex)
50-
51-
if player.selected and player.selected.valid and player.selected.is_ghost then
52-
kb_destroy_ghosts(player)
53-
else
54-
kb_mine(player)
55-
end
56-
end
21+
local Whatever = require("whatever")
5722
```
5823

59-
In this case we have two problems: the player is known top be valid (it came from the factorio API), player.selected is valid if not nil (it also came from the Factorio API, and no ticks have gone by), and the top-level function duplicates the checks
24+
The latter style is what we want. This needs to be fixed across the codebase. Since you have already onboarded, I am continuing this in the same session.
25+
26+
Automated tooling doesn't help too much because IDE things cannot currently handle control.lua, but don't overthink it.
27+
28+
`TH` for table-helpers is a special case; leave it alone. So is `FaUtils` instead of `Utils` (too close to a game built-in) so for e.g. `fa_utils` you'll have to go to `FaUtils`.
6029

61-
there are other similar antipatterns.
30+
Be careful! There's no way sed-type replacement is enough. If it was, I'd have already done that. The reason I am using an LLM is that it does require active intelligence and semantic analysis.
6231

63-
## Deliverables
32+
This can be done file by file, so you can use subagents if you so choose. Run the tests!
6433

65-
Evaluate the codebase. Ultrathink might be required. Prepare a report that:
34+
I suggest looking at the already converted imports and matching those where possible.
6635

67-
- Identifies other similar antipatterns
68-
- Identifies functions whose parents all have duplicate checks
69-
- Proposes small, atomic changes in a list.
70-
- For each change, provides a way to mark whether or not the change should be made.
36+
Expect running stylua to make a lot of formatting changes. Since the identifiers are getting shorter, it will want to wrap code differently.
7137

38+
TIP: Any file which does not contain the characters `fa_` can be eliminated early.
7239

73-
Once the report is prepared and I have evaluated it, and only after this point, we will proceed to coding.
40+
One commit per handled file, please.

control.lua

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,53 @@ local Logger = require("scripts.logger")
33
Logger.init()
44

55
local util = require("util")
6-
local FaUtils = require("scripts.fa-utils")
7-
local FaInfo = require("scripts.fa-info")
8-
local Localising = require("scripts.localising")
6+
7+
local Blueprints = require("scripts.blueprints")
8+
local BuildingTools = require("scripts.building-tools")
9+
local BuildingVehicleSectors = require("scripts.building-vehicle-sectors")
10+
local CircuitNetworks = require("scripts.circuit-networks")
11+
local Combat = require("scripts.combat")
12+
local Consts = require("scripts.consts")
913
local Crafting = require("scripts.crafting")
14+
local Driving = require("scripts.driving")
1015
local Electrical = require("scripts.electrical")
1116
local Equipment = require("scripts.equipment")
12-
local Combat = require("scripts.combat")
17+
local EventManager = require("scripts.event-manager")
18+
local FaCommands = require("scripts.fa-commands")
19+
local FaInfo = require("scripts.fa-info")
20+
local FaUtils = require("scripts.fa-utils")
21+
local F = require("scripts.field-ref")
22+
local Filters = require("scripts.filters")
1323
local Graphics = require("scripts.graphics")
14-
local Mouse = require("scripts.mouse")
15-
local TutorialSystem = require("scripts.tutorial-system")
16-
local BuildingVehicleSectors = require("scripts.building-vehicle-sectors")
24+
local KruiseKontrol = require("scripts.kruise-kontrol-wrapper")
25+
local Localising = require("scripts.localising")
1726
local MenuSearch = require("scripts.menu-search")
18-
local BuildingTools = require("scripts.building-tools")
27+
local MessageBuilder = require("scripts.message-builder")
28+
local Mouse = require("scripts.mouse")
1929
local PlayerMiningTools = require("scripts.player-mining-tools")
20-
local Rails = require("scripts.rails")
30+
local Quickbar = require("scripts.quickbar")
2131
local RailBuilder = require("scripts.rail-builder")
22-
local Trains = require("scripts.trains")
23-
local TrainStops = require("scripts.train-stops")
24-
local Driving = require("scripts.driving")
32+
local Rails = require("scripts.rails")
33+
local Research = require("scripts.research")
34+
local Rulers = require("scripts.rulers")
35+
local ScannerEntrypoint = require("scripts.scanner.entrypoint")
2536
local Spidertron = require("scripts.spidertron")
37+
local TH = require("scripts.table-helpers")
38+
local Teleport = require("scripts.teleport")
39+
local TestFramework = require("scripts.test-framework")
40+
local TrainStops = require("scripts.train-stops")
41+
local Trains = require("scripts.trains")
2642
local TransportBelts = require("scripts.transport-belts")
27-
local Zoom = require("scripts.zoom")
28-
local WorkerRobots = require("scripts.worker-robots")
29-
local Blueprints = require("scripts.blueprints")
3043
local TravelTools = require("scripts.travel-tools")
31-
local Teleport = require("scripts.teleport")
32-
local Warnings = require("scripts.warnings")
33-
local CircuitNetworks = require("scripts.circuit-networks")
34-
local KruiseKontrol = require("scripts.kruise-kontrol-wrapper")
35-
local Quickbar = require("scripts.quickbar")
44+
local TutorialSystem = require("scripts.tutorial-system")
3645
local BeltAnalyzer = require("scripts.ui.belt-analyzer")
3746
local BlueprintsMenu = require("scripts.ui.menus.blueprints-menu")
38-
local FaCommands = require("scripts.fa-commands")
39-
local Filters = require("scripts.filters")
40-
local Consts = require("scripts.consts")
41-
local F = require("scripts.field-ref")
42-
local MessageBuilder = require("scripts.message-builder")
43-
local Research = require("scripts.research")
4447
local UiRouter = require("scripts.ui.router")
45-
local Rulers = require("scripts.rulers")
46-
local ScannerEntrypoint = require("scripts.scanner.entrypoint")
47-
local TH = require("scripts.table-helpers")
48-
local WorkQueue = require("scripts.work-queue")
4948
local Viewpoint = require("scripts.viewpoint")
50-
local EventManager = require("scripts.event-manager")
51-
local TestFramework = require("scripts.test-framework")
49+
local Warnings = require("scripts.warnings")
50+
local WorkQueue = require("scripts.work-queue")
51+
local WorkerRobots = require("scripts.worker-robots")
52+
local Zoom = require("scripts.zoom")
5253

5354
---@meta scripts.shared-types
5455

scripts/blueprints.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--Here: Functions related to ghosts, blueprints and blueprint books
22
--Does not include event handlers
33

4-
local FaUtils = require("scripts.fa-utils")
54
local BuildingTools = require("scripts.building-tools")
6-
local PlayerMiningTools = require("scripts.player-mining-tools")
5+
local FaUtils = require("scripts.fa-utils")
76
local Graphics = require("scripts.graphics")
7+
local PlayerMiningTools = require("scripts.player-mining-tools")
88
local UiRouter = require("scripts.ui.router")
99
local Viewpoint = require("scripts.viewpoint")
1010

scripts/building-tools.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
--Here: Functions for building with the mod, both basics and advanced tools.
2-
local localising = require("scripts.localising")
3-
local FaUtils = require("scripts.fa-utils")
42
local Electrical = require("scripts.electrical")
3+
local FaUtils = require("scripts.fa-utils")
4+
local localising = require("scripts.localising")
55
local dirs = defines.direction
66
local Graphics = require("scripts.graphics")
7-
local RailBuilder = require("scripts.rail-builder")
8-
local TransportBelts = require("scripts.transport-belts")
97
local PlayerMiningTools = require("scripts.player-mining-tools")
8+
local RailBuilder = require("scripts.rail-builder")
109
local Teleport = require("scripts.teleport")
10+
local TransportBelts = require("scripts.transport-belts")
1111
local UiRouter = require("scripts.ui.router")
1212
local Viewpoint = require("scripts.viewpoint")
1313

scripts/building-vehicle-sectors.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
--Here: functions specific to the menus of buildings and vehicles.
22
local util = require("util")
3-
local FaUtils = require("scripts.fa-utils")
3+
local Blueprints = require("scripts.blueprints")
44
local Crafting = require("scripts.crafting")
5+
local FaUtils = require("scripts.fa-utils")
6+
local Filters = require("scripts.filters")
57
local localising = require("scripts.localising")
68
local TransportBelts = require("scripts.transport-belts")
7-
local Blueprints = require("scripts.blueprints")
89
local BeltAnalyzer = require("scripts.ui.belt-analyzer")
9-
local Filters = require("scripts.filters")
1010
local UiRouter = require("scripts.ui.router")
1111
local Viewpoint = require("scripts.viewpoint")
1212

scripts/circuit-networks.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
--Here: Functions relating to circuit networks, virtual signals, wiring and unwiring buildings, and the such.
22
--Does not include event handlers directly, but can have functions called by them.
3-
local circular = require("scripts.ds.circular-options-list")
4-
local localising = require("scripts.localising")
53
local util = require("util")
6-
local FaUtils = require("scripts.fa-utils")
74
local descriptors = require("scripts.descriptors")
8-
local multistate_switch = require("scripts.ui.low-level.multistate-switch")
5+
local circular = require("scripts.ds.circular-options-list")
6+
local FaUtils = require("scripts.fa-utils")
97
local Graphics = require("scripts.graphics")
8+
local localising = require("scripts.localising")
9+
local multistate_switch = require("scripts.ui.low-level.multistate-switch")
1010
local UiRouter = require("scripts.ui.router")
1111
local Viewpoint = require("scripts.viewpoint")
1212

scripts/combat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
--Does not include event handlers, guns and equipment maanagement
33

44
local util = require("util")
5+
local Equipment = require("scripts.equipment")
56
local FaUtils = require("scripts.fa-utils")
67
local Graphics = require("scripts.graphics")
78
local Mouse = require("scripts.mouse")
8-
local Equipment = require("scripts.equipment")
99
local UiRouter = require("scripts.ui.router")
1010
local Viewpoint = require("scripts.viewpoint")
1111

scripts/equipment.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
--Here: functions relating to guns and equipment management
22
--Does not include event handlers, combat, repair packs
33

4-
local localising = require("scripts.localising")
54
local Electrical = require("scripts.electrical")
5+
local localising = require("scripts.localising")
66
local UiRouter = require("scripts.ui.router")
77

88
local mod = {}

scripts/fa-commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Handlers registered by this file are exported and not announced through our
66
normal handling. This is because the launcher cannot handle queueing. We need
77
the mod to be silent.
88
]]
9-
local Fluids = require("scripts.fluids")
109
local FaUtils = require("scripts.fa-utils")
10+
local Fluids = require("scripts.fluids")
1111
local Localising = require("scripts.localising")
1212
local TH = require("scripts.table-helpers")
1313
local TransportBelts = require("scripts.transport-belts")

scripts/fa-info.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ won't change our mind later or maybe even go as far as adding settings for this
1515
stuff.
1616
]]
1717
local dirs = defines.direction
18-
local Filters = require("scripts.filters")
1918
local util = require("util")
19+
local Filters = require("scripts.filters")
2020
local UiRouter = require("scripts.ui.router")
2121

22-
local F = require("scripts.field-ref")
23-
local TransportBelts = require("scripts.transport-belts")
24-
local BotLogistics = require("scripts.worker-robots")
2522
local BuildingTools = require("scripts.building-tools")
2623
local Circuits = require("scripts.circuit-networks")
2724
local Consts = require("scripts.consts")
2825
local Driving = require("scripts.driving")
2926
local Electrical = require("scripts.electrical")
3027
local Equipment = require("scripts.equipment")
3128
local FaUtils = require("scripts.fa-utils")
29+
local F = require("scripts.field-ref")
3230
local Fluids = require("scripts.fluids")
3331
local Geometry = require("scripts.geometry")
3432
local Graphics = require("scripts.graphics")
@@ -38,8 +36,10 @@ local Rails = require("scripts.rails")
3836
local ResourceMining = require("scripts.resource-mining")
3937
local TH = require("scripts.table-helpers")
4038
local Trains = require("scripts.trains")
39+
local TransportBelts = require("scripts.transport-belts")
4140
local Viewpoint = require("scripts.viewpoint")
4241
local Wires = require("scripts.wires")
42+
local BotLogistics = require("scripts.worker-robots")
4343

4444
local mod = {}
4545

0 commit comments

Comments
 (0)