Skip to content

Commit 3540242

Browse files
committed
eslint: reduce log-noise, cleanup error codes
1 parent 4598319 commit 3540242

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class NpmProcess {
3434
}
3535

3636
void install() {
37-
npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline");
37+
npmAwait("install",
38+
"--no-audit",
39+
"--no-package-lock",
40+
"--no-fund",
41+
"--prefer-offline");
3842
}
3943

4044
Process start() {

lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// this file will be glued to the top of the specific xy-server.js file
1+
// this file will be glued to the top of the specific xy-serve.js file
2+
const debug_serve = false; // set to true for debug log output in node process
23
const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager;
34
const express = require("express");
45
const app = express();
@@ -7,8 +8,14 @@ app.use(express.json({ limit: "50mb" }));
78

89
const fs = require("fs");
910

11+
function debugLog() {
12+
if (debug_serve) {
13+
console.log.apply(this, arguments)
14+
}
15+
}
16+
1017
var listener = app.listen(0, "127.0.0.1", () => {
11-
console.log("Server running on port " + listener.address().port);
18+
debugLog("Server running on port " + listener.address().port);
1219
fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) {
1320
if (err) {
1421
return console.log(err);
@@ -26,7 +33,7 @@ const shutdownManager = new GracefulShutdownManager(listener);
2633
app.post("/shutdown", (req, res) => {
2734
res.status(200).send("Shutting down");
2835
setTimeout(function() {
29-
shutdownManager.terminate(() => console.log("graceful shutdown finished."));
36+
shutdownManager.terminate(() => debugLog("graceful shutdown finished."));
3037
}, 200);
3138
});
3239

lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => {
99
const ESLintOverrideConfigFile = format_data.eslint_override_config_file;
1010

1111
if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) {
12-
res.status(501).send("Error while formatting: No config provided");
12+
res.status(400).send("Error while formatting: No config provided");
1313
return;
1414
}
1515

1616
const filePath = format_data.file_path;
1717

1818
if (!filePath) {
19-
res.status(501).send("Error while formatting: No file path provided");
19+
res.status(400).send("Error while formatting: No file path provided");
2020
return;
2121
}
2222

@@ -41,34 +41,34 @@ app.post("/eslint/format", async (req, res) => {
4141
eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig);
4242
}
4343

44-
console.log("using options: " + JSON.stringify(ESLintOptions));
45-
console.log("format input: ", format_data.file_content);
44+
debugLog("using options: " + JSON.stringify(ESLintOptions));
45+
debugLog("format input: ", format_data.file_content);
4646

4747
const eslint = new ESLint(ESLintOptions);
4848

4949

5050
const lintTextOptions = {
5151
filePath: filePath,
5252
}
53-
console.log("lintTextOptions", lintTextOptions);
53+
debugLog("lintTextOptions", lintTextOptions);
5454

5555
// LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type
5656
const results = await eslint.lintText(format_data.file_content, lintTextOptions);
5757
if (results.length !== 1) {
58-
res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results));
58+
res.status(500).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results));
5959
return;
6060
}
6161
const result = results[0];
62-
console.log("result: " + JSON.stringify(result));
62+
debugLog("result: " + JSON.stringify(result));
6363
if (result.fatalErrorCount && result.fatalErrorCount > 0) {
64-
res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages));
64+
res.status(500).send("Fatal error while formatting: " + JSON.stringify(result.messages));
6565
return;
6666
}
6767
const formatted = result.output || result.source || format_data.file_content;
6868
res.set("Content-Type", "text/plain");
6969
res.send(formatted);
7070
} catch (err) {
7171
console.log("error", err);
72-
res.status(501).send("Error while formatting: " + err);
72+
res.status(500).send("Error while formatting: " + err);
7373
}
7474
});

lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ app.post("/prettier/format", (req, res) => {
2727
try {
2828
formatted_file_content = prettier.format(format_data.file_content, format_data.config_options);
2929
} catch(err) {
30-
res.status(501).send("Error while formatting: " + err);
30+
res.status(500).send("Error while formatting: " + err);
3131
return;
3232
}
3333
res.set("Content-Type", "text/plain");

lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ app.post("/tsfmt/format", (req, res) => {
2525
res.set("Content-Type", "text/plain");
2626
res.send(resultMap.dest);
2727
}).catch(reason => {
28-
res.status(501).send(reason);
28+
res.status(500).send(reason);
2929
});
3030
});

testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception {
116116
new PrettierConfig(null, ImmutableMap.of("parser", "postcss")));
117117
try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) {
118118
stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo(
119-
"Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")");
119+
"Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")");
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)