@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.
@@ -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 * as ESTree from 'estree';
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: ESTree.VariableDeclarator): JupyterPluginKind | null;
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: ESTree.ObjectExpression): Map<string, ESTree.Property>;
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: ESTree.ObjectExpression): string | null;
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 element names from an array, including member expressions like JupyterFrontEnd.IPaths
20
+ * Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
17
21
  */
18
- export declare function extractArrayElements(arrayExpr: ESTree.ArrayExpression): string[];
19
- export declare function extractParameterType(param: ESTree.Identifier): string | null;
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.extractArrayElements = extractArrayElements;
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- if (id.typeAnnotation) {
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- const typeAnnotation = id.typeAnnotation;
21
- if (typeAnnotation.typeAnnotation) {
22
- const typeNode = typeAnnotation.typeAnnotation;
23
- if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
24
- if (typeNode.typeName.type === 'Identifier') {
25
- if (typeNode.typeName.name === 'JupyterFrontEndPlugin') {
26
- return 'frontend';
27
- }
28
- if (typeNode.typeName.name === 'ServiceManagerPlugin') {
29
- return 'service-manager';
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 element names from an array, including member expressions like JupyterFrontEnd.IPaths
80
+ * Extracts token names and nodes from an array, including member expressions like JupyterFrontEnd.IPaths
85
81
  */
86
- function extractArrayElements(arrayExpr) {
87
- const names = [];
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
- names.push(element.name);
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
- names.push(`${element.object.name}.${element.property.name}`);
93
+ entries.push({
94
+ name: `${element.object.name}.${element.property.name}`,
95
+ node: element
96
+ });
98
97
  }
99
98
  }
100
99
  }
101
- return names;
100
+ return entries;
102
101
  }
103
102
  function extractParameterType(param) {
104
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
- if (param.typeAnnotation) {
106
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
- const annotation = param.typeAnnotation;
108
- if (annotation && annotation.typeAnnotation) {
109
- const typeNode = annotation.typeAnnotation;
110
- // Handle TSTypeReference (like JupyterFrontEnd.IPaths)
111
- if (typeNode.type === 'TSTypeReference' && typeNode.typeName) {
112
- return extractTypeName(typeNode.typeName);
113
- }
114
- if (typeNode.type === 'TSUnionType') {
115
- const types = typeNode.types;
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.2",
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/utils": "^8.54.0",
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
  },