Skip to content

Commit 3b44018

Browse files
authored
Javascript Linting/Analysis of JS files (#361)
# Description This adds a makefile target to run a check on js files through jshint: `make js-lint` Experimented with a couple other tools such as `eslint` but they proved cumbersome and overly strict, requiring annotations in script files to direct behavior more and more. Things like spacing, undefined functions (because they were defined in a .go binding) etc. were problematic. Settled on `jshint` since it's looser in its rules. Primarily we are testing for: * syntax errors that will break execution * Incompatible keywords * "good" practices such as semicolons at the end of lines. There is some filtering out of noise from the docker image (npm error, npm warn, etc) that can be ignored. Otherwise, exits with code 1 if errors are detected, and reports errors. This _should_ allow us to implement in CI/CD processes. ## Changes - `js-lint` make target. - Handled existing js errors reported (a lot). ### Example Output **With errors:** ``` √ ~/dev/GoMud % make js-lint _datafiles/sample-scripts/spells/harmmulti.js: line 10, col 27, Expected ')' and instead saw 'eActor'. _datafiles/sample-scripts/spells/harmmulti.js: line 10, col 44, Expected an assignment or function call and instead saw an expression. _datafiles/sample-scripts/spells/harmmulti.js: line 10, col 72, Missing semicolon. _datafiles/sample-scripts/spells/harmmulti.js: line 10, col 72, Expected an identifier and instead saw ')'. _datafiles/sample-scripts/spells/harmmulti.js: line 10, col 72, Expected an assignment or function call and instead saw an expression. 5 errors make: *** [js-lint] Error 1 √ ~/dev/GoMud % ``` **Without errors:** ``` √ ~/dev/GoMud % make js-lint √ ~/dev/GoMud % ``` ## Links #342
1 parent d407d16 commit 3b44018

File tree

138 files changed

+701
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+701
-636
lines changed

.jshintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_datafiles/html/public/static/js/xterm.4.19.0.js
2+
_datafiles/html/public/static/js/xterm-addon-fit.js
3+
_datafiles/html/admin/static/js/htmx.2.0.3.js

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 6
3+
}
4+

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ coverage:
113113
go tool cover -html=bin/covdatafiles/cover.out && \
114114
rm -rf bin
115115

116+
.PHONY: js-lint
117+
js-lint:
118+
# Grep filtering it to remove errors reported by docker image around npm packages
119+
# if "### errors" is found in the output, exits with an error code of 1
120+
# This should allow us to use it in CI/CD
121+
@docker run --rm -v "$(PWD)":/app -w /app node:20 npx jshint . \
122+
2>&1 | grep -v "^npm " | tee /dev/stderr | grep -Eq "^[0-9]+ errors" && exit 1 || true
123+
116124
#
117125
#
118126
# Cert generation for testing

_datafiles/sample-scripts/mobs/item-gold-quest.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const REQUIRED_ITEM_ID = 10001;
1313
const REQUIRED_GOLD_AMOUNT = 10;
1414

1515
// This corresponds to the quest defined in the _datafiles/quests/ folder.
16-
const QUEST_START_ID = "1000000-start" // All quests begin with #-start
17-
const QUEST_NEXT_STEP_ID = "1000000-givegold" // Quest steps can be called #-anything
18-
const QUEST_END_ID = "1000000-end" // All quests end with #-end
16+
const QUEST_START_ID = "1000000-start"; // All quests begin with #-start
17+
const QUEST_NEXT_STEP_ID = "1000000-givegold"; // Quest steps can be called #-anything
18+
const QUEST_END_ID = "1000000-end"; // All quests end with #-end
1919

2020

2121
//
@@ -129,7 +129,7 @@ function onGive(mob, room, eventDetails) {
129129
//
130130
// Give them the next step of the quest
131131
//
132-
user.GiveQuest(QUEST_NEXT_STEP_ID)
132+
user.GiveQuest(QUEST_NEXT_STEP_ID);
133133

134134
return true;
135135
}
@@ -172,14 +172,14 @@ function onGive(mob, room, eventDetails) {
172172
//
173173
excessGold = eventDetails.gold - REQUIRED_GOLD_AMOUNT;
174174
if ( excessGold > 0 ) {
175-
mob.Command("say Here's your change.")
175+
mob.Command("say Here's your change.");
176176
mob.Command("give "+String(excessGold)+" gold " + user.ShorthandId()); // Give it to the player using shorthand
177177
}
178178

179179
//
180180
// They have now completed the entire quest, all steps are complete.
181181
//
182-
user.GiveQuest(QUEST_END_ID)
182+
user.GiveQuest(QUEST_END_ID);
183183

184184
return true;
185185
}

