@murky-web/oxlint-plugin-solid 1.4.1 → 1.5.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.
@@ -3,7 +3,7 @@ import {
3
3
  isDOMElementName,
4
4
  formatList,
5
5
  appendImports,
6
- insertImports,
6
+ insertImports
7
7
  } from "../utils.mjs";
8
8
  // Currently all of the control flow components are from 'solid-js'.
9
9
  // Solid 2.0 dropped `Index` (use `<For keyed={false}>`) and renamed the
@@ -16,7 +16,7 @@ const AUTO_COMPONENTS = [
16
16
  "Loading",
17
17
  "Errored",
18
18
  "Repeat",
19
- "Reveal",
19
+ "Reveal"
20
20
  ];
21
21
  const SOURCE_MODULE = "solid-js";
22
22
  export default {
@@ -25,7 +25,7 @@ export default {
25
25
  docs: {
26
26
  description:
27
27
  "Disallow references to undefined variables in JSX. Handles custom directives.",
28
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-undef.md",
28
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-undef.md"
29
29
  },
30
30
  fixable: "code",
31
31
  schema: [
@@ -36,30 +36,30 @@ export default {
36
36
  type: "boolean",
37
37
  description:
38
38
  "When true, the rule will consider the global scope when checking for defined components.",
39
- default: false,
39
+ default: false
40
40
  },
41
41
  autoImport: {
42
42
  type: "boolean",
43
43
  description:
44
44
  'Automatically import certain components from `"solid-js"` if they are undefined.',
45
- default: true,
45
+ default: true
46
46
  },
47
47
  typescriptEnabled: {
48
48
  type: "boolean",
49
49
  description:
50
50
  "Adjusts behavior not to conflict with TypeScript's type checking.",
51
- default: false,
52
- },
51
+ default: false
52
+ }
53
53
  },
54
- additionalProperties: false,
55
- },
54
+ additionalProperties: false
55
+ }
56
56
  ],
57
57
  messages: {
58
58
  undefined: "'{{identifier}}' is not defined.",
59
59
  customDirectiveUndefined:
60
60
  "Custom directive '{{identifier}}' is not defined.",
61
- autoImport: "{{imports}} should be imported from '{{source}}'.",
62
- },
61
+ autoImport: "{{imports}} should be imported from '{{source}}'."
62
+ }
63
63
  },
64
64
  defaultOptions: [],
65
65
  create(context) {
@@ -76,7 +76,7 @@ export default {
76
76
  */
77
77
  function checkIdentifierInJSX(
78
78
  node,
79
- { isComponent, isCustomDirective } = {},
79
+ { isComponent, isCustomDirective } = {}
80
80
  ) {
81
81
  let scope = getScope(context, node);
82
82
  const sourceCode = getSourceCode(context);
@@ -101,7 +101,7 @@ export default {
101
101
  // Temporary fix for babel-eslint
102
102
  if (scope.childScopes[0].childScopes.length) {
103
103
  variables.push(
104
- ...scope.childScopes[0].childScopes[0].variables,
104
+ ...scope.childScopes[0].childScopes[0].variables
105
105
  );
106
106
  }
107
107
  }
@@ -121,16 +121,16 @@ export default {
121
121
  node,
122
122
  messageId: "customDirectiveUndefined",
123
123
  data: {
124
- identifier: node.name,
125
- },
124
+ identifier: node.name
125
+ }
126
126
  });
127
127
  } else if (!isTypeScriptEnabled) {
128
128
  context.report({
129
129
  node,
130
130
  messageId: "undefined",
131
131
  data: {
132
- identifier: node.name,
133
- },
132
+ identifier: node.name
133
+ }
134
134
  });
135
135
  }
136
136
  }
