eslint-plugin-require-use-server 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +29 -0
- package/.nvmrc +1 -0
- package/.prettierrc +19 -0
- package/README.md +57 -2
- package/package.json +26 -3
- package/src/index.ts +13 -0
- package/src/require-use-server.ts +47 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Publish Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write # Required for OIDC
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v7
|
|
17
|
+
|
|
18
|
+
- uses: pnpm/action-setup@v6
|
|
19
|
+
with:
|
|
20
|
+
version: 12
|
|
21
|
+
|
|
22
|
+
- uses: actions/setup-node@v7
|
|
23
|
+
with:
|
|
24
|
+
node-version: '24.21.0'
|
|
25
|
+
registry-url: 'https://registry.npmjs.org'
|
|
26
|
+
cache: 'pnpm'
|
|
27
|
+
- run: pnpm install --frozen-lockfile
|
|
28
|
+
- run: pnpm build
|
|
29
|
+
- run: pnpm publish # Or: npm stage publish
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v24.21.0
|
package/.prettierrc
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"tabWidth": 4,
|
|
5
|
+
"useTabs": true,
|
|
6
|
+
"arrowParens": "avoid",
|
|
7
|
+
"jsxSingleQuote": false,
|
|
8
|
+
"experimentalTernaries": true,
|
|
9
|
+
"bracketSpacing": true,
|
|
10
|
+
"insertPragma": false,
|
|
11
|
+
"requirePragma": false,
|
|
12
|
+
"trailingComma": "all",
|
|
13
|
+
"semi": true,
|
|
14
|
+
"printWidth": 120,
|
|
15
|
+
"importOrder": ["^[./]"],
|
|
16
|
+
"importOrderSeparation": true,
|
|
17
|
+
"importOrderSortSpecifiers": true,
|
|
18
|
+
"importOrderSortByLength": "asc"
|
|
19
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# eslint-plugin-use-server-top-level
|
|
2
|
+
|
|
3
|
+
Custom ESLint rule to ensure specified files start with `use server`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- Checks if the first code line of matched files is `'use server'` or `"use server"`.
|
|
7
|
+
- Skips leading comments and empty lines.
|
|
8
|
+
- Path matching is configurable via the `pathPattern` option.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
- ESLint 9 or 10 (flat config)
|
|
12
|
+
- Node.js `^20.19.0 || ^22.13.0 || >=24`
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install eslint-plugin-require-use-server --save-dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
1. Import the plugin in your ESLint config (e.g. `eslint.config.mjs`):
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import useServerPlugin from '@leo-tools/eslint-plugin-use-server-top-level';
|
|
26
|
+
|
|
27
|
+
export default [
|
|
28
|
+
{
|
|
29
|
+
plugins: {
|
|
30
|
+
'use-server': useServerPlugin,
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
// Configure the rule and specify the path pattern
|
|
34
|
+
'use-server/require-use-server': ['error', { pathPattern: 'src/services/actions/.*\\.ts$' }],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Run ESLint on your target files:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
eslint
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
- `pathPattern` (string): Regex pattern to match file paths. Only matched files will be checked.
|
|
48
|
+
|
|
49
|
+
## Example
|
|
50
|
+
If a file at `src/services/actions/foo.ts` does not start with `use server`, ESLint will report an error:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Error: servers/actions/*.ts must start with 'use server'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
MIT
|
|
2
58
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-require-use-server",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "KLewin23",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/KLewin23/eslint-plugin-require-use-server"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
14
|
+
"@types/eslint": "^9.6.1",
|
|
15
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
16
|
+
"eslint": "^10.12.0",
|
|
17
|
+
"prettier": "^3.9.10",
|
|
18
|
+
"typescript": "^7.0.2"
|
|
19
|
+
},
|
|
20
|
+
"config": {
|
|
21
|
+
"commitizen": {
|
|
22
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"commit": "cz"
|
|
28
|
+
}
|
|
6
29
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
const rule: Rule.RuleModule = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Require 'use server' at the top of the file",
|
|
8
|
+
},
|
|
9
|
+
schema: [
|
|
10
|
+
{
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
pathPattern: { type: 'string' },
|
|
14
|
+
},
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
defaultOptions: [{ pathPattern: 'src/.*\\.ts$' }],
|
|
19
|
+
messages: {
|
|
20
|
+
missingUseServer: "{{filename}} must start with 'use server'",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
create: context => {
|
|
24
|
+
const options = context.options[0] || {};
|
|
25
|
+
const pathPattern = options.pathPattern || 'src/.*\\.ts$';
|
|
26
|
+
const filename = context.filename;
|
|
27
|
+
if (!new RegExp(pathPattern).test(filename)) return {};
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
Program(node) {
|
|
31
|
+
const sourceCode = context.sourceCode;
|
|
32
|
+
const lines = sourceCode.getText().split(/\r?\n/);
|
|
33
|
+
const firstLine = lines[0] ?? '';
|
|
34
|
+
|
|
35
|
+
if (!firstLine.startsWith("'use server'")) {
|
|
36
|
+
context.report({
|
|
37
|
+
node,
|
|
38
|
+
messageId: 'missingUseServer',
|
|
39
|
+
data: { filename },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export = rule;
|