eslint-plugin-required-exports
v0.2.0
Published
ESLint plugin that enforces exports of declarations like const, type, interface, class, enum
Maintainers
Readme
eslint-plugin-required-exports
An ESLint plugin that enforces exports for top-level declarations like const, function, class, interface, type, and enum.
Installation
npm install --save-dev eslint-plugin-required-exports
# or
pnpm add -D eslint-plugin-required-exports
# or
yarn add -D eslint-plugin-required-exportsUsage
ESLint 9 (Flat Config)
import requiredExports from 'eslint-plugin-required-exports';
export default [
{
plugins: {
'required-exports': requiredExports,
},
rules: {
'required-exports/required-exports': 'error',
},
},
// or use the recommended config
requiredExports.configs.recommended,
];Legacy ESLint Config
{
"plugins": ["required-exports"],
"rules": {
"required-exports/required-exports": "error"
}
}Rule: required-exports
This rule enforces that top-level declarations must be exported.
❌ Examples of incorrect code
const myConstant = 42;
function myFunction() {}
class MyClass {}
interface MyInterface {}
type MyType = string;
enum MyEnum { A, B }✅ Examples of correct code
export const myConstant = 42;
export function myFunction() {}
export class MyClass {}
export interface MyInterface {}
export type MyType = string;
export enum MyEnum { A, B }
// Or using export statements
const myConstant = 42;
export { myConstant };
// Private identifiers are ignored by default
const _privateConstant = 42;
function _privateFunction() {}Options
The rule accepts an options object with the following properties:
{
variable?: boolean; // default: true
function?: boolean; // default: true
class?: boolean; // default: true
interface?: boolean; // default: true
type?: boolean; // default: true
enum?: boolean; // default: true
ignorePrivate?: boolean; // default: true
}Examples
// Only check functions and classes
{
"required-exports/required-exports": ["error", {
"variable": false,
"function": true,
"class": true,
"interface": false,
"type": false,
"enum": false
}]
}
// Don't ignore private identifiers
{
"required-exports/required-exports": ["error", {
"ignorePrivate": false
}]
}Auto-fix
This rule supports auto-fixing. It will automatically add the export keyword to declarations that are missing it.
Development
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Create a release
pnpm releaseRelease Setup
To create releases, you'll need to configure environment variables:
Copy the example environment file:
cp .env.example .envFill in your tokens in
.env:# GitHub Personal Access Token for releases GITHUB_TOKEN=ghp_your_token_here # NPM Token for publishing NPM_TOKEN=npm_your_token_here # Git configuration GIT_USER_NAME="Your Name" GIT_USER_EMAIL="[email protected]"Create tokens:
- GitHub Token: Go to GitHub Settings > Tokens
- Required scopes:
repo(for private repos) orpublic_repo(for public repos)
- Required scopes:
- NPM Token: Go to NPM Settings > Tokens
- Required scope:
AutomationorPublish
- Required scope:
- GitHub Token: Go to GitHub Settings > Tokens
Run release commands:
# Dry run to test the release process pnpm release:dry # Create an actual release pnpm release
License
MIT