@@ -141,7 +141,7 @@ export default {
141
141
  case "JSXIdentifier":
142
142
  if (!isDOMElementName(node.name.name)) {
143
143
  checkIdentifierInJSX(node.name, {
144
- isComponent: true,
144
+ isComponent: true
145
145
  });
146
146
  }
147
147
  break;
@@ -166,14 +166,14 @@ export default {
166
166
  node.name?.type === "JSXIdentifier"
167
167
  ) {
168
168
  checkIdentifierInJSX(node.name, {
169
- isCustomDirective: true,
169
+ isCustomDirective: true
170
170
  });
171
171
  }
172
172
  },
173
173
  "Program:exit": (programNode) => {
174
174
  // add in any auto import components used in the program
175
175
  const missingComponents = Array.from(
176
- missingComponentsSet.values(),
176
+ missingComponentsSet.values()
177
177
  );
178
178
  if (autoImport && missingComponents.length) {
179
179
  const importNode = programNode.body.find(
@@ -181,7 +181,7 @@ export default {
181
181
  n.type === "ImportDeclaration" &&
182
182
  n.importKind !== "type" &&
183
183
  n.source.type === "Literal" &&
184
- n.source.value === SOURCE_MODULE,
184
+ n.source.value === SOURCE_MODULE
185
185
  );
186
186
  if (importNode) {
187
187
  context.report({
@@ -189,16 +189,16 @@ export default {
189
189
  messageId: "autoImport",
190
190
  data: {
191
191
  imports: formatList(missingComponents), // "Show, For, and Switch"
192
- source: SOURCE_MODULE,
192
+ source: SOURCE_MODULE
193
193
  },
194
194
  fix: (fixer) => {
195
195
  return appendImports(
196
196
  fixer,
197
197
  getSourceCode(context),
198
198
  importNode,
199
- missingComponents,
199
+ missingComponents
200
200
  );
201
- },
201
+ }
202
202
  });
203
203
  } else {
204
204
  context.report({
@@ -206,7 +206,7 @@ export default {
206
206
  messageId: "autoImport",
207
207
  data: {
208
208
  imports: formatList(missingComponents),
209
- source: SOURCE_MODULE,
209
+ source: SOURCE_MODULE
210
210
  },
211
211
  fix: (fixer) => {
212
212
  // insert `import { missing, identifiers } from "solid-js"` at top of module
@@ -214,13 +214,13 @@ export default {
214
214
  fixer,
215
215
  getSourceCode(context),
216
216
  "solid-js",
217
- missingComponents,
217
+ missingComponents
218
218
  );
219
- },
219
+ }
220
220
  });
221
221
  }
222
222
  }
223
- },
223
+ }
224
224
  };
225
- },
225
+ }
226
226
  };
@@ -5,11 +5,11 @@ export const jsxUsesVarsRule = {
5
5
  docs: {
6
6
  description:
7
7
  "Prevent variables used in JSX from being marked as unused.",
8
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-uses-vars.md",
8
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-uses-vars.md"
9
9
  },
10
10
  messages: {},
11
11
  schema: [],
12
- type: "problem",
12
+ type: "problem"
13
13
  },
14
14
  defaultOptions: [],
15
15
  create(context) {
@@ -45,7 +45,7 @@ export const jsxUsesVarsRule = {
45
45
  ) {
46
46
  markVariableAsUsed(context, node.name.name, node.name);
47
47
  }
48
- },
48
+ }
49
49
  };
50
- },
50
+ }
51
51
  };
@@ -4,14 +4,14 @@ export const noArrayHandlersRule = {
4
4
  meta: {
5
5
  docs: {
6
6
  description: "Disallow usage of type-unsafe event handlers.",
7
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-array-handlers.md",
7
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-array-handlers.md"
8
8
  },
9
9
  messages: {
10
10
  noArrayHandlers:
11
- "Passing an array as an event handler is potentially type-unsafe.",
11
+ "Passing an array as an event handler is potentially type-unsafe."
12
12
  },
13
13
  schema: [],
14
- type: "problem",
14
+ type: "problem"
15
15
  },
16
16
  defaultOptions: [],
17
17
  create(context) {
@@ -40,10 +40,10 @@ export const noArrayHandlersRule = {
40
40
  ) {
41
41
  context.report({
42
42
  messageId: "noArrayHandlers",
43
- node,
43
+ node
44
44
  });
45
45
  }
46
- },
46
+ }
47
47
  };