_datafiles/sample-scripts/spells/harmarea.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
HARM_DICE_QTY = 1
3-
HARM_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful area spell</ansi>'
2+
HARM_DICE_QTY = 1;
3+
HARM_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful area spell</ansi>';
55

66
// Called when the casting is initialized (cast command)
77
// Return false if the casting should be ignored/aborted
88
function onCast(sourceActor, targetActors) {
99

1010
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1111
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
12-
return true
12+
return true;
1313
}
1414

1515
function onWait(sourceActor, targetActors) {

_datafiles/sample-scripts/spells/harmmulti.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
HARM_DICE_QTY = 1
3-
HARM_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful group spell</ansi>'
2+
HARM_DICE_QTY = 1;
3+
HARM_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful group spell</ansi>';
55

66
// Called when the casting is initialized (cast command)
77
// Return false if the casting should be ignored/aborted
88
function onCast(sourceActor, targetActors) {
99

1010
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1111
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
12-
return true
12+
return true;
1313
}
1414

1515
function onWait(sourceActor, targetActors) {

_datafiles/sample-scripts/spells/harmsingle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
HARM_DICE_QTY = 1
3-
HARM_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful single target spell</ansi>'
2+
HARM_DICE_QTY = 1;
3+
HARM_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample harmful single target spell</ansi>';
55

66
// Called when the casting is initialized (cast command)
77
// Return false if the casting should be ignored/aborted
88
function onCast(sourceActor, targetActor) {
99

1010
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1111
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
12-
return true
12+
return true;
1313
}
1414

1515
function onWait(sourceActor, targetActor) {

_datafiles/sample-scripts/spells/helparea.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
HEAL_DICE_QTY = 1
3-
HEAL_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful area spell</ansi>'
2+
HEAL_DICE_QTY = 1;
3+
HEAL_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful area spell</ansi>';
55

66

77
// Called when the casting is initialized (cast command)
@@ -10,7 +10,7 @@ function onCast(sourceActor, targetActors) {
1010

1111
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1212
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
13-
return true
13+
return true;
1414
}
1515

1616
function onWait(sourceActor, targetActors) {

_datafiles/sample-scripts/spells/helpmulti.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
HEAL_DICE_QTY = 1
3-
HEAL_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful group spell</ansi>'
2+
HEAL_DICE_QTY = 1;
3+
HEAL_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful group spell</ansi>';
55

66

77
// Called when the casting is initialized (cast command)
@@ -10,7 +10,7 @@ function onCast(sourceActor, targetActors) {
1010

1111
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1212
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
13-
return true
13+
return true;
1414
}
1515

1616
function onWait(sourceActor, targetActors) {

_datafiles/sample-scripts/spells/helpsingle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
HEAL_DICE_QTY = 1
3-
HEAL_DICE_SIDES = 2
4-
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful single target spell</ansi>'
2+
HEAL_DICE_QTY = 1;
3+
HEAL_DICE_SIDES = 2;
4+
SPELL_DESCRIPTION = '<ansi fg="222">sample helpful single target spell</ansi>';
55

66
// Called when the casting is initialized (cast command)
77
// Return false if the casting should be ignored/aborted
88
function onCast(sourceActor, targetActor) {
99

1010
SendUserMessage(sourceActor.UserId(), 'You begin to chant softly.');
1111
SendRoomMessage(sourceActor.GetRoomId(), sourceActor.GetCharacterName(true)+' begins to chant softly.', sourceActor.UserId());
12-
return true
12+
return true;
1313
}
1414

1515
function onWait(sourceActor, targetActor) {

0 commit comments

Comments
 (0)