@jupyter/eslint-plugin 0.0.5 → 1.0.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.
- package/lib/index.d.ts +55 -10
- package/lib/index.js +85 -13
- package/lib/rules/command-described-by.d.ts +1 -1
- package/lib/rules/no-schema-enum.d.ts +4 -0
- package/lib/rules/no-schema-enum.js +37 -0
- package/lib/rules/no-translation-concatenation.d.ts +1 -1
- package/lib/rules/no-untranslated-string.d.ts +2 -2
- package/lib/rules/plugin-activation-args.d.ts +1 -1
- package/lib/rules/plugin-activation-args.js +44 -2
- package/lib/rules/plugin-description.d.ts +1 -1
- package/lib/rules/require-soft-assertions-before-snapshots.d.ts +4 -0
- package/lib/rules/require-soft-assertions-before-snapshots.js +93 -0
- package/lib/rules/token-format.d.ts +1 -1
- package/lib/utils/plugin-utils.d.ts +5 -1
- package/lib/utils/plugin-utils.js +71 -1
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
import * as jsoncParser from 'jsonc-eslint-parser';
|
|
1
2
|
declare const plugin: {
|
|
2
3
|
rules: {
|
|
3
|
-
'plugin-activation-args': import("@typescript-eslint/utils/
|
|
4
|
+
'plugin-activation-args': import("@typescript-eslint/utils/ts-eslint").RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType" | "optionalNotNullable", [{
|
|
4
5
|
allowedFirstArgumentNames: string[];
|
|
5
|
-
}], unknown, import("@typescript-eslint/utils/
|
|
6
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
6
7
|
name: string;
|
|
7
8
|
};
|
|
8
|
-
'command-described-by': import("@typescript-eslint/utils/
|
|
9
|
+
'command-described-by': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
9
10
|
name: string;
|
|
10
11
|
};
|
|
11
|
-
'plugin-description': import("@typescript-eslint/utils/
|
|
12
|
+
'plugin-description': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
12
13
|
name: string;
|
|
13
14
|
};
|
|
14
|
-
'no-translation-concatenation': import("@typescript-eslint/utils/
|
|
15
|
+
'no-translation-concatenation': import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConcatenation", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
15
16
|
name: string;
|
|
16
17
|
};
|
|
17
|
-
'token-format': import("@typescript-eslint/utils/
|
|
18
|
+
'token-format': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
18
19
|
name: string;
|
|
19
20
|
};
|
|
20
|
-
'no-untranslated-string': import("@typescript-eslint/utils/
|
|
21
|
+
'no-untranslated-string': import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedTitleProp" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText", [{
|
|
21
22
|
enforcePunctuation: boolean;
|
|
22
|
-
}], unknown, import("@typescript-eslint/utils/
|
|
23
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
'no-schema-enum': import("@typescript-eslint/utils/ts-eslint").RuleModule<"forbidEnum", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
'require-soft-assertions-before-snapshots': import("@typescript-eslint/utils/ts-eslint").RuleModule<"requireSoftAssertion", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
23
30
|
name: string;
|
|
24
31
|
};
|
|
25
32
|
};
|
|
26
33
|
configs: {
|
|
27
|
-
recommended: {
|
|
34
|
+
recommended: ({
|
|
28
35
|
files: string[];
|
|
29
36
|
rules: {
|
|
30
37
|
'jupyter/plugin-activation-args': string;
|
|
@@ -33,8 +40,39 @@ declare const plugin: {
|
|
|
33
40
|
'jupyter/no-translation-concatenation': string;
|
|
34
41
|
'jupyter/token-format': string;
|
|
35
42
|
'jupyter/no-untranslated-string': string;
|
|
43
|
+
'jupyter/no-schema-enum'?: undefined;
|
|
44
|
+
'jupyter/require-soft-assertions-before-snapshots'?: undefined;
|
|
36
45
|
};
|
|
37
|
-
|
|
46
|
+
languageOptions?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
files: string[];
|
|
49
|
+
languageOptions: {
|
|
50
|
+
parser: typeof jsoncParser;
|
|
51
|
+
};
|
|
52
|
+
rules: {
|
|
53
|
+
'jupyter/no-schema-enum': string;
|
|
54
|
+
'jupyter/plugin-activation-args'?: undefined;
|
|
55
|
+
'jupyter/command-described-by'?: undefined;
|
|
56
|
+
'jupyter/plugin-description'?: undefined;
|
|
57
|
+
'jupyter/no-translation-concatenation'?: undefined;
|
|
58
|
+
'jupyter/token-format'?: undefined;
|
|
59
|
+
'jupyter/no-untranslated-string'?: undefined;
|
|
60
|
+
'jupyter/require-soft-assertions-before-snapshots'?: undefined;
|
|
61
|
+
};
|
|
62
|
+
} | {
|
|
63
|
+
files: string[];
|
|
64
|
+
rules: {
|
|
65
|
+
'jupyter/require-soft-assertions-before-snapshots': string;
|
|
66
|
+
'jupyter/plugin-activation-args'?: undefined;
|
|
67
|
+
'jupyter/command-described-by'?: undefined;
|
|
68
|
+
'jupyter/plugin-description'?: undefined;
|
|
69
|
+
'jupyter/no-translation-concatenation'?: undefined;
|
|
70
|
+
'jupyter/token-format'?: undefined;
|
|
71
|
+
'jupyter/no-untranslated-string'?: undefined;
|
|
72
|
+
'jupyter/no-schema-enum'?: undefined;
|
|
73
|
+
};
|
|
74
|
+
languageOptions?: undefined;
|
|
75
|
+
})[];
|
|
38
76
|
'recommended-legacy': {
|
|
39
77
|
rules: {
|
|
40
78
|
'jupyter/plugin-activation-args': string;
|
|
@@ -43,7 +81,14 @@ declare const plugin: {
|
|
|
43
81
|
'jupyter/no-translation-concatenation': string;
|
|
44
82
|
'jupyter/token-format': string;
|
|
45
83
|
'jupyter/no-untranslated-string': string;
|
|
84
|
+
'jupyter/no-schema-enum': string;
|
|
46
85
|
};
|
|
86
|
+
overrides: {
|
|
87
|
+
files: string[];
|
|
88
|
+
rules: {
|
|
89
|
+
'jupyter/require-soft-assertions-before-snapshots': string;
|
|
90
|
+
};
|
|
91
|
+
}[];
|
|
47
92
|
};
|
|
48
93
|
};
|
|
49
94
|
};
|
package/lib/index.js
CHANGED
|
@@ -3,15 +3,51 @@
|
|
|
3
3
|
* Copyright (c) Jupyter Development Team.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
6
39
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
40
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
41
|
};
|
|
42
|
+
const jsoncParser = __importStar(require("jsonc-eslint-parser"));
|
|
9
43
|
const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activation-args"));
|
|
10
44
|
const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
|
|
11
45
|
const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
|
|
12
46
|
const no_translation_concatenation_1 = __importDefault(require("./rules/no-translation-concatenation"));
|
|
13
47
|
const token_format_1 = __importDefault(require("./rules/token-format"));
|
|
14
48
|
const no_untranslated_string_1 = __importDefault(require("./rules/no-untranslated-string"));
|
|
49
|
+
const no_schema_enum_1 = __importDefault(require("./rules/no-schema-enum"));
|
|
50
|
+
const require_soft_assertions_before_snapshots_1 = __importDefault(require("./rules/require-soft-assertions-before-snapshots"));
|
|
15
51
|
const plugin = {
|
|
16
52
|
rules: {
|
|
17
53
|
'plugin-activation-args': plugin_activation_args_1.default,
|
|
@@ -19,20 +55,42 @@ const plugin = {
|
|
|
19
55
|
'plugin-description': plugin_description_1.default,
|
|
20
56
|
'no-translation-concatenation': no_translation_concatenation_1.default,
|
|
21
57
|
'token-format': token_format_1.default,
|
|
22
|
-
'no-untranslated-string': no_untranslated_string_1.default
|
|
58
|
+
'no-untranslated-string': no_untranslated_string_1.default,
|
|
59
|
+
'no-schema-enum': no_schema_enum_1.default,
|
|
60
|
+
'require-soft-assertions-before-snapshots': require_soft_assertions_before_snapshots_1.default
|
|
23
61
|
},
|
|
24
62
|
configs: {
|
|
25
|
-
recommended:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
recommended: [
|
|
64
|
+
{
|
|
65
|
+
files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
|
|
66
|
+
rules: {
|
|
67
|
+
'jupyter/plugin-activation-args': 'error',
|
|
68
|
+
'jupyter/command-described-by': 'warn',
|
|
69
|
+
'jupyter/plugin-description': 'warn',
|
|
70
|
+
'jupyter/no-translation-concatenation': 'error',
|
|
71
|
+
'jupyter/token-format': 'error',
|
|
72
|
+
'jupyter/no-untranslated-string': 'warn'
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
files: ['**/schema/*.json'],
|
|
77
|
+
languageOptions: { parser: jsoncParser },
|
|
78
|
+
rules: {
|
|
79
|
+
'jupyter/no-schema-enum': 'warn'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
files: [
|
|
84
|
+
'**/*.spec.ts',
|
|
85
|
+
'**/*.spec.js',
|
|
86
|
+
'**/*.test.ts',
|
|
87
|
+
'**/*.test.js'
|
|
88
|
+
],
|
|
89
|
+
rules: {
|
|
90
|
+
'jupyter/require-soft-assertions-before-snapshots': 'warn'
|
|
91
|
+
}
|
|
34
92
|
}
|
|
35
|
-
|
|
93
|
+
],
|
|
36
94
|
'recommended-legacy': {
|
|
37
95
|
rules: {
|
|
38
96
|
'jupyter/plugin-activation-args': 'error',
|
|
@@ -40,8 +98,22 @@ const plugin = {
|
|
|
40
98
|
'jupyter/plugin-description': 'warn',
|
|
41
99
|
'jupyter/no-translation-concatenation': 'error',
|
|
42
100
|
'jupyter/token-format': 'error',
|
|
43
|
-
'jupyter/no-untranslated-string': 'warn'
|
|
44
|
-
|
|
101
|
+
'jupyter/no-untranslated-string': 'warn',
|
|
102
|
+
'jupyter/no-schema-enum': 'warn'
|
|
103
|
+
},
|
|
104
|
+
overrides: [
|
|
105
|
+
{
|
|
106
|
+
files: [
|
|
107
|
+
'**/*.spec.ts',
|
|
108
|
+
'**/*.spec.js',
|
|
109
|
+
'**/*.test.ts',
|
|
110
|
+
'**/*.test.js'
|
|
111
|
+
],
|
|
112
|
+
rules: {
|
|
113
|
+
'jupyter/require-soft-assertions-before-snapshots': 'warn'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
]
|
|
45
117
|
}
|
|
46
118
|
}
|
|
47
119
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const jupyterCommandDescribedBy: import("@typescript-eslint/utils/
|
|
1
|
+
declare const jupyterCommandDescribedBy: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescribedBy", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
2
|
name: string;
|
|
3
3
|
};
|
|
4
4
|
export = jupyterCommandDescribedBy;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
7
|
+
function isSchemaJsonFile(filename) {
|
|
8
|
+
return /[/\\]schema[/\\][^/\\]*\.json$/.test(filename);
|
|
9
|
+
}
|
|
10
|
+
const noSchemaEnum = (0, create_rule_1.createRule)({
|
|
11
|
+
name: 'no-schema-enum',
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'suggestion',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Disallow `enum` in settings JSON schema files; use `oneOf` with `const` and `title` instead'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
forbidEnum: 'Avoid `enum` in settings schema. Use `oneOf` with `const` and `title` per entry to support user-facing labels and translations.'
|
|
19
|
+
},
|
|
20
|
+
schema: []
|
|
21
|
+
},
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create(context) {
|
|
24
|
+
if (!isSchemaJsonFile(context.filename)) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
JSONProperty(node) {
|
|
29
|
+
const keyValue = node.key.type === 'JSONLiteral' ? node.key.value : node.key.name;
|
|
30
|
+
if (keyValue === 'enum' && node.value.type === 'JSONArrayExpression') {
|
|
31
|
+
context.report({ loc: node.loc, messageId: 'forbidEnum' });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
module.exports = noSchemaEnum;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const noTranslationConcatenation: import("@typescript-eslint/utils/
|
|
1
|
+
declare const noTranslationConcatenation: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noConcatenation", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
2
|
name: string;
|
|
3
3
|
};
|
|
4
4
|
export = noTranslationConcatenation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare const noUntranslatedString: import("@typescript-eslint/utils/
|
|
1
|
+
declare const noUntranslatedString: import("@typescript-eslint/utils/ts-eslint").RuleModule<"untranslatedCommandProp" | "untranslatedSetAttribute" | "untranslatedPropertyAssign" | "untranslatedTitleProp" | "untranslatedDialogOption" | "untranslatedDialogButtonLabel" | "untranslatedJsxText", [{
|
|
2
2
|
enforcePunctuation: boolean;
|
|
3
|
-
}], unknown, import("@typescript-eslint/utils/
|
|
3
|
+
}], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
4
4
|
name: string;
|
|
5
5
|
};
|
|
6
6
|
export = noUntranslatedString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
declare const jupyterPluginActivationArgs: ESLintUtils.RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType", [{
|
|
2
|
+
declare const jupyterPluginActivationArgs: ESLintUtils.RuleModule<"mismatchedOrder" | "incorrectType" | "missingArgument" | "extraArgument" | "appNotFirst" | "serviceManagerFirstArgNotNull" | "invalidAppType" | "wrongArgumentCount" | "unresolvableTokenType" | "optionalNotNullable", [{
|
|
3
3
|
allowedFirstArgumentNames: string[];
|
|
4
4
|
}], unknown, ESLintUtils.RuleListener> & {
|
|
5
5
|
name: string;
|
|
@@ -125,7 +125,8 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
125
125
|
serviceManagerFirstArgNotNull: 'First activation argument for ServiceManagerPlugin must be null, got "{{ arg }}".',
|
|
126
126
|
invalidAppType: 'First activation argument "{{ arg }}" has invalid type "{{ type }}". Expected JupyterFrontEnd, JupyterLab, or Application.',
|
|
127
127
|
wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.',
|
|
128
|
-
unresolvableTokenType: 'Token "{{ token }}" type could not be resolved. The package may be unbuilt or type checking may not be configured.'
|
|
128
|
+
unresolvableTokenType: 'Token "{{ token }}" type could not be resolved. The package may be unbuilt or type checking may not be configured.',
|
|
129
|
+
optionalNotNullable: 'Activation argument "{{ arg }}" for optional token "{{ type }}" must be nullable (use "| null", "| undefined", or optional parameter "?").'
|
|
129
130
|
},
|
|
130
131
|
fixable: 'code',
|
|
131
132
|
schema: [
|
|
@@ -216,6 +217,37 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
216
217
|
}
|
|
217
218
|
return null;
|
|
218
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Returns true when the activate parameter's resolved type includes null or
|
|
222
|
+
* undefined. Falls back to a syntactic AST check when the checker is
|
|
223
|
+
* unavailable.
|
|
224
|
+
*/
|
|
225
|
+
function isParamNullable(paramNode) {
|
|
226
|
+
if (paramNode.optional)
|
|
227
|
+
return true; // param?: T always implies | undefined
|
|
228
|
+
if (checker) {
|
|
229
|
+
try {
|
|
230
|
+
const tsNode = services?.esTreeNodeToTSNodeMap.get(paramNode);
|
|
231
|
+
if (tsNode) {
|
|
232
|
+
const type = checker.getTypeAtLocation(tsNode);
|
|
233
|
+
// Fall back to the syntactic check so `T | null` annotations are still
|
|
234
|
+
// accepted even when T cannot be resolved. (happens when package is unbuilt)
|
|
235
|
+
if (type.flags & ts.TypeFlags.Any) {
|
|
236
|
+
return (0, plugin_utils_1.isNullableAnnotation)(paramNode);
|
|
237
|
+
}
|
|
238
|
+
if (type.isUnion()) {
|
|
239
|
+
return type.types.some(t => !!(t.flags & ts.TypeFlags.Null) ||
|
|
240
|
+
!!(t.flags & ts.TypeFlags.Undefined));
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// Fall through to syntactic check
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return (0, plugin_utils_1.isNullableAnnotation)(paramNode);
|
|
250
|
+
}
|
|
219
251
|
/**
|
|
220
252
|
* Returns true when two TypeScript types refer to the same type.
|
|
221
253
|
*/
|
|
@@ -260,7 +292,7 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
260
292
|
}
|
|
261
293
|
return {
|
|
262
294
|
VariableDeclarator(node) {
|
|
263
|
-
const pluginKind = (0, plugin_utils_1.getJupyterPluginKind)(node);
|
|
295
|
+
const pluginKind = (0, plugin_utils_1.getJupyterPluginKind)(node, checker, n => services?.esTreeNodeToTSNodeMap.get(n));
|
|
264
296
|
if (!pluginKind) {
|
|
265
297
|
return;
|
|
266
298
|
}
|
|
@@ -387,6 +419,16 @@ const jupyterPluginActivationArgs = (0, create_rule_1.createRule)({
|
|
|
387
419
|
});
|
|
388
420
|
}
|
|
389
421
|
}
|
|
422
|
+
else if (i >= requires.length && paramNode) {
|
|
423
|
+
// Token matched and is optional — param must be nullable.
|
|
424
|
+
if (!isParamNullable(paramNode)) {
|
|
425
|
+
context.report({
|
|
426
|
+
node: activateInfo.node,
|
|
427
|
+
messageId: 'optionalNotNullable',
|
|
428
|
+
data: { arg: paramNames[i + 1], type: expectedToken.name }
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
390
432
|
}
|
|
391
433
|
}
|
|
392
434
|
// Validation 4: Check for missing arguments (only if counts don't match)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const jupyterPluginDescription: import("@typescript-eslint/utils/
|
|
1
|
+
declare const jupyterPluginDescription: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingDescription" | "emptyDescription", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
2
|
name: string;
|
|
3
3
|
};
|
|
4
4
|
export = jupyterPluginDescription;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const requireSoftAssertionsBeforeSnapshots: import("@typescript-eslint/utils/ts-eslint").RuleModule<"requireSoftAssertion", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export = requireSoftAssertionsBeforeSnapshots;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
const create_rule_1 = require("../utils/create-rule");
|
|
7
|
+
function isTestBlock(node) {
|
|
8
|
+
const { callee } = node;
|
|
9
|
+
if (callee.type === 'Identifier') {
|
|
10
|
+
return callee.name === 'test' || callee.name === 'it';
|
|
11
|
+
}
|
|
12
|
+
if (callee.type === 'MemberExpression' &&
|
|
13
|
+
!callee.computed &&
|
|
14
|
+
callee.object.type === 'Identifier' &&
|
|
15
|
+
(callee.object.name === 'test' || callee.object.name === 'it') &&
|
|
16
|
+
callee.property.type === 'Identifier') {
|
|
17
|
+
return callee.property.name !== 'step';
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function getSnapshotInfo(node) {
|
|
22
|
+
const { callee } = node;
|
|
23
|
+
if (callee.type !== 'MemberExpression' || callee.computed)
|
|
24
|
+
return null;
|
|
25
|
+
const prop = callee.property;
|
|
26
|
+
if (prop.type !== 'Identifier' || prop.name !== 'toMatchSnapshot') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const expectCall = callee.object;
|
|
30
|
+
if (expectCall.type !== 'CallExpression')
|
|
31
|
+
return null;
|
|
32
|
+
const expectCallee = expectCall.callee;
|
|
33
|
+
if (expectCallee.type === 'Identifier' && expectCallee.name === 'expect') {
|
|
34
|
+
return { isSoft: false };
|
|
35
|
+
}
|
|
36
|
+
if (expectCallee.type === 'MemberExpression' &&
|
|
37
|
+
!expectCallee.computed &&
|
|
38
|
+
expectCallee.object.type === 'Identifier' &&
|
|
39
|
+
expectCallee.object.name === 'expect' &&
|
|
40
|
+
expectCallee.property.type === 'Identifier' &&
|
|
41
|
+
expectCallee.property.name === 'soft') {
|
|
42
|
+
return { isSoft: true };
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const requireSoftAssertionsBeforeSnapshots = (0, create_rule_1.createRule)({
|
|
47
|
+
name: 'require-soft-assertions-before-snapshots',
|
|
48
|
+
meta: {
|
|
49
|
+
type: 'problem',
|
|
50
|
+
docs: {
|
|
51
|
+
description: 'Require expect.soft() for snapshot assertions that precede other snapshot assertions in the same test block'
|
|
52
|
+
},
|
|
53
|
+
messages: {
|
|
54
|
+
requireSoftAssertion: 'Use expect.soft() for snapshot assertions that are not the last in the test block. Hard assertions short-circuit on failure, preventing subsequent snapshots from being updated.'
|
|
55
|
+
},
|
|
56
|
+
schema: []
|
|
57
|
+
},
|
|
58
|
+
defaultOptions: [],
|
|
59
|
+
create(context) {
|
|
60
|
+
const testContextStack = [];
|
|
61
|
+
return {
|
|
62
|
+
CallExpression(node) {
|
|
63
|
+
if (isTestBlock(node)) {
|
|
64
|
+
testContextStack.push([]);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const info = getSnapshotInfo(node);
|
|
68
|
+
if (info && testContextStack.length > 0) {
|
|
69
|
+
testContextStack[testContextStack.length - 1].push({
|
|
70
|
+
node,
|
|
71
|
+
isSoft: info.isSoft
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
'CallExpression:exit'(node) {
|
|
76
|
+
if (!isTestBlock(node))
|
|
77
|
+
return;
|
|
78
|
+
const snapshots = testContextStack.pop();
|
|
79
|
+
if (!snapshots || snapshots.length <= 1)
|
|
80
|
+
return;
|
|
81
|
+
for (let i = 0; i < snapshots.length - 1; i++) {
|
|
82
|
+
if (!snapshots[i].isSoft) {
|
|
83
|
+
context.report({
|
|
84
|
+
node: snapshots[i].node,
|
|
85
|
+
messageId: 'requireSoftAssertion'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
module.exports = requireSoftAssertionsBeforeSnapshots;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const tokenFormat: import("@typescript-eslint/utils/
|
|
1
|
+
declare const tokenFormat: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingColon" | "invalidTokenSymbol", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
2
|
name: string;
|
|
3
3
|
};
|
|
4
4
|
export = tokenFormat;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
+
import * as ts from 'typescript';
|
|
2
3
|
export type JupyterPluginKind = 'frontend' | 'service-manager';
|
|
3
4
|
/**
|
|
4
5
|
* Gets plugin kind from a variable declaration type annotation.
|
|
6
|
+
* Accepts an optional TS checker and node mapper to resolve import aliases
|
|
7
|
+
* (e.g. `import { JupyterFrontEndPlugin as JFEP } from '@jupyterlab/application'`).
|
|
5
8
|
*/
|
|
6
|
-
export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator): JupyterPluginKind | null;
|
|
9
|
+
export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator, checker?: ts.TypeChecker | null, getTSNode?: ((n: TSESTree.Node) => ts.Node | undefined) | null): JupyterPluginKind | null;
|
|
7
10
|
/**
|
|
8
11
|
* Extracts properties from an object expression
|
|
9
12
|
*/
|
|
@@ -20,4 +23,5 @@ export interface TokenEntry {
|
|
|
20
23
|
* Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
|
|
21
24
|
*/
|
|
22
25
|
export declare function extractArrayTokens(arrayExpr: TSESTree.ArrayExpression): TokenEntry[];
|
|
26
|
+
export declare function isNullableAnnotation(param: TSESTree.Identifier): boolean;
|
|
23
27
|
export declare function extractParameterType(param: TSESTree.Identifier): string | null;
|
|
@@ -3,16 +3,53 @@
|
|
|
3
3
|
* Copyright (c) Jupyter Development Team.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
6
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
40
|
exports.getJupyterPluginKind = getJupyterPluginKind;
|
|
8
41
|
exports.getObjectProperties = getObjectProperties;
|
|
9
42
|
exports.getPluginId = getPluginId;
|
|
10
43
|
exports.extractArrayTokens = extractArrayTokens;
|
|
44
|
+
exports.isNullableAnnotation = isNullableAnnotation;
|
|
11
45
|
exports.extractParameterType = extractParameterType;
|
|
46
|
+
const ts = __importStar(require("typescript"));
|
|
12
47
|
/**
|
|
13
48
|
* Gets plugin kind from a variable declaration type annotation.
|
|
49
|
+
* Accepts an optional TS checker and node mapper to resolve import aliases
|
|
50
|
+
* (e.g. `import { JupyterFrontEndPlugin as JFEP } from '@jupyterlab/application'`).
|
|
14
51
|
*/
|
|
15
|
-
function getJupyterPluginKind(node) {
|
|
52
|
+
function getJupyterPluginKind(node, checker, getTSNode) {
|
|
16
53
|
const id = node.id;
|
|
17
54
|
if (id.type !== 'Identifier' || !id.typeAnnotation) {
|
|
18
55
|
return null;
|
|
@@ -21,6 +58,7 @@ function getJupyterPluginKind(node) {
|
|
|
21
58
|
if (typeNode.type !== 'TSTypeReference') {
|
|
22
59
|
return null;
|
|
23
60
|
}
|
|
61
|
+
// Fast path: direct string match (no alias).
|
|
24
62
|
const pluginTypeName = extractTypeName(typeNode.typeName);
|
|
25
63
|
if (pluginTypeName === 'JupyterFrontEndPlugin') {
|
|
26
64
|
return 'frontend';
|
|
@@ -28,6 +66,30 @@ function getJupyterPluginKind(node) {
|
|
|
28
66
|
if (pluginTypeName === 'ServiceManagerPlugin') {
|
|
29
67
|
return 'service-manager';
|
|
30
68
|
}
|
|
69
|
+
// Slow path: resolve import aliases via the TS checker.
|
|
70
|
+
if (checker && getTSNode && typeNode.typeName.type === 'Identifier') {
|
|
71
|
+
try {
|
|
72
|
+
const tsNameNode = getTSNode(typeNode.typeName);
|
|
73
|
+
if (tsNameNode) {
|
|
74
|
+
const symbol = checker.getSymbolAtLocation(tsNameNode);
|
|
75
|
+
if (symbol) {
|
|
76
|
+
const resolved = symbol.flags & ts.SymbolFlags.Alias
|
|
77
|
+
? checker.getAliasedSymbol(symbol)
|
|
78
|
+
: symbol;
|
|
79
|
+
const resolvedName = resolved.getName();
|
|
80
|
+
if (resolvedName === 'JupyterFrontEndPlugin') {
|
|
81
|
+
return 'frontend';
|
|
82
|
+
}
|
|
83
|
+
if (resolvedName === 'ServiceManagerPlugin') {
|
|
84
|
+
return 'service-manager';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Fall through if checker/mapper unavailable
|
|
91
|
+
}
|
|
92
|
+
}
|
|
31
93
|
return null;
|
|
32
94
|
}
|
|
33
95
|
/**
|
|
@@ -99,6 +161,14 @@ function extractArrayTokens(arrayExpr) {
|
|
|
99
161
|
}
|
|
100
162
|
return entries;
|
|
101
163
|
}
|
|
164
|
+
function isNullableAnnotation(param) {
|
|
165
|
+
if (!param.typeAnnotation)
|
|
166
|
+
return false;
|
|
167
|
+
const typeNode = param.typeAnnotation.typeAnnotation;
|
|
168
|
+
if (typeNode.type !== 'TSUnionType')
|
|
169
|
+
return false;
|
|
170
|
+
return typeNode.types.some(t => t.type === 'TSNullKeyword' || t.type === 'TSUndefinedKeyword');
|
|
171
|
+
}
|
|
102
172
|
function extractParameterType(param) {
|
|
103
173
|
if (!param.typeAnnotation) {
|
|
104
174
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "ESLint plugin for Jupyter core and extensions with early error catching and best practices enforcement",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -65,7 +65,8 @@
|
|
|
65
65
|
"typescript": "^5.9.3"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@typescript-eslint/utils": "^8.54.0"
|
|
68
|
+
"@typescript-eslint/utils": "^8.54.0",
|
|
69
|
+
"jsonc-eslint-parser": "^2.4.0"
|
|
69
70
|
},
|
|
70
71
|
"peerDependencies": {
|
|
71
72
|
"eslint": ">=9.0.0"
|