48
- },
48
+ }
49
49
  };
@@ -77,8 +77,7 @@ const isGeneratedCall = (call, callee) => {
77
77
  others.every(
78
78
  (key) =>
79
79
  key.type === "Literal" &&
80
- (typeof key.value === "string" ||
81
- typeof key.value === "number"),
80
+ (typeof key.value === "string" || typeof key.value === "number")
82
81
  )
83
82
  );
84
83
  };
@@ -105,7 +104,7 @@ const getPropertyInfo = (prop) => {
105
104
  init:
106
105
  prop.value.type === "AssignmentPattern"
107
106
  ? prop.value.right
108
- : undefined,
107
+ : undefined
109
108
  };
110
109
  } else {
111
110
  return null;
@@ -117,17 +116,16 @@ export default {
117
116
  docs: {
118
117
  description:
119
118
  "Disallow destructuring props. In Solid, props must be used with property accesses (`props.foo`) to preserve reactivity. This rule only tracks destructuring in the parameter list.",
120
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-destructure.md",
119
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-destructure.md"
121
120
  },
122
121
  fixable: "code",
123
122
  schema: [],
124
123
  messages: {
125
124
  noDestructure:
126
125
  "Destructuring component props breaks Solid's reactivity; use property access instead.",
127
- missingImport:
128
- "`{{name}}` is used without an import from solid-js.",
126
+ missingImport: "`{{name}}` is used without an import from solid-js."
129
127
  // noWriteToProps: "Component props are readonly, writing to props is not supported.",
130
- },
128
+ }
131
129
  },
132
130
  defaultOptions: [],
