@elnop/eslint-plugin-file-named-after-export 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,35 @@
1
- # Temporary Holding Version
1
+ # @elnop/eslint-plugin-file-named-after-export
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 file with a single named export is named after that export. `formatPrice.ts` exporting only `price` is reported: rename the file to `price.ts`, or the export to `formatPrice`.
4
+
5
+ Files whose name ends with one of `exemptSuffixes` are skipped. The default is `['Types', 'Config', 'Content']`, for files that group several types or constants.
6
+
7
+ Works with oxlint and ESLint.
8
+
9
+ ```sh
10
+ npm install --save-dev @elnop/eslint-plugin-file-named-after-export
11
+ ```
12
+
13
+ ## oxlint
14
+
15
+ ```json
16
+ {
17
+ "jsPlugins": ["@elnop/eslint-plugin-file-named-after-export"],
18
+ "rules": {
19
+ "file-named-after-export/file-named-after-export": ["error", { "exemptSuffixes": ["Types", "Config"] }]
20
+ }
21
+ }
22
+ ```
23
+
24
+ ## ESLint
25
+
26
+ ```js
27
+ import fileNamedAfterExport from '@elnop/eslint-plugin-file-named-after-export';
28
+
29
+ export default [
30
+ {
31
+ plugins: { 'file-named-after-export': fileNamedAfterExport },
32
+ rules: { 'file-named-after-export/file-named-after-export': 'error' },
33
+ },
34
+ ];
35
+ ```
@@ -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
+ // ../../utils/lint-utils/dist/baseName.js
3
+ function baseName(filename) {
4
+ return (filename.split("/").pop() ?? "").replace(/\.[^.]+$/, "");
5
+ }
6
+ // ../../utils/lint-utils/dist/exportsOf.js
7
+ function declaredNames(declaration) {
8
+ if (declaration.type === "VariableDeclaration") return declaration.declarations.flatMap((declarator) => declarator.id.type === "Identifier" ? [declarator.id.name] : []);
9
+ return "id" in declaration && declaration.id && "name" in declaration.id ? [declaration.id.name] : [];
10
+ }
11
+ function exportsOf(program) {
12
+ return program.body.flatMap((node) => {
13
+ if (node.type !== "ExportNamedDeclaration") return [];
14
+ return (node.declaration ? declaredNames(node.declaration) : node.specifiers.map((specifier) => specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value)).map((name) => ({
15
+ name,
16
+ node
17
+ }));
18
+ });
19
+ }
20
+ // fileNamedAfterExport.ts
21
+ function stringsAt(options, key) {
22
+ if (typeof options !== "object" || options === null || !(key in options)) return [];
23
+ const value = Reflect.get(options, key);
24
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
25
+ }
26
+ const fileNamedAfterExport = defineRule({
27
+ meta: {
28
+ type: "suggestion",
29
+ docs: { description: "Name a file with a single export after that export." },
30
+ messages: { renameFile: "A file with a single export is named after it: rename {{file}} to {{name}}." },
31
+ defaultOptions: [{ exemptSuffixes: [
32
+ "Types",
33
+ "Config",
34
+ "Content"
35
+ ] }],
36
+ schema: [{
37
+ type: "object",
38
+ properties: { exemptSuffixes: {
39
+ type: "array",
40
+ items: { type: "string" }
41
+ } },
42
+ additionalProperties: false
43
+ }]
44
+ },
45
+ create(context) {
46
+ return { Program(program) {
47
+ const exemptSuffixes = stringsAt(context.options[0], "exemptSuffixes");
48
+ const file = baseName(context.filename);
49
+ const entries = exportsOf(program);
50
+ const [only] = entries;
51
+ if (entries.length !== 1 || !only || exemptSuffixes.some((suffix) => file.endsWith(suffix)) || only.name === file) return;
52
+ context.report({
53
+ node: only.node,
54
+ messageId: "renameFile",
55
+ data: {
56
+ file,
57
+ name: only.name
58
+ }
59
+ });
60
+ } };
61
+ }
62
+ });
63
+ // plugin.ts
64
+ var plugin_default = definePlugin({
65
+ meta: { name: "file-named-after-export" },
66
+ rules: { "file-named-after-export": fileNamedAfterExport }
67
+ });
68
+ export { plugin_default as default };
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@elnop/eslint-plugin-file-named-after-export",
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: a file with a single export is named after it.",
5
+ "keywords": [
6
+ "oxlint",
7
+ "oxlint-plugin",
8
+ "eslint",
9
+ "eslintplugin",
10
+ "eslint-plugin",
11
+ "filename"
12
+ ],
13
+ "homepage": "https://github.com/Elnop/eslint-plugins/tree/main/packages/plugins/eslint-plugin-file-named-after-export#readme",
14
+ "bugs": "https://github.com/Elnop/eslint-plugins/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Elnop/eslint-plugins.git",
18
+ "directory": "packages/plugins/eslint-plugin-file-named-after-export"
19
+ },
20
+ "license": "MIT",
21
+ "author": "elnop",
22
+ "type": "module",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "exports": "./dist/plugin.js",
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "test": "node --test '**/*.test.ts'"
30
+ },
31
+ "dependencies": {
32
+ "@oxlint/plugins": "^1.91.0"
33
+ },
34
+ "peerDependencies": {
35
+ "oxlint": "^1.91.0"
36
+ },
37
+ "devDependencies": {
38
+ "@elnop/lint-utils": "^0.1.0",
39
+ "oxlint": "^1.91.0"
40
+ }
41
+ }