about summary refs log tree commit diff
path: root/eslint/use-prefixed-imports.js
diff options
context:
space:
mode:
Diffstat (limited to 'eslint/use-prefixed-imports.js')
-rw-r--r--eslint/use-prefixed-imports.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/eslint/use-prefixed-imports.js b/eslint/use-prefixed-imports.js
new file mode 100644
index 000000000..141d53648
--- /dev/null
+++ b/eslint/use-prefixed-imports.js
@@ -0,0 +1,39 @@
+const BANNED_IMPORT_PREFIXES = [
+  'alf/',
+  'components/',
+  'lib/',
+  'locale/',
+  'logger/',
+  'platform/',
+  'state/',
+  'storage/',
+  'view/',
+]
+
+module.exports = {
+  meta: {
+    type: 'suggestion',
+    fixable: 'code',
+  },
+  create(context) {
+    return {
+      ImportDeclaration(node) {
+        const source = node.source
+        if (typeof source.value !== 'string') {
+          return
+        }
+        if (
+          BANNED_IMPORT_PREFIXES.some(banned => source.value.startsWith(banned))
+        ) {
+          context.report({
+            node: source,
+            message: `Use '#/${source.value}'`,
+            fix(fixer) {
+              return fixer.replaceText(source, `'#/${source.value}'`)
+            },
+          })
+        }
+      },
+    }
+  },
+}