133
131
  create(context) {
@@ -201,7 +199,7 @@ export default {
201
199
  (def) =>
202
200
  def.name?.range !== undefined &&
203
201
  def.name.range[0] >= props.range[0] &&
204
- def.name.range[1] <= props.range[1],
202
+ def.name.range[1] <= props.range[1]
205
203
  );
206
204
  if (fixable && callScope) {
207
205
  fixable = propertyInfo.every((info) => {
@@ -216,7 +214,7 @@ export default {
216
214
  if (isInPattern) {
217
215
  // The binding itself, nothing else.
218
216
  return variable.defs.some(
219
- (def) => def.name === reference.identifier,
217
+ (def) => def.name === reference.identifier
220
218
  );
221
219
  }
222
220
  return reference.isReadOnly();
@@ -251,13 +249,13 @@ export default {
251
249
  lookupVariable(callScope, name, removedByFix) !== null ||
252
250
  rewrittenScopes.some(
253
251
  (scope) =>
254
- lookupVariable(scope, name, removedByFix) !== null,
252
+ lookupVariable(scope, name, removedByFix) !== null
255
253
  ) ||
256
254
  (scopeManager?.globalScope?.through ?? []).some(
257
255
  ({ identifier }) =>
258
256
  identifier.name === name &&
259
257
  identifier.range[0] >= func.range[0] &&
260
- identifier.range[1] <= func.range[1],
258
+ identifier.range[1] <= func.range[1]
261
259
  );
262
260
  const hasDefaults = propertyInfo.some((info) => info.init);
263
261
  let propsName = "props";
@@ -277,7 +275,7 @@ export default {
277
275
  .filter((info) => info.init)
278
276
  .map(
279
277
  (info) =>
280
- `${info.computed ? "[" : ""}${sourceCode.getText(info.real)}${info.computed ? "]" : ""}: ${sourceCode.getText(info.init)}`,
278
+ `${info.computed ? "[" : ""}${sourceCode.getText(info.real)}${info.computed ? "]" : ""}: ${sourceCode.getText(info.init)}`
281
279
  )
282
280
  .join(", ");
283
281
  // `omit(props, "a", "b")` takes the keys as varargs, where Solid
@@ -287,7 +285,7 @@ export default {
287
285
  .map((info) =>
288
286
  info.real.type === "Identifier"
289
287
  ? JSON.stringify(info.real.name)
290
- : sourceCode.getText(info.real),
288
+ : sourceCode.getText(info.real)
291
289
  )
292
290
  .join(", ");
293
291
  const restName = () =>
@@ -309,19 +307,19 @@ export default {
309
307
  (node) =>
310
308
  node.type === "ImportDeclaration" &&
311
309
  node.specifiers.some(
312
- (specifier) => specifier.local.name === name,
313
- ),
310
+ (specifier) => specifier.local.name === name
311
+ )
314
312
  );
315
313
  const imports = [];
316
314
  const solidCallName = (name) => {
317
315
  for (const specifier of findSolidImportSpecifiers(
318
316
  program,
319
- name,
317
+ name
320
318
  )) {
321
319
  const variable = lookupVariable(
322
320
  callScope,
323
321
  specifier.local.name,
324
- removedByFix,
322
+ removedByFix
325
323
  );
326
324
  // Unless a nearer binding shadows the import here.
327
325
  if (
@@ -358,7 +356,7 @@ export default {
358
356
  propertyInfo,
359
357
  origProps,
360
358
  lineToInsert,
361
- imports,
359
+ imports
362
360
  };
363
361
  };
364
362
  // The import edit: the names go into the file's `solid-js` value
@@ -381,7 +379,7 @@ export default {
381
379
  propsName,
382
380
  propertyInfo,
383
381
  origProps,
384
- lineToInsert,
382
+ lineToInsert
385
383
  } = plan;
386
384
  const sourceCode = getSourceCode(context);
387
385
  // Replace destructured props with a `props` identifier. Only the
@@ -407,7 +405,7 @@ export default {
407
405
  // Inject lines handling defaults/rest params before the first statement in the block.
408
406
  yield fixer.insertTextBefore(
409
407
  body.body[0],
410
- lineToInsert,
408
+ lineToInsert
411
409
  );
412
410
  }
413
411
  // with an empty block statement body, no need to inject code
@@ -425,7 +423,7 @@ export default {
425
423
  // Inject lines handling defaults/rest params
426
424
  yield fixer.insertTextBefore(
427
425
  body,
428
- `{\n${lineToInsert} return (`,
426
+ `{\n${lineToInsert} return (`
429
427
  );
430
428
  yield fixer.insertTextAfter(body, `);\n}`);
431
429
  }
@@ -435,7 +433,7 @@ export default {
435
433
  // iterate through destructured variables, associated with real node
436
434
  for (const [info, variable] of propertyInfo.map((info) => [
437
435
  info,
438
- scope.set.get(info.var),
436
+ scope.set.get(info.var)
439
437
  ])) {
440
438
  if (variable) {
441
439
  // replace all usages of the variable with props accesses
@@ -457,7 +455,7 @@ export default {
457
455
  reference.identifier,
458
456
  isShorthand
459
457
  ? `${reference.identifier.name}: ${propsName}${access}`
460
- : `${propsName}${access}`,
458
+ : `${propsName}${access}`
461
459
  );
462
460
  }
463
461
  }
@@ -496,7 +494,7 @@ export default {
496
494
  sourceCode.ast.body.some(
497
495
  (node) =>
498
496
  node.type === "ImportDeclaration" &&
499
- node.source.value === SOLID_SOURCE,
497
+ node.source.value === SOLID_SOURCE
500
498
  );
501
499
  const callees = (
502
500
  sourceCode.scopeManager?.globalScope?.through ?? []
@@ -504,7 +502,7 @@ export default {
504
502
  .filter(
505
503
  ({ identifier }) =>
506
504
  isSolidFile &&
507
- isGeneratedCall(identifier.parent, identifier),
505
+ isGeneratedCall(identifier.parent, identifier)
508
506
  )
509
507
  .sort((a, b) => a.identifier.range[0] - b.identifier.range[0]);
510
508
  const danglingImports = [];
@@ -515,17 +513,17 @@ export default {
515
513
  }
516
514
  };
517
515
  callees.forEach(({ identifier }) =>
518
- addImport(danglingImports, generatedImport(identifier.name)),
516
+ addImport(danglingImports, generatedImport(identifier.name))
519
517
  );
520
518
  plans.forEach((plan) =>
521
519
  plan.imports
522
520
  .filter(
523
521
  (entry) =>
524
522
  !danglingImports.some(
525
- (known) => known.local === entry.local,
526
- ),
523
+ (known) => known.local === entry.local
524
+ )
527
525
  )
528
- .forEach((entry) => addImport(plannedImports, entry)),
526
+ .forEach((entry) => addImport(plannedImports, entry))
529
527
  );
530
528
  if (callees.length > 0) {
531
529
  const [{ identifier }] = callees;
@@ -533,7 +531,7 @@ export default {
533
531
  node: identifier,
534
532
  messageId: "missingImport",
535
533
  data: { name: identifier.name },
536
- fix: (fixer) => importFix(fixer, danglingImports),
534
+ fix: (fixer) => importFix(fixer, danglingImports)
537
535
  });
538
536
  }
539
537
  const [carrier] = plans.filter((plan) => plan.fixable);
@@ -541,7 +539,7 @@ export default {
541
539
  if (!plan.fixable) {
542
540
  context.report({
543
541
  node: plan.props,
544
- messageId: "noDestructure",
542
+ messageId: "noDestructure"
545
543
  });
546
544
  return;
547
545
  }
@@ -552,8 +550,8 @@ export default {
552
550
  fixDestructure(
553
551
  plan,
554
552
  plan === carrier ? plannedImports : [],
555
- fixer,
556
- ),
553
+ fixer
554
+ )
557
555
  });
558
556
  });
559
557
  };
@@ -576,7 +574,7 @@ export default {
576
574
  if (functionStack.length) {
577
575
  currentFunction().hasJSX = true;
578
576
  }
579
- },
577
+ }
580
578
  };
581
- },
579
+ }
582
580
  };
@@ -8,7 +8,7 @@ export default {
8
8
  docs: {
9
9
  description:
10
10
  "Disallow usage of the innerHTML attribute, which can often lead to security vulnerabilities.",
11
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-innerhtml.md",
11
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-innerhtml.md"
12
12
  },
13
13
  fixable: "code",
14
14
  hasSuggestions: true,
@@ -20,11 +20,11 @@ export default {
20
20
  description:
21
21
  "if the innerHTML value is guaranteed to be a static HTML string (i.e. no user input), allow it",
22
22
  type: "boolean",
23
- default: true,
24
- },
23
+ default: true
24
+ }
25
25
  },
