@discourse/lint-configs 2.13.1 → 2.13.2

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.
@@ -20,7 +20,7 @@ export default {
20
20
  message:
21
21
  "Import from 'i18n' is not allowed. Use 'discourse-i18n' instead.",
22
22
  fix(fixer) {
23
- return fixer.replaceText(node.source, "'discourse-i18n'");
23
+ return fixer.replaceText(node.source, `"discourse-i18n"`);
24
24
  },
25
25
  });
26
26
  }
@@ -35,13 +35,22 @@ export default {
35
35
  fix(fixer) {
36
36
  const canSafelyReplace =
37
37
  node.specifiers.length === 1 &&
38
- node.specifiers[0].type === "ImportDefaultSpecifier" &&
39
- node.specifiers[0].local.name === "i18n";
38
+ node.specifiers[0].type === "ImportDefaultSpecifier";
40
39
 
41
40
  if (!canSafelyReplace) {
42
41
  return;
43
42
  }
44
43
 
44
+ const localName = node.specifiers[0].local.name;
45
+ let sourceName = node.source.value.match(/([^/]+)$/)[0];
46
+ let importString;
47
+
48
+ if (localName === sourceName) {
49
+ importString = `${localName}`;
50
+ } else {
51
+ importString = `${sourceName} as ${localName}`;
52
+ }
53
+
45
54
  const existingImport = context
46
55
  .getSourceCode()
47
56
  .ast.body.find(
@@ -54,13 +63,13 @@ export default {
54
63
  return [
55
64
  fixer.remove(node),
56
65
  fixImport(fixer, existingImport, {
57
- namedImportsToAdd: ["i18n"],
66
+ namedImportsToAdd: [importString],
58
67
  }),
59
68
  ];
60
69
  } else {
61
70
  return fixer.replaceText(
62
71
  node,
63
- `import { i18n } from 'discourse-i18n';`
72
+ `import { ${importString} } from "discourse-i18n";`
64
73
  );
65
74
  }
66
75
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discourse/lint-configs",
3
- "version": "2.13.1",
3
+ "version": "2.13.2",
4
4
  "description": "Shareable lint configs for Discourse core, plugins, and themes",
5
5
  "author": "Discourse",
6
6
  "license": "MIT",