Skip to content

Commit bc4de89

Browse files
authored
test: migrate to type-friendly createRuleTestCaseFunction (#184)
1 parent 8c1c14d commit bc4de89

File tree

69 files changed

+4414
-4931
lines changed

Some content is hidden

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

69 files changed

+4414
-4931
lines changed

.changeset/cuddly-ligers-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix(no-cycle): improves the type declaration of the rule `no-cycle`’s `maxDepth` option

.changeset/fluffy-dolls-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix(first): improves the type declaration of the rule `first`'s option

.changeset/nice-schools-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix(no-unused-modules): improves the type declaration of the rule `no-unused-modules`’s `missingExports` option

.changeset/nine-wolves-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix(no-deprecated): improve error message when no description is available

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
module.exports = {
55
root: true,
6+
reportUnusedDisableDirectives: true,
67
extends: [
78
'eslint:recommended',
89
'plugin:@typescript-eslint/recommended',
@@ -33,7 +34,7 @@ module.exports = {
3334
'eslint-plugin/report-message-format': 'error',
3435
'eslint-plugin/require-meta-docs-description': [
3536
'error',
36-
{ pattern: '^(Enforce|Ensure|Prefer|Forbid).+\\.$' },
37+
{ pattern: String.raw`^(Enforce|Ensure|Prefer|Forbid).+\.$` },
3738
],
3839
'eslint-plugin/require-meta-schema': 'error',
3940
'eslint-plugin/require-meta-type': 'error',

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"eslint": "^8.57.0 || ^9.0.0"
4949
},
5050
"dependencies": {
51+
"@typescript-eslint/scope-manager": "^8.1.0",
5152
"@typescript-eslint/utils": "^8.1.0",
5253
"debug": "^4.3.4",
5354
"doctrine": "^3.0.0",
@@ -82,8 +83,8 @@
8283
"@total-typescript/ts-reset": "^0.5.1",
8384
"@types/debug": "^4.1.12",
8485
"@types/doctrine": "^0.0.9",
85-
"@types/eslint8.56": "npm:@types/eslint@^8.56.11",
8686
"@types/eslint": "^9.6.1",
87+
"@types/eslint8.56": "npm:@types/eslint@^8.56.11",
8788
"@types/eslint9": "npm:@types/eslint@^9.6.1",
8889
"@types/is-glob": "^4.0.4",
8990
"@types/jest": "^29.5.12",
@@ -97,9 +98,7 @@
9798
"cross-env": "^7.0.3",
9899
"enhanced-resolve": "^5.16.0",
99100
"escope": "^4.0.0",
100-
"eslint8.56": "npm:eslint@^8.56.0",
101101
"eslint": "^9.15.0",
102-
"eslint9": "npm:eslint@^9.15.0",
103102
"eslint-config-prettier": "^9.1.0",
104103
"eslint-doc-generator": "^1.7.1",
105104
"eslint-import-resolver-typescript": "^3.6.1",
@@ -112,6 +111,8 @@
112111
"eslint-plugin-n": "^16.6.2",
113112
"eslint-plugin-prettier": "^5.1.3",
114113
"eslint-plugin-unicorn": "^56.0.1",
114+
"eslint8.56": "npm:eslint@^8.56.0",
115+
"eslint9": "npm:eslint@^9.15.0",
115116
"hermes-eslint": "^0.23.1",
116117
"jest": "^29.7.0",
117118
"klaw-sync": "^6.0.0",

src/rules/dynamic-import-chunkname.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export = createRule<[Options?], MessageId>({
7373
const {
7474
importFunctions = [],
7575
allowEmpty = false,
76-
webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+',
76+
webpackChunknameFormat = String.raw`([0-9a-zA-Z-_/.]|\[(request|index)\])+`,
7777
} = context.options[0] || {}
7878

7979
const paddedCommentRegex = /^ (\S[\S\s]+\S) $/

src/rules/first.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ function isPossibleDirective(node: TSESTree.ProgramStatement) {
2020
)
2121
}
2222

23+
type Options = 'absolute-first' | 'disable-absolute-first'
24+
2325
type MessageId = 'absolute' | 'order'
2426

25-
export = createRule<['absolute-first'?], MessageId>({
27+
export = createRule<[Options?], MessageId>({
2628
name: 'first',
2729
meta: {
2830
type: 'suggestion',

src/rules/group-exports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function accessorChain(node: TSESTree.MemberExpression) {
3535
return chain
3636
}
3737

38-
export = createRule<[], 'ExportNamedDeclaration' | 'AssignmentExpression'>({
38+
type MessageId = 'ExportNamedDeclaration' | 'AssignmentExpression'
39+
40+
export = createRule<[], MessageId>({
3941
name: 'group-exports',
4042
meta: {
4143
type: 'suggestion',

src/rules/namespace.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type MessageId =
1515
| 'namespaceMember'
1616
| 'topLevelNames'
1717
| 'notFoundInNamespace'
18+
| 'notFoundInNamespaceDeep'
1819

1920
type Options = {
2021
allowComputed?: boolean
@@ -86,15 +87,16 @@ function makeMessage(
8687
namepath: string[],
8788
node: TSESTree.Node = last,
8889
) {
90+
const messageId =
91+
namepath.length > 1 ? 'notFoundInNamespaceDeep' : 'notFoundInNamespace'
8992
return {
9093
node,
91-
messageId: 'notFoundInNamespace' as const,
94+
messageId,
9295
data: {
9396
name: last.name,
94-
depth: namepath.length > 1 ? 'deeply ' : '',
9597
namepath: namepath.join('.'),
9698
},
97-
}
99+
} as const
98100
}
99101

100102
export = createRule<[Options], MessageId>({
@@ -127,7 +129,9 @@ export = createRule<[Options], MessageId>({
127129
namespaceMember: "Assignment to member of namespace '{{namespace}}'.",
128130
topLevelNames: 'Only destructure top-level names.',
129131
notFoundInNamespace:
130-
"'{{name}}' not found in {{depth}}imported namespace '{{namepath}}'.",
132+
"'{{name}}' not found in imported namespace '{{namepath}}'.",
133+
notFoundInNamespaceDeep:
134+
"'{{name}}' not found in deeply imported namespace '{{namepath}}'.",
131135
},
132136
},
133137
defaultOptions: [

0 commit comments

Comments
 (0)