26
- additionalProperties: false,
27
- },
26
+ additionalProperties: false
27
+ }
28
28
  ],
29
29
  messages: {
30
30
  dangerous:
@@ -36,8 +36,8 @@ export default {
36
36
  useInnerText:
37
37
  "For text content, using innerText is clearer and safer.",
38
38
  dangerouslySetInnerHTML:
39
- "The dangerouslySetInnerHTML prop is not supported; use innerHTML instead.",
40
- },
39
+ "The dangerouslySetInnerHTML prop is not supported; use innerHTML instead."
40
+ }
41
41
  },
42
42
  defaultOptions: [{ allowStatic: true }],
43
43
  create(context) {
@@ -65,25 +65,25 @@ export default {
65
65
  return [
66
66
  fixer.replaceTextRange(
67
67
  [propRange[0], valueRange[0]],
68
- "innerHTML={",
68
+ "innerHTML={"
69
69
  ),
70
70
  fixer.replaceTextRange(
71
71
  [valueRange[1], propRange[1]],
72
- "}",
73
- ),
72
+ "}"
73
+ )
74
74
  ];
75
- },
75
+ }
76
76
  });
77
77
  } else {
78
78
  context.report({
79
79
  node,
80
- messageId: "dangerouslySetInnerHTML",
80
+ messageId: "dangerouslySetInnerHTML"
81
81
  });
82
82
  }
