@jupyter/eslint-plugin 0.0.2 → 0.0.4
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/README.md +1 -1
- package/lib/index.d.ts +26 -3
- package/lib/index.js +15 -3
- package/lib/rules/command-described-by.d.ts +3 -2
- package/lib/rules/command-described-by.js +12 -12
- package/lib/rules/no-translation-concatenation.d.ts +4 -0
- package/lib/rules/no-translation-concatenation.js +132 -0
- package/lib/rules/no-untranslated-string.d.ts +4 -0
- package/lib/rules/no-untranslated-string.js +250 -0
- package/lib/rules/plugin-activation-args.d.ts +6 -2
- package/lib/rules/plugin-activation-args.js +233 -94
- package/lib/rules/plugin-description.d.ts +3 -2
- package/lib/rules/plugin-description.js +27 -18
- package/lib/rules/token-format.d.ts +4 -0
- package/lib/rules/token-format.js +63 -0
- package/lib/utils/commands.d.ts +2 -2
- package/lib/utils/create-rule.d.ts +4 -0
- package/lib/utils/create-rule.js +9 -0
- package/lib/utils/plugin-utils.d.ts +11 -7
- package/lib/utils/plugin-utils.js +35 -48
- package/package.json +5 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Jupyter Development Team.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createRule = void 0;
|
|
8
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
9
|
+
exports.createRule = utils_1.ESLintUtils.RuleCreator(name => `https://eslint-plugin.readthedocs.io/en/latest/rules/${name}/`);
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
2
2
|
export type JupyterPluginKind = 'frontend' | 'service-manager';
|
|
3
3
|
/**
|
|
4
4
|
* Gets plugin kind from a variable declaration type annotation.
|
|
5
5
|
*/
|
|
6
|
-
export declare function getJupyterPluginKind(node:
|
|
6
|
+
export declare function getJupyterPluginKind(node: TSESTree.VariableDeclarator): JupyterPluginKind | null;
|
|
7
7
|
/**
|
|
8
8
|
* Extracts properties from an object expression
|
|
9
9
|
*/
|
|
10
|
-
export declare function getObjectProperties(obj:
|
|
10
|
+
export declare function getObjectProperties(obj: TSESTree.ObjectExpression): Map<string, TSESTree.Property>;
|
|
11
11
|
/**
|
|
12
12
|
* Gets the plugin ID from an object expression
|
|
13
13
|
*/
|
|
14
|
-
export declare function getPluginId(obj:
|
|
14
|
+
export declare function getPluginId(obj: TSESTree.ObjectExpression): string | null;
|
|
15
|
+
export interface TokenEntry {
|
|
16
|
+
name: string;
|
|
17
|
+
node: TSESTree.Node;
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
|
-
* Extracts
|
|
20
|
+
* Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
|
|
17
21
|
*/
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function extractParameterType(param:
|
|
22
|
+
export declare function extractArrayTokens(arrayExpr: TSESTree.ArrayExpression): TokenEntry[];
|
|
23
|
+
export declare function extractParameterType(param: TSESTree.Identifier): string | null;
|
|
@@ -7,30 +7,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.getJupyterPluginKind = getJupyterPluginKind;
|
|
8
8
|
exports.getObjectProperties = getObjectProperties;
|
|
9
9
|
exports.getPluginId = getPluginId;
|
|
10
|
-
exports.
|
|
10
|
+
exports.extractArrayTokens = extractArrayTokens;
|
|
11
11
|
exports.extractParameterType = extractParameterType;
|
|
12
12
|
/**
|
|
13
13
|
* Gets plugin kind from a variable declaration type annotation.
|
|
14
14
|
*/
|
|
15
15
|
function getJupyterPluginKind(node) {
|
|
16
16
|
const id = node.id;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
17
|
+
if (id.type !== 'Identifier' || !id.typeAnnotation) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const typeNode = id.typeAnnotation.typeAnnotation;
|
|
21
|
+
if (typeNode.type !== 'TSTypeReference') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const pluginTypeName = extractTypeName(typeNode.typeName);
|
|
25
|
+
if (pluginTypeName === 'JupyterFrontEndPlugin') {
|
|
26
|
+
return 'frontend';
|
|
27
|
+
}
|
|
28
|
+
if (pluginTypeName === 'ServiceManagerPlugin') {
|
|
29
|
+
return 'service-manager';
|
|
34
30
|
}
|
|
35
31
|
return null;
|
|
36
32
|
}
|
|
@@ -81,47 +77,41 @@ function getPluginId(obj) {
|
|
|
81
77
|
return null;
|
|
82
78
|
}
|
|
83
79
|
/**
|
|
84
|
-
* Extracts
|
|
80
|
+
* Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
|
|
85
81
|
*/
|
|
86
|
-
function
|
|
87
|
-
const
|
|
82
|
+
function extractArrayTokens(arrayExpr) {
|
|
83
|
+
const entries = [];
|
|
88
84
|
for (const element of arrayExpr.elements) {
|
|
89
85
|
if (element === null)
|
|
90
86
|
continue;
|
|
91
87
|
if (element.type === 'Identifier') {
|
|
92
|
-
|
|
88
|
+
entries.push({ name: element.name, node: element });
|
|
93
89
|
}
|
|
94
90
|
else if (element.type === 'MemberExpression') {
|
|
95
91
|
if (element.object.type === 'Identifier' &&
|
|
96
92
|
element.property.type === 'Identifier') {
|
|
97
|
-
|
|
93
|
+
entries.push({
|
|
94
|
+
name: `${element.object.name}.${element.property.name}`,
|
|
95
|
+
node: element
|
|
96
|
+
});
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
|
-
return
|
|
100
|
+
return entries;
|
|
102
101
|
}
|
|
103
102
|
function extractParameterType(param) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (Array.isArray(types) && types.length > 0) {
|
|
117
|
-
const nonNullType = types.find(
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
-
(t) => t.type !== 'TSNullKeyword');
|
|
120
|
-
if (nonNullType && nonNullType.type === 'TSTypeReference') {
|
|
121
|
-
return extractTypeName(nonNullType.typeName);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
103
|
+
if (!param.typeAnnotation) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const typeNode = param.typeAnnotation.typeAnnotation;
|
|
107
|
+
// Handle TSTypeReference (like JupyterFrontEnd.IPaths)
|
|
108
|
+
if (typeNode.type === 'TSTypeReference') {
|
|
109
|
+
return extractTypeName(typeNode.typeName);
|
|
110
|
+
}
|
|
111
|
+
if (typeNode.type === 'TSUnionType') {
|
|
112
|
+
const nonNullType = typeNode.types.find(t => t.type !== 'TSNullKeyword');
|
|
113
|
+
if (nonNullType && nonNullType.type === 'TSTypeReference') {
|
|
114
|
+
return extractTypeName(nonNullType.typeName);
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
117
|
return null;
|
|
@@ -131,10 +121,7 @@ function extractParameterType(param) {
|
|
|
131
121
|
* handling both simple Identifiers and qualified names (TSQualifiedName)
|
|
132
122
|
* e.g. `IType` -> "IType", `JupyterFrontEnd.IPaths` -> "JupyterFrontEnd.IPaths"
|
|
133
123
|
*/
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
124
|
function extractTypeName(typeName) {
|
|
136
|
-
if (!typeName)
|
|
137
|
-
return null;
|
|
138
125
|
if (typeName.type === 'Identifier') {
|
|
139
126
|
return typeName.name;
|
|
140
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/eslint-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@types/node": "^25.3.5",
|
|
56
56
|
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
57
57
|
"@typescript-eslint/parser": "^8.54.0",
|
|
58
|
-
"@typescript-eslint/
|
|
58
|
+
"@typescript-eslint/rule-tester": "^8.57.0",
|
|
59
59
|
"eslint": "^9.39.2",
|
|
60
60
|
"eslint-plugin": "^1.0.1",
|
|
61
61
|
"jest": "^30.2.0",
|
|
@@ -64,6 +64,9 @@
|
|
|
64
64
|
"ts-jest": "^29.4.6",
|
|
65
65
|
"typescript": "^5.9.3"
|
|
66
66
|
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"@typescript-eslint/utils": "^8.54.0"
|
|
69
|
+
},
|
|
67
70
|
"peerDependencies": {
|
|
68
71
|
"eslint": ">=9.0.0"
|
|
69
72
|
},
|