@jupyter/eslint-plugin 0.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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2026, Project Jupyter Contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # eslint-plugin
2
+
3
+ ESLint plugin for Jupyter core and extensions with early error catching and best practices enforcement.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install --save-dev @jupyter/eslint-plugin
9
+ ```
10
+
11
+ ## Rules
12
+
13
+ - `command-described-by` - Ensure JupyterLab commands include describedBy property
14
+ - `plugin-activation-args` - Ensure JupyterLab plugin activation function arguments match requires and optional tokens in order
15
+ - `plugin-description` - Ensure JupyterLab plugins have a description property
16
+
17
+ ## Usage
18
+
19
+ Add `jupyter` to the plugins section of your ESLint configuration:
20
+
21
+ ```javascript
22
+ // eslint.config.js
23
+ import jupyterPlugin from '@jupyter/eslint-plugin';
24
+
25
+ export default [
26
+ {
27
+ files: ['**/*.ts', '**/*.tsx'],
28
+ plugins: {
29
+ jupyter: jupyterPlugin
30
+ },
31
+ rules: {
32
+ 'jupyter/command-described-by': 'warn',
33
+ 'jupyter/plugin-activation-args': 'warn',
34
+ 'jupyter/plugin-description': 'warn'
35
+ }
36
+ }
37
+ ];
38
+ ```
39
+
40
+ ## License
41
+
42
+ BSD 3-Clause
package/lib/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ declare const plugin: {
2
+ rules: {
3
+ 'plugin-activation-args': import("eslint").Rule.RuleModule;
4
+ 'command-described-by': import("eslint").Rule.RuleModule;
5
+ 'plugin-description': import("eslint").Rule.RuleModule;
6
+ };
7
+ configs: {
8
+ recommended: {
9
+ files: string[];
10
+ rules: {
11
+ 'jupyter/plugin-activation-args': string;
12
+ 'jupyter/command-described-by': string;
13
+ 'jupyter/plugin-description': string;
14
+ };
15
+ };
16
+ };
17
+ };
18
+ export = plugin;
package/lib/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ const plugin_activation_args_1 = __importDefault(require("./rules/plugin-activation-args"));
10
+ const command_described_by_1 = __importDefault(require("./rules/command-described-by"));
11
+ const plugin_description_1 = __importDefault(require("./rules/plugin-description"));
12
+ const plugin = {
13
+ rules: {
14
+ 'plugin-activation-args': plugin_activation_args_1.default,
15
+ 'command-described-by': command_described_by_1.default,
16
+ 'plugin-description': plugin_description_1.default
17
+ },
18
+ configs: {
19
+ recommended: {
20
+ files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
21
+ rules: {
22
+ 'jupyter/plugin-activation-args': 'error',
23
+ 'jupyter/command-described-by': 'error',
24
+ 'jupyter/plugin-description': 'error'
25
+ }
26
+ }
27
+ }
28
+ };
29
+ module.exports = plugin;
@@ -0,0 +1,3 @@
1
+ import { Rule } from 'eslint';
2
+ declare const jupyterCommandDescribedBy: Rule.RuleModule;
3
+ export = jupyterCommandDescribedBy;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ const plugin_utils_1 = require("../utils/plugin-utils");
7
+ const commands_1 = require("../utils/commands");
8
+ const jupyterCommandDescribedBy = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'Ensure JupyterLab commands include describedBy property',
13
+ recommended: 'recommended',
14
+ url: 'https://github.com/jupyterlab/eslint-plugin'
15
+ },
16
+ messages: {
17
+ missingDescribedBy: 'Command "{{ commandId }}" is missing the "describedBy" property.'
18
+ },
19
+ schema: []
20
+ },
21
+ create(context) {
22
+ return {
23
+ CallExpression(node) {
24
+ const callExpr = node;
25
+ // Check if this is <something>.addCommand()
26
+ if (!(0, commands_1.isAddCommandCall)(callExpr)) {
27
+ return;
28
+ }
29
+ // Get the command ID and options
30
+ if (callExpr.arguments.length < 2) {
31
+ return;
32
+ }
33
+ const commandIdArg = callExpr.arguments[0];
34
+ const optionsArg = callExpr.arguments[1];
35
+ // Extract command ID for error message
36
+ let commandId = 'unknown';
37
+ if (commandIdArg.type === 'Literal' &&
38
+ typeof commandIdArg.value === 'string') {
39
+ commandId = commandIdArg.value;
40
+ }
41
+ else if (commandIdArg.type === 'Identifier') {
42
+ commandId = commandIdArg.name;
43
+ }
44
+ else if (commandIdArg.type === 'MemberExpression') {
45
+ // Handle CommandIDs.something pattern
46
+ if (commandIdArg.property.type === 'Identifier') {
47
+ commandId = commandIdArg.property.name;
48
+ }
49
+ }
50
+ // Options must be an object
51
+ if (optionsArg.type !== 'ObjectExpression') {
52
+ return;
53
+ }
54
+ const options = optionsArg;
55
+ const properties = (0, plugin_utils_1.getObjectProperties)(options);
56
+ // Check if execute function exists and has parameters
57
+ const executeProp = properties.get('execute');
58
+ if (!executeProp || executeProp.value.type === 'Literal') {
59
+ return;
60
+ }
61
+ const describedByProp = properties.get('describedBy');
62
+ if (!describedByProp) {
63
+ context.report({
64
+ node: callExpr,
65
+ messageId: 'missingDescribedBy',
66
+ data: { commandId }
67
+ });
68
+ return;
69
+ }
70
+ if (describedByProp.value.type !== 'ObjectExpression') {
71
+ return;
72
+ }
73
+ }
74
+ };
75
+ }
76
+ };
77
+ module.exports = jupyterCommandDescribedBy;
@@ -0,0 +1,3 @@
1
+ import { Rule } from 'eslint';
2
+ declare const jupyterPluginActivationArgs: Rule.RuleModule;
3
+ export = jupyterPluginActivationArgs;
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ const plugin_utils_1 = require("../utils/plugin-utils");
7
+ const DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES = ['app', '_app', '_'];
8
+ /**
9
+ * Finds the activate function in the plugin object
10
+ */
11
+ function findActivateFunction(node) {
12
+ const activateProp = node.properties.find(prop => ((prop.type === 'Property' || prop.type === 'SpreadElement') &&
13
+ prop.type === 'Property' &&
14
+ ((prop.key.type === 'Identifier' && prop.key.name === 'activate') ||
15
+ (prop.key.type === 'Literal' && prop.key.value === 'activate'))) ||
16
+ prop.type === 'SpreadElement');
17
+ if (!activateProp || activateProp.type !== 'Property') {
18
+ return null;
19
+ }
20
+ const activateValue = activateProp.value;
21
+ // Handle both arrow functions and regular functions
22
+ if ((activateValue.type === 'ArrowFunctionExpression' ||
23
+ activateValue.type === 'FunctionExpression') &&
24
+ activateValue.params) {
25
+ const params = activateValue.params
26
+ .filter((param) => param.type === 'Identifier')
27
+ .map(param => param.name);
28
+ // Extract type annotations if available
29
+ const paramTypes = activateValue.params
30
+ .filter((param) => param.type === 'Identifier')
31
+ .map(param => (0, plugin_utils_1.extractParameterType)(param));
32
+ return { node: activateProp, params, paramTypes };
33
+ }
34
+ return null;
35
+ }
36
+ /**
37
+ * Extracts requires and optional arrays from a plugin object
38
+ */
39
+ function extractRequiresOptional(node) {
40
+ const result = {
41
+ requires: [],
42
+ optional: []
43
+ };
44
+ const props = node.properties;
45
+ for (const prop of props) {
46
+ if (prop.type !== 'Property')
47
+ continue;
48
+ let keyName = null;
49
+ if (prop.key.type === 'Identifier') {
50
+ keyName = prop.key.name;
51
+ }
52
+ else if (prop.key.type === 'Literal' &&
53
+ typeof prop.key.value === 'string') {
54
+ keyName = prop.key.value;
55
+ }
56
+ if (keyName === 'requires' && prop.value.type === 'ArrayExpression') {
57
+ result.requires = (0, plugin_utils_1.extractIdentifierNames)(prop.value);
58
+ }
59
+ else if (keyName === 'optional' &&
60
+ prop.value.type === 'ArrayExpression') {
61
+ result.optional = (0, plugin_utils_1.extractIdentifierNames)(prop.value);
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ /**
67
+ * Checks if a type name is compatible with JupyterFrontEnd
68
+ */
69
+ function isCompatibleWithJupyterFrontEnd(typeName) {
70
+ if (!typeName) {
71
+ return true; // If we can't check, we allow it
72
+ }
73
+ const compatibleTypes = [
74
+ 'JupyterFrontEnd',
75
+ 'JupyterLab',
76
+ 'Application'
77
+ ];
78
+ return compatibleTypes.includes(typeName);
79
+ }
80
+ const jupyterPluginActivationArgs = {
81
+ meta: {
82
+ type: 'problem',
83
+ docs: {
84
+ description: 'Ensure JupyterLab plugin activation function arguments match requires and optional tokens in order',
85
+ recommended: 'recommended',
86
+ url: 'https://github.com/jupyterlab/eslint-plugin'
87
+ },
88
+ messages: {
89
+ mismatchedOrder: 'Activation argument "{{ arg }}" does not match the order of requires/optional tokens.',
90
+ missingArgument: 'Token "{{ token }}" from requires/optional is missing in activation arguments.',
91
+ extraArgument: 'Activation argument "{{ arg }}" is not in requires/optional tokens.',
92
+ appNotFirst: 'First activation argument must be one of [{{ allowedNames }}] (JupyterFrontEnd), got "{{ arg }}".',
93
+ invalidAppType: 'First activation argument "{{ arg }}" has invalid type "{{ type }}". Expected JupyterFrontEnd, JupyterLab, or Application.',
94
+ wrongArgumentCount: 'Expected {{ expected }} activation arguments (app + {{ tokenCount }} tokens), got {{ actual }}.'
95
+ },
96
+ fixable: 'code',
97
+ schema: [
98
+ {
99
+ type: 'object',
100
+ properties: {
101
+ allowedFirstArgumentNames: {
102
+ type: 'array',
103
+ items: {
104
+ type: 'string'
105
+ },
106
+ default: DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES,
107
+ description: 'Allowed names for the first activation argument (JupyterFrontEnd)'
108
+ }
109
+ },
110
+ additionalProperties: false
111
+ }
112
+ ]
113
+ },
114
+ create(context) {
115
+ // Get configuration options
116
+ const options = context.options[0] || {};
117
+ const allowedFirstArgumentNames = options.allowedFirstArgumentNames || DEFAULT_ALLOWED_FIRST_ARGUMENT_NAMES;
118
+ return {
119
+ VariableDeclarator(node) {
120
+ const varDecl = node;
121
+ if (!(0, plugin_utils_1.hasJupyterPluginType)(varDecl)) {
122
+ return;
123
+ }
124
+ if (varDecl.init && varDecl.init.type === 'ObjectExpression') {
125
+ const pluginObj = varDecl.init;
126
+ const { requires, optional } = extractRequiresOptional(pluginObj);
127
+ const activateInfo = findActivateFunction(pluginObj);
128
+ if (!activateInfo) {
129
+ return;
130
+ }
131
+ const { params, paramTypes } = activateInfo;
132
+ const expectedCount = 1 + requires.length + optional.length;
133
+ const expectedTokensWithoutApp = [...requires, ...optional];
134
+ if (expectedCount === 1 && params.length === 0) {
135
+ // Special case, not invalid
136
+ return;
137
+ }
138
+ // Validation 1a: Check if first argument is one of the allowed names
139
+ if (params.length > 0 && !allowedFirstArgumentNames.includes(params[0])) {
140
+ context.report({
141
+ node: activateInfo.node,
142
+ messageId: 'appNotFirst',
143
+ data: {
144
+ arg: params[0],
145
+ allowedNames: allowedFirstArgumentNames.map(name => `"${name}"`).join(', ')
146
+ }
147
+ });
148
+ return;
149
+ }
150
+ // Validation 1b: Check if first argument type is compatible with JupyterFrontEnd
151
+ if (params.length > 0 && paramTypes.length > 0) {
152
+ const firstParamType = paramTypes[0];
153
+ if (!isCompatibleWithJupyterFrontEnd(firstParamType)) {
154
+ context.report({
155
+ node: activateInfo.node,
156
+ messageId: 'invalidAppType',
157
+ data: {
158
+ arg: params[0],
159
+ type: firstParamType || 'unknown'
160
+ }
161
+ });
162
+ return;
163
+ }
164
+ }
165
+ // Validation 2: Check if argument count matches
166
+ if (params.length !== expectedCount) {
167
+ context.report({
168
+ node: activateInfo.node,
169
+ messageId: 'wrongArgumentCount',
170
+ data: {
171
+ expected: String(expectedCount),
172
+ tokenCount: String(requires.length + optional.length),
173
+ actual: String(params.length)
174
+ }
175
+ });
176
+ }
177
+ // Validation 3: If parameters have type annotations, validate order
178
+ const actualParamTypes = paramTypes.slice(1); // Already validated above
179
+ const hasTypeInfo = actualParamTypes.some((t) => t !== null);
180
+ if (hasTypeInfo) {
181
+ // Validate that parameter types match expected token types in order
182
+ for (let i = 0; i < actualParamTypes.length; i++) {
183
+ const paramType = actualParamTypes[i];
184
+ const expectedToken = expectedTokensWithoutApp[i];
185
+ if (expectedToken === undefined) {
186
+ // Extra argument
187
+ if (paramType) {
188
+ context.report({
189
+ node: activateInfo.node,
190
+ messageId: 'extraArgument',
191
+ data: { arg: params[i + 1] }
192
+ });
193
+ }
194
+ }
195
+ else if (paramType !== null && paramType !== expectedToken) {
196
+ // Type mismatch
197
+ context.report({
198
+ node: activateInfo.node,
199
+ messageId: 'mismatchedOrder',
200
+ data: { arg: params[i + 1] }
201
+ });
202
+ }
203
+ }
204
+ }
205
+ else {
206
+ // Without type information, we only check for extra arguments
207
+ const actualParams = params.slice(1);
208
+ for (let i = expectedTokensWithoutApp.length; i < actualParams.length; i++) {
209
+ context.report({
210
+ node: activateInfo.node,
211
+ messageId: 'extraArgument',
212
+ data: { arg: actualParams[i] }
213
+ });
214
+ }
215
+ }
216
+ // Validation 4: Check for missing arguments (only if counts don't match)
217
+ if (params.length < expectedCount) {
218
+ for (let i = params.length - 1; i < expectedTokensWithoutApp.length; i++) {
219
+ const missingToken = expectedTokensWithoutApp[i];
220
+ context.report({
221
+ node: activateInfo.node,
222
+ messageId: 'missingArgument',
223
+ data: { token: missingToken }
224
+ });
225
+ }
226
+ }
227
+ }
228
+ }
229
+ };
230
+ }
231
+ };
232
+ module.exports = jupyterPluginActivationArgs;
@@ -0,0 +1,3 @@
1
+ import { Rule } from 'eslint';
2
+ declare const jupyterPluginDescription: Rule.RuleModule;
3
+ export = jupyterPluginDescription;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Jupyter Development Team.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ const plugin_utils_1 = require("../utils/plugin-utils");
7
+ /**
8
+ * Checks if an object expression has a description property
9
+ */
10
+ function hasDescriptionProperty(obj) {
11
+ for (const prop of obj.properties) {
12
+ if (prop.type === 'Property') {
13
+ let keyName = null;
14
+ if (prop.key.type === 'Identifier') {
15
+ keyName = prop.key.name;
16
+ }
17
+ else if (prop.key.type === 'Literal' &&
18
+ typeof prop.key.value === 'string') {
19
+ keyName = prop.key.value;
20
+ }
21
+ if (keyName === 'description') {
22
+ // Check if description value is not empty
23
+ if (prop.value.type === 'Literal') {
24
+ const value = prop.value.value;
25
+ return typeof value === 'string' && value.trim().length > 0;
26
+ }
27
+ return true; // Non-literal descriptions are assumed valid
28
+ }
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ const jupyterPluginDescription = {
34
+ meta: {
35
+ type: 'problem',
36
+ docs: {
37
+ description: 'Ensure all JupyterLab plugins have a description property',
38
+ recommended: 'recommended',
39
+ url: 'https://github.com/jupyterlab/eslint-plugin'
40
+ },
41
+ messages: {
42
+ missingDescription: 'JupyterLab plugin{{ pluginId }} is missing a "description" property.',
43
+ emptyDescription: 'JupyterLab plugin{{ pluginId }} has an empty "description" property.'
44
+ },
45
+ schema: []
46
+ },
47
+ create(context) {
48
+ return {
49
+ VariableDeclarator(node) {
50
+ const varDecl = node;
51
+ // Check if this has a JupyterFrontEndPlugin type annotation
52
+ if (!(0, plugin_utils_1.hasJupyterPluginType)(varDecl)) {
53
+ return;
54
+ }
55
+ // Check if init is an object expression
56
+ if (!varDecl.init || varDecl.init.type !== 'ObjectExpression') {
57
+ return;
58
+ }
59
+ const pluginObj = varDecl.init;
60
+ const pluginId = (0, plugin_utils_1.getPluginId)(pluginObj);
61
+ const pluginIdSuffix = pluginId ? ` "${pluginId}"` : '';
62
+ // Check if description property exists
63
+ if (!hasDescriptionProperty(pluginObj)) {
64
+ context.report({
65
+ node: pluginObj,
66
+ messageId: 'missingDescription',
67
+ data: { pluginId: pluginIdSuffix }
68
+ });
69
+ }
70
+ }
71
+ };
72
+ }
73
+ };
74
+ module.exports = jupyterPluginDescription;
@@ -0,0 +1,5 @@
1
+ import * as ESTree from 'estree';
2
+ /**
3
+ * Checks if a node represents *.addCommand()
4
+ */
5
+ export declare function isAddCommandCall(node: ESTree.CallExpression): boolean;
@@ -0,0 +1,20 @@
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.isAddCommandCall = isAddCommandCall;
8
+ /**
9
+ * Checks if a node represents *.addCommand()
10
+ */
11
+ function isAddCommandCall(node) {
12
+ if (node.callee.type === 'MemberExpression') {
13
+ const callee = node.callee;
14
+ if (callee.property.type === 'Identifier' &&
15
+ callee.property.name === 'addCommand') {
16
+ return true;
17
+ }
18
+ }
19
+ return false;
20
+ }
@@ -0,0 +1,23 @@
1
+ import * as ESTree from 'estree';
2
+ /**
3
+ * Extracts properties from an object expression
4
+ */
5
+ export declare function getObjectProperties(obj: ESTree.ObjectExpression): Map<string, ESTree.Property>;
6
+ /**
7
+ * Checks if a variable declaration has a JupyterFrontEndPlugin type annotation
8
+ */
9
+ export declare function hasJupyterPluginType(node: ESTree.VariableDeclarator): boolean;
10
+ /**
11
+ * Gets the plugin ID from an object expression
12
+ */
13
+ export declare function getPluginId(obj: ESTree.ObjectExpression): string | null;
14
+ /**
15
+ * Extracts identifier names from an array expression
16
+ * Useful for extracting token names from requires/optional arrays
17
+ */
18
+ export declare function extractIdentifierNames(arrayNode: ESTree.ArrayExpression): string[];
19
+ /**
20
+ * Extracts type annotation from a function parameter
21
+ * Returns the type name if it has a type annotation, null otherwise
22
+ */
23
+ export declare function extractParameterType(param: ESTree.Identifier): string | null;
@@ -0,0 +1,125 @@
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.getObjectProperties = getObjectProperties;
8
+ exports.hasJupyterPluginType = hasJupyterPluginType;
9
+ exports.getPluginId = getPluginId;
10
+ exports.extractIdentifierNames = extractIdentifierNames;
11
+ exports.extractParameterType = extractParameterType;
12
+ /**
13
+ * Extracts properties from an object expression
14
+ */
15
+ function getObjectProperties(obj) {
16
+ const props = new Map();
17
+ for (const prop of obj.properties) {
18
+ if (prop.type === 'Property' && !prop.computed) {
19
+ let keyName = null;
20
+ if (prop.key.type === 'Identifier') {
21
+ keyName = prop.key.name;
22
+ }
23
+ else if (prop.key.type === 'Literal' &&
24
+ typeof prop.key.value === 'string') {
25
+ keyName = prop.key.value;
26
+ }
27
+ if (keyName) {
28
+ props.set(keyName, prop);
29
+ }
30
+ }
31
+ }
32
+ return props;
33
+ }
34
+ /**
35
+ * Checks if a variable declaration has a JupyterFrontEndPlugin type annotation
36
+ */
37
+ function hasJupyterPluginType(node) {
38
+ // Check if the variable declarator has a type annotation
39
+ const id = node.id;
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ if (id.typeAnnotation) {
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ const typeAnnotation = id.typeAnnotation;
44
+ if (typeAnnotation.typeAnnotation) {
45
+ const typeNode = typeAnnotation.typeAnnotation;
46
+ if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
47
+ if (typeNode.typeName.type === 'Identifier') {
48
+ return typeNode.typeName.name === 'JupyterFrontEndPlugin';
49
+ }
50
+ }
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ /**
56
+ * Gets the plugin ID from an object expression
57
+ */
58
+ function getPluginId(obj) {
59
+ for (const prop of obj.properties) {
60
+ if (prop.type === 'Property') {
61
+ let keyName = null;
62
+ if (prop.key.type === 'Identifier') {
63
+ keyName = prop.key.name;
64
+ }
65
+ else if (prop.key.type === 'Literal' &&
66
+ typeof prop.key.value === 'string') {
67
+ keyName = prop.key.value;
68
+ }
69
+ if (keyName === 'id' && prop.value.type === 'Literal') {
70
+ const value = prop.value.value;
71
+ if (typeof value === 'string') {
72
+ return value;
73
+ }
74
+ }
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+ /**
80
+ * Extracts identifier names from an array expression
81
+ * Useful for extracting token names from requires/optional arrays
82
+ */
83
+ function extractIdentifierNames(arrayNode) {
84
+ return arrayNode.elements
85
+ .filter((elem) => {
86
+ return elem !== null && elem.type === 'Identifier';
87
+ })
88
+ .map(id => id.name);
89
+ }
90
+ /**
91
+ * Extracts type annotation from a function parameter
92
+ * Returns the type name if it has a type annotation, null otherwise
93
+ */
94
+ function extractParameterType(param) {
95
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ if (param.typeAnnotation) {
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ const annotation = param.typeAnnotation;
99
+ if (annotation && annotation.typeAnnotation) {
100
+ const typeNode = annotation.typeAnnotation;
101
+ // Handle TSTypeReference (e.g., type: IType)
102
+ if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
103
+ if (typeNode.typeName.type === 'Identifier') {
104
+ return typeNode.typeName.name;
105
+ }
106
+ }
107
+ // Handle TSUnionType (e.g., type: IType | null)
108
+ if (typeNode.type === 'TSUnionType') {
109
+ const types = typeNode.types;
110
+ if (Array.isArray(types) && types.length > 0) {
111
+ const nonNullType = types.find(
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ (t) => t.type !== 'TSNullKeyword');
114
+ if (nonNullType && nonNullType.type === 'TSTypeReference') {
115
+ if (nonNullType.typeName &&
116
+ nonNullType.typeName.type === 'Identifier') {
117
+ return nonNullType.typeName.name;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ return null;
125
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@jupyter/eslint-plugin",
3
+ "version": "0.0.1",
4
+ "description": "ESLint plugin for Jupyter core and extensions with early error catching and best practices enforcement",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "watch": "tsc --watch",
13
+ "test": "jest",
14
+ "test:watch": "jest --watch",
15
+ "lint": "eslint",
16
+ "lint:fix": "eslint --fix",
17
+ "format": "prettier --write .",
18
+ "format:check": "prettier --check ."
19
+ },
20
+ "keywords": [
21
+ "eslint",
22
+ "eslint-plugin",
23
+ "jupyter",
24
+ "jupyterlab"
25
+ ],
26
+ "author": "Jupyter Development Team",
27
+ "license": "BSD-3-Clause",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/jupyterlab/eslint-plugin.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/jupyterlab/eslint-plugin/issues"
34
+ },
35
+ "homepage": "https://github.com/jupyterlab/eslint-plugin",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "jupyter-releaser": {
40
+ "hooks": {
41
+ "before-build-npm": [
42
+ "npm install",
43
+ "npm run build"
44
+ ]
45
+ }
46
+ },
47
+ "devDependencies": {
48
+ "@types/eslint": "^9.6.1",
49
+ "@types/estree": "^1.0.8",
50
+ "@types/jest": "^30.0.0",
51
+ "@types/node": "^25.2.0",
52
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
53
+ "@typescript-eslint/parser": "^8.54.0",
54
+ "@typescript-eslint/utils": "^8.54.0",
55
+ "eslint": "^9.39.2",
56
+ "eslint-plugin": "^1.0.1",
57
+ "jest": "^30.2.0",
58
+ "pre-commit": "^1.2.2",
59
+ "prettier": "^3.8.1",
60
+ "ts-jest": "^29.4.6",
61
+ "typescript": "^5.9.3"
62
+ },
63
+ "peerDependencies": {
64
+ "eslint": ">=9.0.0"
65
+ },
66
+ "engines": {
67
+ "node": ">=16.0.0"
68
+ }
69
+ }