@elnop/eslint-plugin-store-layout 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 elnop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @elnop/eslint-plugin-store-layout
2
2
 
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.
3
+ A store file named `xStore` (any extension) exports `xStore` and, optionally, `xActions`, and nothing else. `viewStore.ts` may export `viewStore` and `viewActions`. Any other export is reported, and so is a missing `viewStore`.
4
+
5
+ Written for zustand stores, but the rule only looks at file and export names.
6
+
7
+ Works with oxlint and ESLint.
8
+
9
+ ```sh
10
+ npm install --save-dev @elnop/eslint-plugin-store-layout
11
+ ```
12
+
13
+ ## oxlint
14
+
15
+ ```json
16
+ {
17
+ "jsPlugins": ["@elnop/eslint-plugin-store-layout"],
18
+ "rules": { "store-layout/store-layout": "error" }
19
+ }
20
+ ```
21
+
22
+ ## ESLint
23
+
24
+ ```js
25
+ import storeLayout from '@elnop/eslint-plugin-store-layout';
26
+
27
+ export default [
28
+ {
29
+ plugins: { 'store-layout': storeLayout },
30
+ rules: { 'store-layout/store-layout': 'error' },
31
+ },
32
+ ];
33
+ ```
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@oxlint/plugins").Plugin;
2
+ export { _default as default };
package/dist/plugin.js ADDED
@@ -0,0 +1,68 @@
1
+ import { definePlugin, defineRule } from "@oxlint/plugins";
2
+ import { basename } from "node:path";
3
+ // ../../utils/lint-utils/dist/baseName.js
4
+ function baseName(filename) {
5
+ return (filename.split("/").pop() ?? "").replace(/\.[^.]+$/, "");
6
+ }
7
+ // ../../utils/lint-utils/dist/exportsOf.js
8
+ function declaredNames(declaration) {
9
+ if (declaration.type === "VariableDeclaration") return declaration.declarations.flatMap((declarator) => declarator.id.type === "Identifier" ? [declarator.id.name] : []);
10
+ return "id" in declaration && declaration.id && "name" in declaration.id ? [declaration.id.name] : [];
11
+ }
12
+ function exportsOf(program) {
13
+ return program.body.flatMap((node) => {
14
+ if (node.type !== "ExportNamedDeclaration") return [];
15
+ return (node.declaration ? declaredNames(node.declaration) : node.specifiers.map((specifier) => specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value)).map((name) => ({
16
+ name,
17
+ node
18
+ }));
19
+ });
20
+ }
21
+ // storeLayout.ts
22
+ const storeLayout = defineRule({
23
+ meta: {
24
+ type: "suggestion",
25
+ docs: { description: "A xStore.ts file exports only xStore and xActions." },
26
+ messages: {
27
+ foreignExport: "{{file}} only exports {{store}} and {{actions}}: move {{name}} out of it.",
28
+ missingStore: "{{file}} must export {{store}}."
29
+ },
30
+ schema: []
31
+ },
32
+ create(context) {
33
+ return { Program(program) {
34
+ const file = basename(context.filename);
35
+ const store = baseName(context.filename);
36
+ if (!store.endsWith("Store")) return;
37
+ const actions = store.replace(/Store$/, "Actions");
38
+ const entries = exportsOf(program);
39
+ for (const entry of entries) {
40
+ if (entry.name === store || entry.name === actions) continue;
41
+ context.report({
42
+ node: entry.node,
43
+ messageId: "foreignExport",
44
+ data: {
45
+ file,
46
+ store,
47
+ actions,
48
+ name: entry.name
49
+ }
50
+ });
51
+ }
52
+ if (!entries.some((entry) => entry.name === store)) context.report({
53
+ node: program,
54
+ messageId: "missingStore",
55
+ data: {
56
+ file,
57
+ store
58
+ }
59
+ });
60
+ } };
61
+ }
62
+ });
63
+ // plugin.ts
64
+ var plugin_default = definePlugin({
65
+ meta: { name: "store-layout" },
66
+ rules: { "store-layout": storeLayout }
67
+ });
68
+ export { plugin_default as default };
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@elnop/eslint-plugin-store-layout",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Lint rule for oxlint and ESLint: xStore.ts only exports xStore and xActions.",
5
+ "keywords": [
6
+ "oxlint",
7
+ "oxlint-plugin",
8
+ "eslint",
9
+ "eslintplugin",
10
+ "eslint-plugin",
11
+ "zustand",
12
+ "store"
13
+ ],
14
+ "homepage": "https://github.com/Elnop/eslint-plugins/tree/main/packages/plugins/eslint-plugin-store-layout#readme",
15
+ "bugs": "https://github.com/Elnop/eslint-plugins/issues",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Elnop/eslint-plugins.git",
19
+ "directory": "packages/plugins/eslint-plugin-store-layout"
20
+ },
21
+ "license": "MIT",
22
+ "author": "elnop",
23
+ "type": "module",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "exports": "./dist/plugin.js",
28
+ "scripts": {
29
+ "build": "tsdown",
30
+ "test": "node --test '**/*.test.ts'"
31
+ },
32
+ "dependencies": {
33
+ "@oxlint/plugins": "^1.91.0"
34
+ },
35
+ "peerDependencies": {
36
+ "oxlint": "^1.91.0"
37
+ },
38
+ "devDependencies": {
39
+ "@elnop/lint-utils": "^0.1.0",
40
+ "oxlint": "^1.91.0"
41
+ }
42
+ }