uhyo / eslint-plugin-import-access Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.npmjs.com/package/eslint-plugin-import-access
License: MIT License
Home Page: https://www.npmjs.com/package/eslint-plugin-import-access
License: MIT License
When import a file via import * as
, there is still a chance to expose package/private exports to outside. Is it a bug or design limitation?
// ----- sub/foo.ts -----
/** @public */
export const public_var = 0;
/** @package */
export const package_var = 0;
// ----- baz.ts -----
import * as Foo from "./sub/foo";
Foo.public_var;
Foo.package_var;
// ^ expect error here
Documentation does not make it clear whether it needs to be added to just one or both.
As this concerns the API design of this plugin, I will start from this proposal. As a new feature, I would like to add selfReferencingLoophole via the exports
field in the package.json.
Let me explain in details with a specific use case. In the component library I am currently developing, I am writing Storybook stories only for the public API. In the package.json, I have specified the exports as follows, and I use them in Storybook like import { SomeComponent } from 'my-library/components'
. (This is called as self-referencing in the Node.js document)
{
"name": "my-library",
"exports": {
"./components": {
"type": "./src/components/index.ts",
"default": "./src/components/index.ts",
},
"./styles": {
"type": "./src/styles/index.ts",
"default": "./src/styles/index.ts",
},
}
Currently, I have to manually add the @public
comment tag to all the members exported from src/components/index.ts. This is because I have set the defaultImportability
to 'package'
, and I place story files in a 'stories'
directory which is a sibling directory of 'src'
.
However, since src/components/index.ts
is intended as the public API, the task of adding comment tags feels excessively cumbersome. It would be greatly appreciated if, as an option, we could have self-referencing automatically treated as public.
When I try export from like this :
/app/bff/client.ts
export const function1 = () => {}
export const function2 = () => {}
...
export const function_n = () => {}
And in app
folder I have exported will package jsdoc like this.
/*
@public
*/
export * from './client'
From the same level folder with bff
. Let's say component
folder . I try to to import like this.
import {function1} from './bff
It's will throw Cannot import a package-private export 'function1'
.
Is that a bug of plugin. Or can you show me how to solve this problem.
This package is a very good project that implemented what I thought. However, there are some things that I would like to see updated further. It would be more perfect if we could restrict imports to each other even within the same folder path.
/**
* @package
* "./page/home.tsx"
*/
List the available paths as follows. Can you please update this feature??
A grammar that restricts all imports, a grammar that allows only some paths to be used
It would be nice to add these two.
If you don't have enough resources to work on this project, I'll blow a PR and add it! Just say something.
Thank you for this amazing plugin @uhyo!
I have two questions:
@package
rule to an entire file?We cannot use eslint-plugin-import-access
with Flat Config. ๐จ This is caused by providing TypeScript Language Server Plugin from the same module.
import typescriptEslintParser from "@typescript-eslint/parser";
import importAccess from 'eslint-plugin-import-access';
export default [
{
languageOptions: {
parser: typescriptEslintParser,
},
files: ['**/*.ts'],
plugins: {
'import-access': importAccess,
},
rules: {
'import-access/jsdoc': 'error'
}
}
]
ESLint: 9.0.0
ConfigError: Config (unnamed): Key "plugins": Key "import-access": Expected an object.
plugins: {
'import-access': { ...importAccess },
},
We must deal with breaking changes made in v9: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/
Hey,
so I followed the setup (added config to eslint and tsconfig) and in all of my .tsx
files I have the error mentioned above. I see it's specific to this library and I have no idea what it means...
Hi.
I found that I can reexport members annotated with @private
, although importing them is incorrect as expected)
I have a reproduction code available at the following GitHub repository: https://github.com/m-shaka/minimum-reproduction-private-access.
Interestingly, I added a test to check private:reexport in a forked repository, and the rule seems to be working fine!
You can find the commit with the test here:
f0d5fae
Do you have any idea about the cause behind this behavior?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.