Giter VIP home page Giter VIP logo

eslint-plugin-monorepo's Introduction

eslint-plugin-monorepo

Travis Prettier npm semantic-release License

A collection of ESLint rules for enforcing import rules in a monorepo. Supports:

Configuration

Use the "recommended" configuration:

// .eslintrc.json
{
  "extends": ["plugin:monorepo/recommended"]
}

Or enable rules manually:

// .eslintrc.json
{
  "plugins": ["monorepo"],
  "rules": {
    "monorepo/no-internal-import": "error",
    "monorepo/no-relative-import": "error"
  }
}

Rules

monorepo/no-internal-import

Forbids importing specific files from a monorepo package.

// Bad
import 'module/src/foo.js';

// Good
import { foo } from 'module';

monorepo/no-relative-import (fixable)

Forbids importing other packages from the monorepo with a relative path.

// Bad
import module from '../module';

// Good
import module from 'module';

eslint-plugin-monorepo's People

Contributors

alonmiz avatar azz avatar jdanil avatar shmidt-i avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eslint-plugin-monorepo's Issues

TypeError in no-internal-import

After the 0.3.0 release, I'm getting this error running eslint.

TypeError: Cannot read property 'location' of undefined
    at .../node_modules/eslint-plugin-monorepo/lib/rules/no-internal-import.js:63:38

I think one of the checks just needs to be moved up. I'll push up a proposed fix.

Enforce package.json dependency

Sometimes in a monorepo one will forget to add a dependency to a package's package.json and it will continue to work because the dependency was hoisted from another package, or it is installed in the root. This means the package cannot be individually installed so should be prevented.

Suggestion: Add Rule to Disallow Imports Between Certain Packages

Our repo is structured into yarn workspaces like this:

  • applications/app1
  • applications/app2
  • common/c1
  • common/c2

The desired rule is that applications might import from packages common/c1 and common/c2, but never from another application. In other words, in app1 there must never be an import from app2.

Currently we use depencency-cruiser for such advanced checks. Sounds like a good use case for this plugin though.

Don't error on a non-monorepo project

Error while loading rule 'monorepo/no-internal-import': unable to find monorepo packages
Error: Error while loading rule 'monorepo/no-internal-import': unable to find monorepo packages
    at exports.default (/Users/haroen/git/eslint-config-algolia/node_modules/eslint-plugin-monorepo/lib/get-packages.js:44:9)
    at Object.create (/Users/haroen/git/eslint-config-algolia/node_modules/eslint-plugin-monorepo/lib/rules/no-internal-import.js:32:44)
    at Object.keys.forEach.ruleId (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/linter.js:925:44)
    at Array.forEach (<anonymous>)
    at Linter._verifyWithoutProcessors (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/linter.js:865:35)
    at preprocess.map.textBlock (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/linter.js:994:35)
    at Array.map (<anonymous>)
    at Linter.verify (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/linter.js:993:42)
    at Linter.verifyAndFix (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/linter.js:1085:29)
    at processText (/Users/haroen/git/eslint-config-algolia/node_modules/eslint/lib/cli-engine.js:179:32)

I get this when running the linting in a project that doesn't have a monorepo because I want to put it in a sharable config. It would be nice if the plugin would just bail out in case there's no monorepo

No-relative-import fixer doesn't actually work

I ran eslint --fix on my monorepo and it correctly identified a relative import as an error but did not fix it, even though this plugin says the relative import error is autofixable.

monorepo/no-internal-import prevents some safe imports

My understanding of this rule is that it's meant to prevent packages in the monorepo from importing files that exist locally, but would not be present after publishing to NPM.

It's also preventing valid internal imports of files that we know do get published to NPM, e.g. anything that is listed in the files array of package.json. For example if we know that package-a has files: ["lib"] in it's package.json, we should be able to tell that an import like import foo from 'package-a/lib/foo.js' is safe.

Would you be open to a flag that allowed these sort of internal imports?

Resolve error: unable to load resolver "node".

If eslint-plugin-import is not installed the plugin will throw the following error:

Resolve error: unable to load resolver "node".  monorepo/no-relative-import

when trying to resolve an import statement.

I not sure why installing eslint-plugin-import solves this issue (maybe incompatible with @typescript-eslint?). Is there a better way to fix this?

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.