@leo-tools/eslint-plugin-use-server-top-level
v1.0.0
Published
Custom ESLint rule to ensure specified TypeScript files start with `'use server'`.
Downloads
6
Maintainers
Readme
eslint-plugin-use-server-top-level
Custom ESLint rule to ensure specified TypeScript files start with 'use server'.
Features
- Checks if the first code line of matched files is
'use server'or"use server". - Skips leading comments and empty lines.
- Path matching is configurable via the
pathPatternoption.
Installation
npm install @leo-tools/eslint-plugin-use-server-top-level --save-devUsage
- Import the plugin in your ESLint config (e.g.
eslint.config.mjs):
import useServerPlugin from '@leo-tools/eslint-plugin-use-server-top-level';
export default [
{
plugins: {
'use-server': useServerPlugin,
},
rules: {
// Configure the rule and specify the path pattern
'use-server/require-use-server': ['error', { pathPattern: 'src/services/actions/.*\\.ts$' }],
},
},
];- Run ESLint on your target files:
eslintOptions
pathPattern(string): Regex pattern to match file paths. Only matched files will be checked.
Example
If a file at src/services/actions/foo.ts does not start with 'use server', ESLint will report an error:
Error: servers/actions/*.ts must start with 'use server'License
MIT