83
83
  } else {
84
84
  context.report({
85
85
  node,
86
- messageId: "dangerouslySetInnerHTML",
86
+ messageId: "dangerouslySetInnerHTML"
87
87
  });
88
88
  }
89
89
  return;
@@ -106,7 +106,7 @@ export default {
106
106
  ) {
107
107
  context.report({
108
108
  node: node.parent.parent, // report error on JSXElement instead of JSXAttribute
109
- messageId: "conflict",
109
+ messageId: "conflict"
110
110
  });
111
111
  }
112
112
  } else {
@@ -118,26 +118,26 @@ export default {
118
118
  fix: (fixer) =>
119
119
  fixer.replaceText(
120
120
  node.name,
121
- "innerText",
121
+ "innerText"
122
122
  ),
123
- messageId: "useInnerText",
124
- },
125
- ],
123
+ messageId: "useInnerText"
124
+ }
125
+ ]
126
126
  });
127
127
  }
128
128
  } else {
129
129
  context.report({
130
130
  node,
131
- messageId: "dangerous",
131
+ messageId: "dangerous"
132
132
  });
133
133
  }
134
134
  } else {
135
135
  context.report({
136
136
  node,
137
- messageId: "dangerous",
137
+ messageId: "dangerous"
138
138
  });
139
139
  }
140
- },
140
+ }
141
141
  };
142
- },
142
+ }
143
143
  };
@@ -13,7 +13,7 @@ const OWNED_PRIMITIVES = [
13
13
  "createReaction",
14
14
  "createRenderEffect",
15
15
  "onCleanup",
16
- "onSettled",
16
+ "onSettled"
17
17
  ];
18
18
 
19
19
  /** The callbacks a `ref` prop applies, including the ones in a ref array. */
@@ -27,7 +27,7 @@ function getRefCallbacks(expression) {
27
27
  // callback like any other.
28
28
  if (expression?.type === "ArrayExpression") {
29
29
  return expression.elements.flatMap((element) =>
30
- element !== null && isFunctionNode(element) ? [element] : [],
30
+ element !== null && isFunctionNode(element) ? [element] : []
31
31
  );
32
32
  }
33
33
 
@@ -73,13 +73,13 @@ export default {
73
73
  docs: {
74
74
  description:
75
75
  "Disallow creating owner-bound primitives inside a ref callback.",
76
- url: "https://docs.solidjs.com/",
76
+ url: "https://docs.solidjs.com/"
77
77
  },
78
78
  schema: [],
79
79
  messages: {
80
80
  ownedPrimitiveInRef:
81
- "`{{name}}` is called inside a ref callback, which runs without an owner — nothing will ever dispose it. Create it in the directive factory instead, and let the returned callback only store the element.",
82
- },
81
+ "`{{name}}` is called inside a ref callback, which runs without an owner — nothing will ever dispose it. Create it in the directive factory instead, and let the returned callback only store the element."
82
+ }
83
83
  },
84
84
  defaultOptions: [],
85
85
  create(context) {
@@ -103,7 +103,7 @@ export default {
103
103
  candidate.callee.type !== "Identifier" ||
104
104
  !matchImport(
105
105
  OWNED_PRIMITIVES,
106
- candidate.callee.name,
106
+ candidate.callee.name
107
107
  )
108
108
  ) {
109
109
  return;
@@ -112,11 +112,11 @@ export default {
112
112
  context.report({
113
113
  node: candidate,
114
114
  messageId: "ownedPrimitiveInRef",
115
- data: { name: candidate.callee.name },
115
+ data: { name: candidate.callee.name }
116
116
  });
117
117
  });
118
118
  }
119
- },
119
+ }
120
120
  };
121
- },
121
+ }
122
122
  };