-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
105 lines (96 loc) · 2.71 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import assert from "node:assert";
import test from "node:test";
import { ESLint } from "eslint";
import config from "@cargosense/eslint-config";
const eslint = new ESLint({
baseConfig: config,
overrideConfigFile: true,
});
test("default export", () => {
assert.ok(Array.isArray(config));
});
test("loads config and validates correct syntax", async () => {
const [{ errorCount }] = await eslint.lintText("(() => 1)();\n", {
filePath: "index.test.js",
});
assert.strictEqual(errorCount, 0);
});
test("loads config and invalidates incorrect syntax", async () => {
const [{ errorCount, messages }] = await eslint.lintText("(() => { [].map().flat(); }) ()\n", {
filePath: "index.test.js",
});
const expected = [
{
column: 8,
endColumn: 9,
endLine: 1,
fix: { range: [8, 8], text: "\n" },
line: 1,
message: "Statement inside of curly braces should be on next line.",
messageId: "blockSameLine",
nodeType: "Punctuator",
ruleId: "@stylistic/brace-style",
severity: 2,
},
{
column: 10,
endColumn: 26,
endLine: 1,
line: 1,
message: "This line has 2 statements. Maximum allowed is 1.",
messageId: "exceed",
nodeType: "ExpressionStatement",
ruleId: "@stylistic/max-statements-per-line",
severity: 2,
},
{
column: 13,
endColumn: 25,
endLine: 1,
fix: { range: [12, 24], text: "flatMap()" },
line: 1,
message: "Use flatMap instead of .map().flat()",
messageId: "preferFlatMap",
nodeType: null,
ruleId: "array-func/prefer-flat-map",
severity: 2,
},
{
column: 27,
endColumn: 28,
endLine: 1,
fix: { range: [26, 26], text: "\n" },
line: 1,
// eslint-disable-next-line @stylistic/max-len
message: "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.",
messageId: "singleLineClose",
nodeType: "Punctuator",
ruleId: "@stylistic/brace-style",
severity: 2,
},
{
column: 28,
fix: { range: [28, 29], text: "" },
line: 1,
message: "Unexpected whitespace between function name and paren.",
messageId: "unexpectedWhitespace",
nodeType: "CallExpression",
ruleId: "@stylistic/function-call-spacing",
severity: 2,
},
{
column: 32,
endColumn: 1,
endLine: 2,
fix: { range: [31, 31], text: ";" },
line: 1,
message: "Missing semicolon.",
messageId: "missingSemi",
nodeType: "ExpressionStatement",
ruleId: "@stylistic/semi",
severity: 2,
},
];
assert.strictEqual(errorCount, 6);
assert.deepEqual(messages, expected);
});