talk icon indicating copy to clipboard operation
talk copied to clipboard

[CORL-2524] Create a simple import blocker that checks for cross imports

Open nick-funk opened this issue 3 years ago • 2 comments

What does this PR do?

Prevents you from importint coral-server into src/core/client source files and vice versa for coral-client into src/core/server.

Runs as part of our linting.

Configuration is in importBlocker.json at the root of the repository.

What changes to the GraphQL/Database Schema does this PR introduce?

None

Does this PR introduce any new environment variables or feature flags?

No

If any indexes were added, were they added to INDEXES.md?

No new indexes added.

How do I test this PR?

  • Run npm run lint
  • Check that the output includes Blocked imports linter found 0 errors.
  • Add an import from the server to a client source file, the following is a good example:
    import logger from "coral-server/logger";
    import {
      Cursor,
      createCollection,
    } from "coral-server/models/helpers";
    
  • Add an import from the client to a server source file, the following is a good example:
    import { CommentContainer_viewer as ViewerData } from "coral-stream/__generated__/CommentContainer_viewer.graphql";
    
  • Run npm run lint again
  • See that the output includes errors from the blocked imports linter and it lists out the files, line numbers, and line context

How do we deploy this PR?

No special considerations needed to deploy.

nick-funk avatar Apr 27 '22 16:04 nick-funk

Deploy Preview for gallant-galileo-14878c canceled.

Name Link
Latest commit 326cf847856c8fa97cdf0c3334cbb2ad0af23130
Latest deploy log https://app.netlify.com/sites/gallant-galileo-14878c/deploys/64496790e9bb7e000866c359

netlify[bot] avatar Apr 27 '22 16:04 netlify[bot]

The import server to client example above works correctly, but the import client to server doesn't fail linting with the example above. In the code, the blockedImports for server is: "blockedImports": [ "coral-client/" ],

The example above is importing from coral-stream, if I change the blockedImports to: "blockedImports": [ "coral-client/", "coral-stream/" ], Then linting fails appropriately.

dennisrjohn avatar Apr 28 '22 17:04 dennisrjohn