Giter VIP home page Giter VIP logo

Comments (1)

jrwpatterson avatar jrwpatterson commented on September 10, 2024

@anand-sundaram-zocdoc little late I know but if you never solved this or anybody else that has this problem. I have created a pr for this #30 don't know if the library is still being maintained. if not add the following code into your library.

I this also adds a fixer for the no-internal-import

I have created a file patches/eslint-plugin-monorepo.patch
Then put that code in there
then in my package.json I have:

    "eslint-plugin-monorepo": "patch:[email protected]#patches/eslint-plugin-monorepo.patch"
diff --git a/lib/rules/no-internal-import.js b/lib/rules/no-internal-import.js
index c56792a399c37553d92891a26347d218bba74037..a801eb08c2d694721f98adbab80b77e70245303b 100644
--- a/lib/rules/no-internal-import.js
+++ b/lib/rules/no-internal-import.js
@@ -34,7 +34,8 @@ var _fs2 = _interopRequireDefault(_fs);
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
 var meta = exports.meta = {
-  schema: [(0, _moduleVisitor.makeOptionsSchema)({})]
+  schema: [(0, _moduleVisitor.makeOptionsSchema)({})],
+  fixable: 'code'
 };
 
 var withoutExtension = function withoutExtension(importFile, fileEntry) {
@@ -102,7 +103,11 @@ var create = exports.create = function create(context) {
 
     context.report({
       node: node,
-      message: 'Import for monorepo package \'' + name + '\' is internal.'
+      message: 'Import for monorepo package \'' + name + '\' is internal.',
+      fix: function fix(fixer) {
+        const path = _path.parse(node.value).dir
+        return fixer.replaceText(node, '\'' + path + '\'');
+      }
     });
   }, moduleUtilOptions);
 };
diff --git a/lib/rules/no-relative-import.js b/lib/rules/no-relative-import.js
index 1298280d1e67e7753fc8bc7d9fc8dcbf1d8477dd..f2c048be13f221e1e12cdc012210fd0a5159c476 100644
--- a/lib/rules/no-relative-import.js
+++ b/lib/rules/no-relative-import.js
@@ -33,12 +33,17 @@ var _getMonorepoPackages2 = _interopRequireDefault(_getMonorepoPackages);
 
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
-var meta = exports.meta = {
-  schema: [(0, _moduleVisitor.makeOptionsSchema)({})],
-  fixable: 'code'
-};
-
-var create = exports.create = function create(context) {
+module.exports = {
+ meta: {
+  docs: {
+      description: "disallow relative imports",
+      category: "Possible Errors",
+      recommended: true
+  },
+  schema: [],
+  fixable: "code",
+ },
+ create: function create(context) {
   var _context$options = _slicedToArray(context.options, 1),
       moduleUtilOptions = _context$options[0];
 
@@ -47,6 +52,7 @@ var create = exports.create = function create(context) {
 
   return (0, _moduleVisitor2.default)(function (node) {
     var resolvedPath = (0, _resolve2.default)(node.value, context);
+
     var packageDir = getPackageDir(sourceFsPath, packages);
 
     if (!packageDir || !resolvedPath || (0, _pathIsInside2.default)(resolvedPath, packageDir)) {
@@ -61,15 +67,19 @@ var create = exports.create = function create(context) {
     }
 
     var subPackagePath = _path2.default.relative(pkg.location, resolvedPath);
-    context.report({
+    return context.report({
       node: node,
       message: 'Import for monorepo package \'' + pkg.package.name + '\' should be absolute.',
       fix: function fix(fixer) {
-        fixer.replaceText(node, '' + pkg.package.name + (subPackagePath !== '.' ? '/' + subPackagePath : ''));
+        const basePath = '' + pkg.package.name + (subPackagePath !== '.' ? '/' + subPackagePath : '')
+        const path = _path.parse(basePath).dir
+        const name = _path.parse(basePath).name
+        return fixer.replaceText(node, '\'' + (name !== '.' && name !== 'index' ? path + '/' + name : path) + '\'');
       }
     });
   }, moduleUtilOptions);
-};
+ }
+}
 
 var getPackageDir = function getPackageDir(filePath, packages) {
   var match = packages.find(function (pkg) {

from eslint-plugin-monorepo.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.