@virmator/lint 14.30.0 → 14.30.1
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.
|
@@ -35,6 +35,12 @@ const objectShapeTesterAssertionNames = [
|
|
|
35
35
|
'assertValidShape',
|
|
36
36
|
'assertWrapValidShape',
|
|
37
37
|
];
|
|
38
|
+
/**
|
|
39
|
+
* Names of `@augment-vir/test` exports that assert, so a test that calls one is asserting.
|
|
40
|
+
* Recognized by name rather than by treating the whole module as assertion utilities because most
|
|
41
|
+
* of its exports (`describe`, `it`, etc.) define tests instead of asserting within them.
|
|
42
|
+
*/
|
|
43
|
+
const augmentVirTestAssertionNames = ['assertSnapshot'];
|
|
38
44
|
/** Names of the test-defining functions whose callbacks must contain at least one assertion. */
|
|
39
45
|
const testFunctionNames = [
|
|
40
46
|
'it',
|
|
@@ -209,6 +215,7 @@ const rule = {
|
|
|
209
215
|
const names = [
|
|
210
216
|
...augmentVirAssertionNames,
|
|
211
217
|
...objectShapeTesterAssertionNames,
|
|
218
|
+
...augmentVirTestAssertionNames,
|
|
212
219
|
...(options.additionalAssertionNames || []),
|
|
213
220
|
];
|
|
214
221
|
const assertionIdentifiers = collectAssertionIdentifiers(context.sourceCode.ast.body, {
|
|
@@ -1,17 +1,40 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* caller, so they cannot adopt a params object. Such callbacks should be skipped.
|
|
3
|
+
* Determines whether the given node sits inside an argument of a call or `new` expression, looking
|
|
4
|
+
* through object and array literals so that callbacks nested in a config object still count.
|
|
5
5
|
*/
|
|
6
|
-
function
|
|
7
|
-
|
|
6
|
+
function isWithinCallArgument(node) {
|
|
7
|
+
const parent = node.parent;
|
|
8
|
+
if (!parent) {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
else if (parent.type === 'CallExpression' || parent.type === 'NewExpression') {
|
|
12
|
+
return check.hasValue(parent.arguments, node);
|
|
13
|
+
}
|
|
14
|
+
else if (parent.type === 'Property') {
|
|
15
|
+
return parent.value === node && isWithinCallArgument(parent);
|
|
16
|
+
}
|
|
17
|
+
else if (parent.type === 'ObjectExpression' ||
|
|
18
|
+
parent.type === 'ArrayExpression' ||
|
|
19
|
+
parent.type === 'SpreadElement') {
|
|
20
|
+
return isWithinCallArgument(parent);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Callbacks passed to an interface we don't control have a signature dictated by that interface, so
|
|
28
|
+
* they cannot adopt a params object. This covers both function or arrow expressions passed directly
|
|
29
|
+
* as call arguments (like `array.reduce((accum, entry, index, wholeArray) => ...)`) and methods or
|
|
30
|
+
* function properties within an object literal passed as a call argument (like `new
|
|
31
|
+
* IntervalObservable({equalityCheck(a, b) {...}})`). Such callbacks should be skipped.
|
|
32
|
+
*/
|
|
33
|
+
function isInlineCallbackArgument(node) {
|
|
34
|
+
if (node.type === 'FunctionDeclaration') {
|
|
12
35
|
return false;
|
|
13
36
|
}
|
|
14
|
-
return
|
|
37
|
+
return isWithinCallArgument(node);
|
|
15
38
|
}
|
|
16
39
|
/**
|
|
17
40
|
* Class constructors are exempt: they can declare class fields through parameter properties and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virmator/lint",
|
|
3
|
-
"version": "14.30.
|
|
3
|
+
"version": "14.30.1",
|
|
4
4
|
"description": "Default ESLint linting plugin for virmator.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"virmator",
|
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
"test:update": "npm test update"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@augment-vir/assert": "^32.1
|
|
36
|
-
"@augment-vir/common": "^32.1
|
|
37
|
-
"@augment-vir/node": "^32.1
|
|
38
|
-
"@virmator/core": "^14.30.
|
|
35
|
+
"@augment-vir/assert": "^32.2.1",
|
|
36
|
+
"@augment-vir/common": "^32.2.1",
|
|
37
|
+
"@augment-vir/node": "^32.2.1",
|
|
38
|
+
"@virmator/core": "^14.30.1",
|
|
39
39
|
"globals": "^17.7.0",
|
|
40
40
|
"jiti": "^2.7.0",
|
|
41
41
|
"mri": "^1.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@augment-vir/test": "^32.1
|
|
44
|
+
"@augment-vir/test": "^32.2.1",
|
|
45
45
|
"@eslint/js": "10.0.1",
|
|
46
46
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
47
47
|
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
|
48
48
|
"@types/estree": "^1.0.9",
|
|
49
49
|
"@types/node": "^26.1.1",
|
|
50
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^8.65.0",
|
|
51
51
|
"c8": "^12.0.0",
|
|
52
52
|
"eslint": "^10.7.0",
|
|
53
53
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"eslint-plugin-sonarjs": "^4.2.0",
|
|
58
58
|
"eslint-plugin-unicorn": "^72.0.0",
|
|
59
59
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
60
|
-
"typescript-eslint": "^8.
|
|
60
|
+
"typescript-eslint": "^8.65.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=22"
|
|
@@ -49,6 +49,13 @@ const objectShapeTesterAssertionNames: ReadonlyArray<string> = [
|
|
|
49
49
|
'assertWrapValidShape',
|
|
50
50
|
];
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Names of `@augment-vir/test` exports that assert, so a test that calls one is asserting.
|
|
54
|
+
* Recognized by name rather than by treating the whole module as assertion utilities because most
|
|
55
|
+
* of its exports (`describe`, `it`, etc.) define tests instead of asserting within them.
|
|
56
|
+
*/
|
|
57
|
+
const augmentVirTestAssertionNames: ReadonlyArray<string> = ['assertSnapshot'];
|
|
58
|
+
|
|
52
59
|
/** Names of the test-defining functions whose callbacks must contain at least one assertion. */
|
|
53
60
|
const testFunctionNames: ReadonlyArray<string> = [
|
|
54
61
|
'it',
|
|
@@ -295,6 +302,7 @@ const rule: Rule.RuleModule = {
|
|
|
295
302
|
const names = [
|
|
296
303
|
...augmentVirAssertionNames,
|
|
297
304
|
...objectShapeTesterAssertionNames,
|
|
305
|
+
...augmentVirTestAssertionNames,
|
|
298
306
|
...(options.additionalAssertionNames || []),
|
|
299
307
|
];
|
|
300
308
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {check} from '@augment-vir/assert';
|
|
1
2
|
import {type Rule, type SourceCode} from 'eslint';
|
|
2
3
|
import type {
|
|
3
4
|
ArrowFunctionExpression,
|
|
@@ -27,22 +28,42 @@ type FixableParam = {
|
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* caller, so they cannot adopt a params object. Such callbacks should be skipped.
|
|
31
|
+
* Determines whether the given node sits inside an argument of a call or `new` expression, looking
|
|
32
|
+
* through object and array literals so that callbacks nested in a config object still count.
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
35
|
-
|
|
34
|
+
function isWithinCallArgument(node: Node): boolean {
|
|
35
|
+
const parent = (node as Rule.Node).parent;
|
|
36
|
+
|
|
37
|
+
if (!parent) {
|
|
38
|
+
return false;
|
|
39
|
+
} else if (parent.type === 'CallExpression' || parent.type === 'NewExpression') {
|
|
40
|
+
return check.hasValue(parent.arguments, node);
|
|
41
|
+
} else if (parent.type === 'Property') {
|
|
42
|
+
return parent.value === node && isWithinCallArgument(parent);
|
|
43
|
+
} else if (
|
|
44
|
+
parent.type === 'ObjectExpression' ||
|
|
45
|
+
parent.type === 'ArrayExpression' ||
|
|
46
|
+
parent.type === 'SpreadElement'
|
|
47
|
+
) {
|
|
48
|
+
return isWithinCallArgument(parent);
|
|
49
|
+
} else {
|
|
36
50
|
return false;
|
|
37
51
|
}
|
|
52
|
+
}
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Callbacks passed to an interface we don't control have a signature dictated by that interface, so
|
|
56
|
+
* they cannot adopt a params object. This covers both function or arrow expressions passed directly
|
|
57
|
+
* as call arguments (like `array.reduce((accum, entry, index, wholeArray) => ...)`) and methods or
|
|
58
|
+
* function properties within an object literal passed as a call argument (like `new
|
|
59
|
+
* IntervalObservable({equalityCheck(a, b) {...}})`). Such callbacks should be skipped.
|
|
60
|
+
*/
|
|
61
|
+
function isInlineCallbackArgument(node: AnyFunctionNode): boolean {
|
|
62
|
+
if (node.type === 'FunctionDeclaration') {
|
|
42
63
|
return false;
|
|
43
64
|
}
|
|
44
65
|
|
|
45
|
-
return
|
|
66
|
+
return isWithinCallArgument(node);
|
|
46
67
|
}
|
|
47
68
|
|
|
48
69
|
/**
|