Repository navigation
chore(lint): flag package-internal imports through a barrel #9080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0aaf7ea
chore(lint): flag package-internal imports through a barrel
cixzhang de085f6
fix(lint): exempt index files, key the baseline to the repo root, cat…
cixzhang 98f1256
Merge commit '5b76cd5a37e1ab5783a2a6cb8093790d1d4a2860' into lint/no-…
cixzhang 89062ac
chore(lint): refresh the barrel-import baseline on current main (575 …
cixzhang 5bbcb50
fix(lint): read the baseline without the URL global; catch '/index.js…
cixzhang 2d99d9e
Merge commit '6e39742e88d9f9b352423f32b9b6008e5ceeaaa3' into lint/no-…
cixzhang 19562bb
chore(lint): refresh the barrel-import baseline on current main
cixzhang e76cfd6
chore(lint): a baseline script for the barrel rule; keep richtext's b…
cixzhang ad45d0f
Merge commit '0ef60ddb6234ba71354bbf67324586bb97ba7a53' into lint/no-…
cixzhang df7c562
chore(lint): share the barrel rule's file scope with its baseline script
cixzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import {defineConfig} from 'eslint/config'; | ||
| import {includeIgnoreFile} from '@eslint/compat'; | ||
| import path from 'node:path'; | ||
| import {readFileSync} from 'node:fs'; | ||
| import js from '@eslint/js'; | ||
| import tseslint from 'typescript-eslint'; | ||
| import eslintReact from '@eslint-react/eslint-plugin'; | ||
|
|
@@ -31,6 +32,32 @@ | |
| : astryxPlugin.configs.recommended; | ||
| const reactSeverity = isStrictMode ? 'error' : 'warn'; | ||
|
|
||
| // Barrel imports that existed when `@astryx/no-internal-barrel-import` arrived, | ||
| // by repo-relative file. The list only shrinks. | ||
| const internalBarrelBaseline = JSON.parse( | ||
| readFileSync( | ||
| new URL( | ||
| './internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json', | ||
| import.meta.url, | ||
| ), | ||
| 'utf8', | ||
| ), | ||
| ); | ||
| // Tests, stories and test helpers never ship, so they may import barrels; a | ||
| // barrel itself (a folder's or a package's index) is the public surface and | ||
| // may re-export from other barrels (`architecture:public-component-api`). | ||
| const INTERNAL_BARREL_EXEMPT_FILES = [ | ||
| '**/index.*', | ||
| '**/*.test.*', | ||
| '**/*.spec.*', | ||
| '**/*.stories.*', | ||
| '**/*.testing.*', | ||
| '**/*.render-testing.*', | ||
| '**/__tests__/**', | ||
| '**/__fixtures__/**', | ||
| '**/dist/**', | ||
| ]; | ||
|
|
||
| // The internal plugin is plain untyped JS (kept out of the lint/type surface), | ||
| // so its inferred shape doesn't satisfy ESLint's strict `Plugin` type. One | ||
| // localized assertion here keeps every `plugins` entry below type-checked. | ||
|
|
@@ -863,6 +890,27 @@ | |
| // | ||
| // Remove an entry here as its backlog closes; the file is clean when the | ||
| // block is empty. | ||
| // Inside a package's own shipped source, import the module that defines a | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block lands between richtext's backlog comment (lines 878-892) and the richtext block at line 914, so that comment now reads as if it describes the barrel rule. Moving this block and its comment above line 878 keeps richtext's block last and its comment attached. |
||
| // name, not a folder's index (a barrel): a lazily imported module that goes | ||
| // through a barrel pulls every sibling export into its graph, which broke | ||
| // the single-file bundle. Public consumers keep importing from the package | ||
| // entry. The barrel imports that predate the rule are listed in the | ||
| // baseline and stay allowed until a codemod removes them; anything new is | ||
| // reported (an error in strict mode, so a pull request that adds one fails | ||
| // lint, while main stays green). Type-only imports are erased and allowed. | ||
| { | ||
| files: ['packages/*/src/**/*.{ts,tsx,mts,cts,js,jsx,mjs}'], | ||
| ignores: INTERNAL_BARREL_EXEMPT_FILES, | ||
| plugins: { | ||
| '@astryx': astryxEslintPlugin, | ||
| }, | ||
| rules: { | ||
| '@astryx/no-internal-barrel-import': [ | ||
| reactSeverity, | ||
| {baseline: internalBarrelBaseline, root: import.meta.dirname}, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| files: ['packages/richtext/src/**/*.{ts,tsx}'], | ||
| rules: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URLis not declared for this file (only/* global process */at line 13), sopnpm lintreports'URL' is not defined(no-undef) here in strict and local mode; the Lint check for this head fails on it. Reading the file the way the.gitignoreimports do avoids the global:readFileSync(path.join(import.meta.dirname, 'internal/eslint-plugin-astryx/no-internal-barrel-import.baseline.json'), 'utf8').