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
Changes from 1 commit
0aaf7ea
de085f6
98f1256
89062ac
5bbcb50
2d99d9e
19562bb
e76cfd6
ad45d0f
df7c562
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,29 @@ | |
| : 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. | ||
| const INTERNAL_BARREL_TEST_FILES = [ | ||
| '**/*.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 +887,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_TEST_FILES, | ||
|
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 also covers package entries and component barrels. Adding |
||
| plugins: { | ||
| '@astryx': astryxEslintPlugin, | ||
| }, | ||
| rules: { | ||
| '@astryx/no-internal-barrel-import': [ | ||
| reactSeverity, | ||
| {baseline: internalBarrelBaseline}, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| files: ['packages/richtext/src/**/*.{ts,tsx}'], | ||
| rules: { | ||
|
|
||
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').