@dvukovic/style-guide 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/eslint/configs/aws.test.js +0 -17
- package/src/eslint/configs/core.test.js +0 -23
- package/src/eslint/configs/jest.test.js +0 -17
- package/src/eslint/configs/mobx.test.js +0 -17
- package/src/eslint/configs/next.test.js +0 -17
- package/src/eslint/configs/node.test.js +0 -17
- package/src/eslint/configs/package-json.test.js +0 -154
- package/src/eslint/configs/playwright.test.js +0 -17
- package/src/eslint/configs/react.test.js +0 -17
- package/src/eslint/configs/storybook.test.js +0 -17
- package/src/eslint/configs/typescript-strict.test.js +0 -19
- package/src/eslint/configs/typescript.test.js +0 -19
- package/src/eslint/configs/vitest.test.js +0 -17
- package/src/eslint/plugins/eslint.test.js +0 -42
- package/src/eslint/plugins/validate-rules.test.js +0 -68
- package/src/eslint/rules/document-todos/document-todos.test.js +0 -174
- package/src/eslint/rules/no-commented-out-code/no-commented-out-code.test.js +0 -89
- package/src/eslint/rules/no-restricted-dependencies/no-restricted-dependencies.test.js +0 -237
- package/src/eslint/rules/no-t/no-t.test.js +0 -85
- package/src/eslint/rules/require-properties/require-properties.test.js +0 -164
- package/src/eslint/rules/valid-engines-node/valid-engines-node.test.js +0 -154
- package/src/prettier/configs/core.test.js +0 -24
- package/src/stylelint/configs/core.test.js +0 -24
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { ESLint } from "eslint"
|
|
2
|
-
import tseslint from "typescript-eslint"
|
|
3
|
-
|
|
4
|
-
import { documentTodos } from "./document-todos.js"
|
|
5
|
-
|
|
6
|
-
const createEslint = (url = "http") => {
|
|
7
|
-
return new ESLint({
|
|
8
|
-
overrideConfig: [
|
|
9
|
-
{
|
|
10
|
-
files: ["**/*.ts"],
|
|
11
|
-
languageOptions: {
|
|
12
|
-
parser: tseslint.parser,
|
|
13
|
-
},
|
|
14
|
-
plugins: {
|
|
15
|
-
dvukovic: {
|
|
16
|
-
rules: {
|
|
17
|
-
"document-todos": documentTodos,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
rules: {
|
|
22
|
-
"dvukovic/document-todos": ["error", { url }],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
overrideConfigFile: true,
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe("dvukovic/document-todos", () => {
|
|
31
|
-
test("reports TODO without URL", async () => {
|
|
32
|
-
const eslint = createEslint()
|
|
33
|
-
const code = `// TODO: fix this later\nconst y = 2\n`
|
|
34
|
-
|
|
35
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
36
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
37
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
expect(errors?.length).toBe(1)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test("reports FIXME without URL", async () => {
|
|
44
|
-
const eslint = createEslint()
|
|
45
|
-
const code = `// FIXME: broken feature\nconst y = 2\n`
|
|
46
|
-
|
|
47
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
48
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
49
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
expect(errors?.length).toBe(1)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test("allows TODO with URL", async () => {
|
|
56
|
-
const eslint = createEslint()
|
|
57
|
-
const code = `// TODO: fix this later https://github.com/issue/1\nconst y = 2\n`
|
|
58
|
-
|
|
59
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
60
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
61
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
expect(errors?.length).toBe(0)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test("allows FIXME with URL", async () => {
|
|
68
|
-
const eslint = createEslint()
|
|
69
|
-
const code = `// FIXME: broken feature http://jira.com/123\nconst y = 2\n`
|
|
70
|
-
|
|
71
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
72
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
73
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
expect(errors?.length).toBe(0)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test("allows regular comments", async () => {
|
|
80
|
-
const eslint = createEslint()
|
|
81
|
-
const code = `// This is a regular comment\nconst y = 2\n`
|
|
82
|
-
|
|
83
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
84
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
85
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
expect(errors?.length).toBe(0)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test("reports lowercase todo without URL", async () => {
|
|
92
|
-
const eslint = createEslint()
|
|
93
|
-
const code = `// todo fix this later\nconst y = 2\n`
|
|
94
|
-
|
|
95
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
96
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
97
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
expect(errors?.length).toBe(1)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
test("reports lowercase fixme without URL", async () => {
|
|
104
|
-
const eslint = createEslint()
|
|
105
|
-
const code = `// fixme broken feature\nconst y = 2\n`
|
|
106
|
-
|
|
107
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
108
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
109
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
expect(errors?.length).toBe(1)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test("reports TODO in block comments without URL", async () => {
|
|
116
|
-
const eslint = createEslint()
|
|
117
|
-
const code = `/* TODO: fix this later */\nconst y = 2\n`
|
|
118
|
-
|
|
119
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
120
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
121
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
expect(errors?.length).toBe(1)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
test("allows TODO in block comments with URL", async () => {
|
|
128
|
-
const eslint = createEslint()
|
|
129
|
-
const code = `/* TODO: fix this https://example.com/issue/1 */\nconst y = 2\n`
|
|
130
|
-
|
|
131
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
132
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
133
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
expect(errors?.length).toBe(0)
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
test("uses custom URL prefix", async () => {
|
|
140
|
-
const eslint = createEslint("https://jira.example.com")
|
|
141
|
-
const code = `// TODO: fix this https://jira.example.com/PROJ-123\nconst y = 2\n`
|
|
142
|
-
|
|
143
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
144
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
145
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
expect(errors?.length).toBe(0)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test("reports when URL does not match custom prefix", async () => {
|
|
152
|
-
const eslint = createEslint("https://jira.example.com")
|
|
153
|
-
const code = `// TODO: fix this https://github.com/issue/1\nconst y = 2\n`
|
|
154
|
-
|
|
155
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
156
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
157
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
expect(errors?.length).toBe(1)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test("reports multiple TODO comments without URLs", async () => {
|
|
164
|
-
const eslint = createEslint()
|
|
165
|
-
const code = `// TODO: first issue\n// TODO: second issue\nconst y = 2\n`
|
|
166
|
-
|
|
167
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
168
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
169
|
-
return message.ruleId === "dvukovic/document-todos"
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
expect(errors?.length).toBe(2)
|
|
173
|
-
})
|
|
174
|
-
})
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ESLint } from "eslint"
|
|
2
|
-
import tseslint from "typescript-eslint"
|
|
3
|
-
|
|
4
|
-
import { dvukovic } from "../../plugins/dvukovic.js"
|
|
5
|
-
|
|
6
|
-
const eslint = new ESLint({
|
|
7
|
-
overrideConfig: [
|
|
8
|
-
{
|
|
9
|
-
files: ["**/*.ts"],
|
|
10
|
-
languageOptions: {
|
|
11
|
-
parser: tseslint.parser,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
dvukovic,
|
|
15
|
-
],
|
|
16
|
-
overrideConfigFile: true,
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe("dvukovic/no-commented-out-code", () => {
|
|
20
|
-
test("detects commented-out code", async () => {
|
|
21
|
-
const code = `// const x = 1\nconst y = 2\n`
|
|
22
|
-
|
|
23
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
24
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
25
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
expect(errors?.length).toBe(1)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test("detects multi-line commented-out code", async () => {
|
|
32
|
-
const code = `// function foo() {
|
|
33
|
-
// return 1
|
|
34
|
-
// }
|
|
35
|
-
const y = 2
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
39
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
40
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
expect(errors?.length).toBe(1)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test("detects block commented-out code", async () => {
|
|
47
|
-
const code = `/* const x = 1 */\nconst y = 2\n`
|
|
48
|
-
|
|
49
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
50
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
51
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
expect(errors?.length).toBe(1)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test("allows regular comments", async () => {
|
|
58
|
-
const code = `// This is a regular comment\nconst y = 2\n`
|
|
59
|
-
|
|
60
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
61
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
62
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
expect(errors?.length).toBe(0)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test("allows TODO comments", async () => {
|
|
69
|
-
const code = `// TODO: fix this later\nconst y = 2\n`
|
|
70
|
-
|
|
71
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
72
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
73
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
expect(errors).toHaveLength(0)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test("allows region comments", async () => {
|
|
80
|
-
const code = `// #region\nconst y = 2\n// #endregion\n`
|
|
81
|
-
|
|
82
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
83
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
84
|
-
return message.ruleId === "dvukovic/no-commented-out-code"
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
expect(errors).toHaveLength(0)
|
|
88
|
-
})
|
|
89
|
-
})
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { ESLint } from "eslint"
|
|
2
|
-
import jsoncParser from "jsonc-eslint-parser"
|
|
3
|
-
|
|
4
|
-
import { noRestrictedDependencies } from "./no-restricted-dependencies.js"
|
|
5
|
-
|
|
6
|
-
const createEslint = (options) => {
|
|
7
|
-
return new ESLint({
|
|
8
|
-
overrideConfig: [
|
|
9
|
-
{
|
|
10
|
-
files: ["**/package.json"],
|
|
11
|
-
languageOptions: {
|
|
12
|
-
parser: jsoncParser,
|
|
13
|
-
},
|
|
14
|
-
plugins: {
|
|
15
|
-
custom: {
|
|
16
|
-
rules: {
|
|
17
|
-
"no-restricted-dependencies": noRestrictedDependencies,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
rules: {
|
|
22
|
-
"custom/no-restricted-dependencies": ["error", options],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
overrideConfigFile: true,
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const getErrors = async (eslint, packageJson) => {
|
|
31
|
-
const results = await eslint.lintText(packageJson, { filePath: "package.json" })
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
results[0]?.messages.filter((message) => {
|
|
35
|
-
return message.ruleId === "custom/no-restricted-dependencies"
|
|
36
|
-
}) ?? []
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("no-restricted-dependencies", () => {
|
|
41
|
-
test("detects restricted package in dependencies", async () => {
|
|
42
|
-
const eslint = createEslint({ dependencies: ["lodash"] })
|
|
43
|
-
const packageJson = JSON.stringify(
|
|
44
|
-
{
|
|
45
|
-
dependencies: {
|
|
46
|
-
lodash: "^4.0.0",
|
|
47
|
-
},
|
|
48
|
-
name: "test",
|
|
49
|
-
},
|
|
50
|
-
null,
|
|
51
|
-
4,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
const errors = await getErrors(eslint, packageJson)
|
|
55
|
-
|
|
56
|
-
expect(errors.length).toBe(1)
|
|
57
|
-
expect(errors[0]?.message).toContain("lodash")
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test("detects restricted package in devDependencies", async () => {
|
|
61
|
-
const eslint = createEslint({ devDependencies: ["jest"] })
|
|
62
|
-
const packageJson = JSON.stringify(
|
|
63
|
-
{
|
|
64
|
-
devDependencies: {
|
|
65
|
-
jest: "^29.0.0",
|
|
66
|
-
},
|
|
67
|
-
name: "test",
|
|
68
|
-
},
|
|
69
|
-
null,
|
|
70
|
-
4,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
const errors = await getErrors(eslint, packageJson)
|
|
74
|
-
|
|
75
|
-
expect(errors.length).toBe(1)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test("detects pattern with wildcard", async () => {
|
|
79
|
-
const eslint = createEslint({ devDependencies: ["@types/*"] })
|
|
80
|
-
const packageJson = JSON.stringify(
|
|
81
|
-
{
|
|
82
|
-
devDependencies: {
|
|
83
|
-
"@types/node": "^20.0.0",
|
|
84
|
-
"@types/react": "^18.0.0",
|
|
85
|
-
},
|
|
86
|
-
name: "test",
|
|
87
|
-
},
|
|
88
|
-
null,
|
|
89
|
-
4,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
const errors = await getErrors(eslint, packageJson)
|
|
93
|
-
|
|
94
|
-
expect(errors.length).toBe(2)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test("allows non-restricted packages", async () => {
|
|
98
|
-
const eslint = createEslint({ dependencies: ["lodash"] })
|
|
99
|
-
const packageJson = JSON.stringify(
|
|
100
|
-
{
|
|
101
|
-
dependencies: {
|
|
102
|
-
react: "^18.0.0",
|
|
103
|
-
},
|
|
104
|
-
name: "test",
|
|
105
|
-
},
|
|
106
|
-
null,
|
|
107
|
-
4,
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
const errors = await getErrors(eslint, packageJson)
|
|
111
|
-
|
|
112
|
-
expect(errors.length).toBe(0)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test("detects multiple restricted packages", async () => {
|
|
116
|
-
const eslint = createEslint({ dependencies: ["lodash", "ramda", "underscore"] })
|
|
117
|
-
const packageJson = JSON.stringify(
|
|
118
|
-
{
|
|
119
|
-
dependencies: {
|
|
120
|
-
lodash: "^4.0.0",
|
|
121
|
-
ramda: "^0.29.0",
|
|
122
|
-
react: "^18.0.0",
|
|
123
|
-
},
|
|
124
|
-
name: "test",
|
|
125
|
-
},
|
|
126
|
-
null,
|
|
127
|
-
4,
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
const errors = await getErrors(eslint, packageJson)
|
|
131
|
-
|
|
132
|
-
expect(errors.length).toBe(2)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test("handles empty options", async () => {
|
|
136
|
-
const eslint = createEslint({})
|
|
137
|
-
const packageJson = JSON.stringify(
|
|
138
|
-
{
|
|
139
|
-
dependencies: {
|
|
140
|
-
lodash: "^4.0.0",
|
|
141
|
-
},
|
|
142
|
-
name: "test",
|
|
143
|
-
},
|
|
144
|
-
null,
|
|
145
|
-
4,
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
const errors = await getErrors(eslint, packageJson)
|
|
149
|
-
|
|
150
|
-
expect(errors.length).toBe(0)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
test("restricts @types/* in dependencies but allows in devDependencies", async () => {
|
|
154
|
-
const eslint = createEslint({ dependencies: ["@types/*"] })
|
|
155
|
-
const packageJson = JSON.stringify(
|
|
156
|
-
{
|
|
157
|
-
dependencies: {
|
|
158
|
-
"@types/node": "^20.0.0",
|
|
159
|
-
},
|
|
160
|
-
devDependencies: {
|
|
161
|
-
"@types/react": "^18.0.0",
|
|
162
|
-
},
|
|
163
|
-
name: "test",
|
|
164
|
-
},
|
|
165
|
-
null,
|
|
166
|
-
4,
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
const errors = await getErrors(eslint, packageJson)
|
|
170
|
-
|
|
171
|
-
expect(errors.length).toBe(1)
|
|
172
|
-
expect(errors[0]?.message).toContain("@types/node")
|
|
173
|
-
expect(errors[0]?.message).toContain("dependencies")
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
test("restricts different patterns in different dependency types", async () => {
|
|
177
|
-
const eslint = createEslint({
|
|
178
|
-
dependencies: ["@types/*", "lodash"],
|
|
179
|
-
devDependencies: ["jest"],
|
|
180
|
-
})
|
|
181
|
-
const packageJson = JSON.stringify(
|
|
182
|
-
{
|
|
183
|
-
dependencies: {
|
|
184
|
-
"@types/node": "^20.0.0",
|
|
185
|
-
lodash: "^4.0.0",
|
|
186
|
-
},
|
|
187
|
-
devDependencies: {
|
|
188
|
-
"@types/react": "^18.0.0",
|
|
189
|
-
jest: "^29.0.0",
|
|
190
|
-
},
|
|
191
|
-
name: "test",
|
|
192
|
-
},
|
|
193
|
-
null,
|
|
194
|
-
4,
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
const errors = await getErrors(eslint, packageJson)
|
|
198
|
-
|
|
199
|
-
expect(errors.length).toBe(3)
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
test("restricts in peerDependencies", async () => {
|
|
203
|
-
const eslint = createEslint({ peerDependencies: ["react"] })
|
|
204
|
-
const packageJson = JSON.stringify(
|
|
205
|
-
{
|
|
206
|
-
name: "test",
|
|
207
|
-
peerDependencies: {
|
|
208
|
-
react: "^18.0.0",
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
null,
|
|
212
|
-
4,
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
const errors = await getErrors(eslint, packageJson)
|
|
216
|
-
|
|
217
|
-
expect(errors.length).toBe(1)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
test("restricts in optionalDependencies", async () => {
|
|
221
|
-
const eslint = createEslint({ optionalDependencies: ["fsevents"] })
|
|
222
|
-
const packageJson = JSON.stringify(
|
|
223
|
-
{
|
|
224
|
-
name: "test",
|
|
225
|
-
optionalDependencies: {
|
|
226
|
-
fsevents: "^2.0.0",
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
null,
|
|
230
|
-
4,
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
const errors = await getErrors(eslint, packageJson)
|
|
234
|
-
|
|
235
|
-
expect(errors.length).toBe(1)
|
|
236
|
-
})
|
|
237
|
-
})
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { ESLint } from "eslint"
|
|
2
|
-
import tseslint from "typescript-eslint"
|
|
3
|
-
|
|
4
|
-
import { dvukovic } from "../../plugins/dvukovic.js"
|
|
5
|
-
|
|
6
|
-
const eslint = new ESLint({
|
|
7
|
-
overrideConfig: [
|
|
8
|
-
{
|
|
9
|
-
files: ["**/*.ts"],
|
|
10
|
-
languageOptions: {
|
|
11
|
-
parser: tseslint.parser,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
dvukovic,
|
|
15
|
-
],
|
|
16
|
-
overrideConfigFile: true,
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe("dvukovic/no-t", () => {
|
|
20
|
-
test("detects single-character type parameter", async () => {
|
|
21
|
-
const code = `function foo<T>(arg: T): T { return arg }\n`
|
|
22
|
-
|
|
23
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
24
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
25
|
-
return message.ruleId === "dvukovic/no-t"
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
expect(errors?.length).toBe(1)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test("detects multiple single-character type parameters", async () => {
|
|
32
|
-
const code = `type Entry<K, V> = { key: K; value: V }\n`
|
|
33
|
-
|
|
34
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
35
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
36
|
-
return message.ruleId === "dvukovic/no-t"
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
expect(errors?.length).toBe(2)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test("allows descriptive type parameters", async () => {
|
|
43
|
-
const code = `function foo<Element>(arg: Element): Element { return arg }\n`
|
|
44
|
-
|
|
45
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
46
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
47
|
-
return message.ruleId === "dvukovic/no-t"
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
expect(errors?.length).toBe(0)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test("allows descriptive type parameters in type alias", async () => {
|
|
54
|
-
const code = `type Entry<Key, Value> = { key: Key; value: Value }\n`
|
|
55
|
-
|
|
56
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
57
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
58
|
-
return message.ruleId === "dvukovic/no-t"
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
expect(errors?.length).toBe(0)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test("detects single-character in interface", async () => {
|
|
65
|
-
const code = `interface Container<T> { value: T }\n`
|
|
66
|
-
|
|
67
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
68
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
69
|
-
return message.ruleId === "dvukovic/no-t"
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
expect(errors?.length).toBe(1)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test("detects single-character in class", async () => {
|
|
76
|
-
const code = `class Box<T> { constructor(public value: T) {} }\n`
|
|
77
|
-
|
|
78
|
-
const results = await eslint.lintText(code, { filePath: "test.ts" })
|
|
79
|
-
const errors = results[0]?.messages.filter((message) => {
|
|
80
|
-
return message.ruleId === "dvukovic/no-t"
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
expect(errors?.length).toBe(1)
|
|
84
|
-
})
|
|
85
|
-
})
|