From 8256afc7e6e5a0919b0be980769be387b44ffffe Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Mon, 29 Apr 2024 11:09:13 +0300 Subject: [PATCH 1/7] parser: Move Integer import to outfits Why: It apparently isn't used anywhere in the parser.clj file but is used in the outfits.clj file What: Move the import to the outfits.clj file --- src/clj/endless_ships/outfits.clj | 3 ++- src/clj/endless_ships/parser.clj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clj/endless_ships/outfits.clj b/src/clj/endless_ships/outfits.clj index ba4071c..f4f2318 100644 --- a/src/clj/endless_ships/outfits.clj +++ b/src/clj/endless_ships/outfits.clj @@ -1,6 +1,7 @@ (ns endless-ships.outfits (:require [clojure.string :as str] - [endless-ships.parser :refer [->map data]])) + [endless-ships.parser :refer [->map data]]) + (:import [java.lang Integer])) (defn- update-if-present [m k f] (if (contains? m k) diff --git a/src/clj/endless_ships/parser.clj b/src/clj/endless_ships/parser.clj index 07468b8..5b562a1 100644 --- a/src/clj/endless_ships/parser.clj +++ b/src/clj/endless_ships/parser.clj @@ -3,7 +3,7 @@ [clojure.java.io :refer [file resource]] [clojure.string :as str] [instaparse.core :as insta]) - (:import [java.lang Float Integer])) + (:import [java.lang Float])) (def files "All files containing game data." From db21aad3c715b897a1388e8828a48374b1b47193 Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Tue, 20 Aug 2024 09:27:24 +0300 Subject: [PATCH 2/7] outfits.clj: Comment out unused outfits map keys Why: clj-kondo complains the shield damage and hull-damage are unused bindings. What: Comment them out so that they are still easily accessible if ever needed --- src/clj/endless_ships/outfits.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj/endless_ships/outfits.clj b/src/clj/endless_ships/outfits.clj index f4f2318..7088a51 100644 --- a/src/clj/endless_ships/outfits.clj +++ b/src/clj/endless_ships/outfits.clj @@ -92,7 +92,7 @@ (defn- normalize-weapon-attrs [outfits] (map (fn [{category :category - {:keys [reload velocity velocity-override lifetime shield-damage hull-damage] + {:keys [reload velocity velocity-override lifetime] ; shield-damage hull-damage] [submunition-name submunition-count] :submunition :as weapon-attrs} :weapon :as outfit}] From 2072e137ba086884834e8a3db73322285bf2fcab Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Tue, 20 Aug 2024 09:30:12 +0300 Subject: [PATCH 3/7] outfitters.clj: Stop requiring ->map Why: clj-kondo complains about ->map being referred but never used What: Remove it from the refer. If it is ever needed, it can easily be added back again --- src/clj/endless_ships/outfitters.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj/endless_ships/outfitters.clj b/src/clj/endless_ships/outfitters.clj index cb94fd0..f830053 100644 --- a/src/clj/endless_ships/outfitters.clj +++ b/src/clj/endless_ships/outfitters.clj @@ -1,5 +1,5 @@ (ns endless-ships.outfitters - (:require [endless-ships.parser :refer [->map data]])) + (:require [endless-ships.parser :refer [data]])) (defn- find-object-with-name [objects name] (some (fn [object] From 5268c4111317c88da0be1f45a02f819a6ec4a0ff Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Tue, 20 Aug 2024 22:58:31 +0300 Subject: [PATCH 4/7] core: Require endless-ships.parser Why: It's used it in the file, to use the data binding, but not explicitly required. While it works, readability wise, I think it's better to be explicit What: Explicitly require endless-ships.parser --- src/clj/endless_ships/core.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clj/endless_ships/core.clj b/src/clj/endless_ships/core.clj index f7fa7e7..39477cc 100644 --- a/src/clj/endless_ships/core.clj +++ b/src/clj/endless_ships/core.clj @@ -8,7 +8,8 @@ [clojure.string :as str] [endless-ships.outfits :refer [outfits]] [endless-ships.outfitters :refer [outfitters]] - [endless-ships.ships :refer [modifications ships]])) + [endless-ships.ships :refer [modifications ships]] + [endless-ships.parser])) (def file->race {"kestrel.txt" :human From 88691f82d91a05b0fb9f0d5e52b719e22c28924f Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Tue, 20 Aug 2024 23:00:16 +0300 Subject: [PATCH 5/7] core: Switch an if with no else to when Why: An if missing an else branch can be surprising and when exists precisely to cover this use case What: Switch if to when --- src/clj/endless_ships/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj/endless_ships/core.clj b/src/clj/endless_ships/core.clj index 39477cc..2414eec 100644 --- a/src/clj/endless_ships/core.clj +++ b/src/clj/endless_ships/core.clj @@ -134,7 +134,7 @@ (io/file "./build/app.css")) (io/copy (io/file "./public/ga.json") (io/file "./build/ga.json")) - (if (.exists (io/file "./ga.json")) + (when (.exists (io/file "./ga.json")) (io/copy (io/file "./ga.json") (io/file "./build/ga.json"))))) From 74ab51a90cacee3a97349cf1ae7afd6c3fc8e466 Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Tue, 20 Aug 2024 23:02:27 +0300 Subject: [PATCH 6/7] ships: Remove unused require Why: rename-keys from clojure.set is apparently not used What: Remove the require --- src/clj/endless_ships/ships.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clj/endless_ships/ships.clj b/src/clj/endless_ships/ships.clj index 0781ca1..bd52acd 100644 --- a/src/clj/endless_ships/ships.clj +++ b/src/clj/endless_ships/ships.clj @@ -1,6 +1,5 @@ (ns endless-ships.ships - (:require [clojure.set :refer [rename-keys]] - [endless-ships.parser :refer [->map data]])) + (:require [endless-ships.parser :refer [->map data]])) (defn- add-key-if [cond key value] (if cond From e4cd6727452d556d33b2eaa72abb81b25b1b3010 Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Sun, 25 Aug 2024 23:03:44 +0300 Subject: [PATCH 7/7] ships.clj: Ignore a :not-empty? warning by clj-kondo Why: Given clj-kondo doesn't complain about the rest of the Clojure codebase after the last few patches, this is the last hanging fruit. I 've been pondering over this for a while. Replacing (not (empty?) with idiom (seq) as per https://clojuredocs.org/clojure.core/empty_q feels a bit weird. It seems I am not the only one with this opinion per https://github.com/clj-kondo/clj-kondo/issues/937 Given the above, I am inclined to just ignore it for now, but happy to be convinced otherwise What: Just instruct clj-kondo to ignore this --- src/clj/endless_ships/ships.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clj/endless_ships/ships.clj b/src/clj/endless_ships/ships.clj index bd52acd..2642b6c 100644 --- a/src/clj/endless_ships/ships.clj +++ b/src/clj/endless_ships/ships.clj @@ -27,7 +27,8 @@ :file file} (add-key-if (contains? ship "sprite") :sprite - [sprite (not (empty? animation))]) + [sprite #_{:clj-kondo/ignore [:not-empty?]} + (not (empty? animation))]) (add-key-if (contains? attrs "licenses") :licenses (-> license-attrs keys vec))