eslint-plugin-absolute 0.3.0 → 0.4.0

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.
Files changed (2) hide show
  1. package/dist/index.js +37 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -225,6 +225,37 @@ var hasDuplicateNames = (names) => {
225
225
  }
226
226
  return false;
227
227
  };
228
+ var hasDuplicatePropertyNames = (properties) => {
229
+ const kindsByName = new Map;
230
+ for (const property of properties) {
231
+ if (property.type !== "Property") {
232
+ continue;
233
+ }
234
+ let keyName = null;
235
+ if (property.key.type === "Identifier") {
236
+ keyName = property.key.name;
237
+ } else if (property.key.type === "Literal") {
238
+ const { value } = property.key;
239
+ keyName = typeof value === "string" ? value : String(value);
240
+ }
241
+ if (keyName === null) {
242
+ continue;
243
+ }
244
+ const kinds = kindsByName.get(keyName) ?? [];
245
+ kinds.push(property.kind);
246
+ kindsByName.set(keyName, kinds);
247
+ }
248
+ for (const kinds of kindsByName.values()) {
249
+ if (kinds.length === 1) {
250
+ continue;
251
+ }
252
+ if (kinds.length === 2 && kinds.includes("get") && kinds.includes("set")) {
253
+ continue;
254
+ }
255
+ return true;
256
+ }
257
+ return false;
258
+ };
228
259
  var sortKeysFixable = {
229
260
  create(context) {
230
261
  const { sourceCode } = context;
@@ -342,7 +373,7 @@ var sortKeysFixable = {
342
373
  };
343
374
  const addAncestorConstBindings = (ancestor, node, stableLocals) => {
344
375
  const addDeclarationBindings = (statement) => {
345
- if (statement.type !== "VariableDeclaration" || statement.kind !== "const") {
376
+ if (statement.type !== "VariableDeclaration") {
346
377
  return;
347
378
  }
348
379
  for (const declaration of statement.declarations) {
@@ -377,6 +408,7 @@ var sortKeysFixable = {
377
408
  for (const ancestor of ancestors) {
378
409
  addAncestorBindingsForNode(ancestor, node, stableLocals);
379
410
  }
411
+ stableLocals.add("this");
380
412
  return stableLocals;
381
413
  };
382
414
  const getStaticMemberName = (memberExpression) => {
@@ -800,6 +832,9 @@ var sortKeysFixable = {
800
832
  if (!node || node.type === "PrivateIdentifier") {
801
833
  return false;
802
834
  }
835
+ if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSInstantiationExpression") {
836
+ return isPureRuntimeExpression(node.expression, stableLocals);
837
+ }
803
838
  switch (node.type) {
804
839
  case "Identifier":
805
840
  return isStableIdentifier(node.name, stableLocals);
@@ -1038,7 +1073,7 @@ ${indent}`;
1038
1073
  node: prop
1039
1074
  };
1040
1075
  });
1041
- if (hasDuplicateNames(keys.map((key) => key.keyName))) {
1076
+ if (hasDuplicatePropertyNames(node.properties)) {
1042
1077
  autoFixable = false;
1043
1078
  }
1044
1079
  if (autoFixable) {
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "typecheck": "bun run tsc --noEmit"
41
41
  },
42
42
  "type": "module",
43
- "version": "0.3.0"
43
+ "version": "0.4.0"
44
44
  }