Skip to content

Commit 9454bc1

Browse files
committed
eask analyze prints to stdout to filter messages
1 parent 166d014 commit 9454bc1

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

lisp/core/analyze.el

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,40 @@ Argument LEVEL and MSG are data from the debug log signal."
9393
(t #'eask-analyze--write-plain-text))
9494
level msg))))
9595

96+
(defun eask-stdout (msg &rest args)
97+
"Like `eask-msg' but prints to stdout."
98+
(eask-princ (apply #'eask--format-paint-kwds msg args) nil)
99+
(eask-princ "\n" nil))
100+
96101
(defun eask-analyze--file (files)
97102
"Lint list of Eask FILES."
98103
(let (checked-files content)
99104
;; Linting
100105
(dolist (file files)
101106
(eask--silent-error
102-
(eask--save-load-eask-file file
103-
(push file checked-files))))
107+
(eask--save-load-eask-file file
108+
(push file checked-files))))
104109

105110
;; Print result
106111
(eask-msg "")
107-
(cond ((and (eask-json-p) ; JSON format
112+
(cond ((and (eask-json-p) ; JSON format
108113
(or eask-analyze--warnings eask-analyze--errors))
109114
(setq content
110115
(eask-analyze--pretty-json (json-encode
111116
`((warnings . ,eask-analyze--warnings)
112117
(errors . ,eask-analyze--errors)))))
113118
;; XXX: When printing the result, no color allow.
114119
(eask--with-no-color
115-
(eask-msg content)))
116-
(eask-analyze--log ; Plain text
120+
(eask-stdout content)))
121+
(eask-analyze--log ; Plain text
117122
(setq content
118123
(with-temp-buffer
119124
(dolist (msg (reverse eask-analyze--log))
120125
(insert msg "\n"))
121126
(buffer-string)))
122127
;; XXX: When printing the result, no color allow.
123128
(eask--with-no-color
124-
(mapc #'eask-msg (reverse eask-analyze--log))))
129+
(mapc #'eask-stdout (reverse eask-analyze--log))))
125130
(t
126131
(eask-info "(Checked %s file%s)"
127132
(length checked-files)

test/jest/__snapshots__/analyze.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
exports[`analyze in ./analyze/dsl matches snapshot 1`] = `
44
{
55
"stderr": "
6-
~/Eask:9:18 Error: ✗ Multiple definition of \`package'
6+
",
7+
"stdout": "~/Eask:9:18 Error: ✗ Multiple definition of \`package'
78
~/Eask:12:55 Error: ✗ Multiple definition of \`website-url'
89
~/Eask:14:16 Error: ✗ Multiple definition of \`keywords'
910
~/Eask:17:15 Warning: 💡 Warning regarding duplicate author name, name
@@ -22,6 +23,5 @@ exports[`analyze in ./analyze/dsl matches snapshot 1`] = `
2223
~/Eask:50:2 Error: ✗ Define dependencies with the same name \`f'
2324
~/Eask:50:2 Error: ✗ Define dependencies with the same name \`f' with different version
2425
",
25-
"stdout": "",
2626
}
2727
`;

test/jest/analyze.test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const { TestContext } = require("./helpers");
22

3+
/**
4+
* Clean output and attempt to parse as JSON.
5+
* Throws if failing.
6+
* @param {string} s
7+
* @returns {object} the parsed JSON.
8+
*/
9+
function tryJSON(s) {
10+
return JSON.parse(s.trim() || "{}");
11+
}
12+
313
describe("analyze", () => {
414
describe("in ./analyze/dsl", () => {
515
const ctx = new TestContext("./test/jest/analyze/dsl");
@@ -10,11 +20,11 @@ describe("analyze", () => {
1020
});
1121

1222
it("handles json option", async () => {
13-
const { stderr } = await ctx.runEask("analyze --json");
23+
const { stdout } = await ctx.runEask("analyze --json");
1424
await ctx.runEask("analyze Eask --json");
1525

1626
// try to parse output, errors if not valid
17-
JSON.parse(stderr);
27+
tryJSON(stdout);
1828
});
1929

2030
it("matches snapshot", async () => {
@@ -24,9 +34,9 @@ describe("analyze", () => {
2434
});
2535

2636
it("should report multiple definitions", async () => {
27-
const { stderr } = await ctx.runEask("analyze");
37+
const { stdout } = await ctx.runEask("analyze");
2838
// expect this substring
29-
expect(stderr).toMatch("Multiple definition of `package'");
39+
expect(stdout).toMatch("Multiple definition of `package'");
3040
});
3141
});
3242

@@ -71,6 +81,18 @@ describe("analyze", () => {
7181
await expect(ctx.runEask("analyze Eask-error")).rejects.toThrow();
7282
});
7383

84+
// JSON
85+
it("handles json option when no errors", async () => {
86+
const { stdout } = await ctx.runEask("analyze --json Eask-normal");
87+
tryJSON(stdout);
88+
});
89+
90+
it("handles json option when lexical binding warnings are present", async () => {
91+
const { stdout } = await ctx.runEask("analyze --json Eask-lexical");
92+
tryJSON(stdout);
93+
});
94+
95+
// --strict and --allow-error
7496
it.failing("should error when using --strict on Eask-warn", async () => {
7597
await expect(ctx.runEask("analyze --strict Eask-warn")).rejects.toThrow();
7698
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(package "check-dsl" "0.0.1" "Test for DSL")
2+
(keywords "dsl")

0 commit comments

Comments
 (0)