You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
# Task: analyze LLM-generated issue plans and execute on them.
1
+
# Task: fix import styling
2
2
3
3
## Character
4
4
@@ -9,65 +9,32 @@ write code accordingly. It is fair to assume a deep knowledge of Lua.
9
9
10
10
## What
11
11
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:
16
13
17
14
```
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")
31
16
```
32
17
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:
34
19
35
20
```
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")
57
22
```
58
23
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`.
60
29
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.
62
31
63
-
## Deliverables
32
+
This can be done file by file, so you can use subagents if you so choose. Run the tests!
64
33
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.
66
35
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.
71
37
38
+
TIP: Any file which does not contain the characters `fa_` can be eliminated early.
72
39
73
-
Once the report is prepared and I have evaluated it, and only after this point, we will proceed to coding.
0 commit comments