brave / ads-ui

Self-service ads UI
Mozilla Public License 2.0
22 stars 11 forks source link

refactor: switch to using `@/` for in-app imports #1170

Closed tackley closed 4 months ago

tackley commented 4 months ago

Use @/name for app imports, as opposed to just name as previously. This is the modern convention for web apps, and makes clearer when imports are coming from the application as opposed to npm modules.

There's a few deep ../../ style imports remaining - these get worse if I move them to @/-style imports, and I think are better left until we move the files around a bit more in a subsequent PR.

github-actions[bot] commented 4 months ago

[puLL-Merge] - brave/ads-ui@1170

Here is my review of the pull request:

Description

This PR updates import statements throughout the codebase to use absolute imports with a @ alias pointing to the src directory. This allows importing modules using a consistent syntax like import { Foo } from "@/path/to/Foo" rather than relative paths like import { Foo } from "../../path/to/Foo".

Changes ### Changes - `tsconfig.json`: Adds a `paths` configuration to map the `@` alias to the `src` directory. - All files under `src`: Updates import statements to use the `@` absolute import alias instead of relative import paths.

Security Hotspots

No obvious security issues. The changes are limited to updating import statements which should not introduce any vulnerabilities.

The use of absolute imports with an alias has a few benefits:

  1. Makes import statements more readable and consistent
  2. Avoids issues with long and hard to follow relative import paths
  3. Allows easily moving files around without having to update many relative imports

Overall this is a straightforward refactor that improves the developer experience without changing any functionality. The changes look good to me and I would approve this PR.

Let me know if you have any other questions!