@elnop/check-tree 0.0.0-stage → 0.1.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/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,30 @@
1
- # Temporary Holding Version
1
+ # @elnop/check-tree
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
+ Checks the folders of a source tree, which a linter does not see:
4
+
5
+ - no empty folder
6
+ - a category folder (`components`, `hooks`, `stores`…) does not hold a single child: move the child up and delete the folder
7
+ - a folder with more than one stylesheet puts them in a `styles/` folder, and a folder that has a `styles/` folder keeps no stylesheet next to it
8
+
9
+ Test files (`*.test.ts`, `*.test.tsx`) are not counted.
10
+
11
+ ```sh
12
+ npm install --save-dev @elnop/check-tree
13
+ npx check-tree src
14
+ ```
15
+
16
+ It prints one line per problem and exits with code 1 if it found any.
17
+
18
+ The default category folders are `components`, `orchestrators`, `presenters`, `hooks`, `styles`, `types`, `configs`, `stores` and `lib`. Pass your own list with `--categories`:
19
+
20
+ ```sh
21
+ npx check-tree src --categories components,hooks,utils
22
+ ```
23
+
24
+ The check is also exported as a function:
25
+
26
+ ```ts
27
+ import { treeViolations } from '@elnop/check-tree/treeViolations';
28
+
29
+ const violations = treeViolations('src');
30
+ ```
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from 'node:path';
3
+ import { parseArgs } from 'node:util';
4
+ import { treeViolations } from './treeViolations.js';
5
+ const { values, positionals } = parseArgs({ allowPositionals: true, options: { categories: { type: 'string' } } });
6
+ const categories = values.categories?.split(',').map((category) => category.trim());
7
+ const violations = treeViolations(resolve(positionals[0] ?? 'src'), categories);
8
+ for (const violation of violations)
9
+ console.error(violation);
10
+ process.exitCode = violations.length === 0 ? 0 : 1;
@@ -0,0 +1 @@
1
+ export declare function treeViolations(root: string, categoryFolders?: readonly string[]): string[];
@@ -0,0 +1,30 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { basename, join, relative } from 'node:path';
3
+ const DEFAULT_CATEGORY_FOLDERS = ['components', 'orchestrators', 'presenters', 'hooks', 'styles', 'types', 'configs', 'stores', 'lib'];
4
+ const TEST_FILE = /\.test\.tsx?$/;
5
+ function folderViolations(folder, name, categoryFolders) {
6
+ const entries = readdirSync(folder, { withFileTypes: true });
7
+ const children = entries.filter((entry) => !TEST_FILE.test(entry.name));
8
+ const stylesheets = entries.filter((entry) => entry.isFile() && entry.name.endsWith('.css'));
9
+ const hasStylesFolder = entries.some((entry) => entry.isDirectory() && entry.name === 'styles');
10
+ const violations = [];
11
+ if (children.length === 0)
12
+ violations.push(`${name} is empty: delete it`);
13
+ if (children.length === 1 && categoryFolders.has(basename(folder)))
14
+ violations.push(`${name} holds a single child: move it up one level and delete the folder`);
15
+ if (stylesheets.length > 0 && hasStylesFolder)
16
+ violations.push(`${name} has a styles/ folder: move ${stylesheets.map((entry) => entry.name).join(', ')} into it`);
17
+ if (stylesheets.length > 1 && basename(folder) !== 'styles')
18
+ violations.push(`${name} holds ${stylesheets.length} stylesheets: move them into a styles/ folder`);
19
+ return violations;
20
+ }
21
+ export function treeViolations(root, categoryFolders = DEFAULT_CATEGORY_FOLDERS) {
22
+ const categories = new Set(categoryFolders);
23
+ const walk = (folder) => [
24
+ ...folderViolations(folder, relative(join(root, '..'), folder), categories),
25
+ ...readdirSync(folder, { withFileTypes: true })
26
+ .filter((entry) => entry.isDirectory())
27
+ .flatMap((entry) => walk(join(folder, entry.name))),
28
+ ];
29
+ return walk(root);
30
+ }
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@elnop/check-tree",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Checks a source tree: no empty folder, no category folder holding a single child, stylesheets grouped in styles/.",
5
+ "keywords": [
6
+ "lint",
7
+ "folder-structure",
8
+ "project-structure",
9
+ "cli"
10
+ ],
11
+ "homepage": "https://github.com/Elnop/eslint-plugins/tree/main/packages/tools/check-tree#readme",
12
+ "bugs": "https://github.com/Elnop/eslint-plugins/issues",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Elnop/eslint-plugins.git",
16
+ "directory": "packages/tools/check-tree"
17
+ },
18
+ "license": "MIT",
19
+ "author": "elnop",
20
+ "type": "module",
21
+ "files": [
22
+ "dist",
23
+ "!dist/tsconfig.tsbuildinfo"
24
+ ],
25
+ "bin": {
26
+ "check-tree": "./dist/checkTree.js"
27
+ },
28
+ "exports": {
29
+ "./treeViolations": "./dist/treeViolations.js"
30
+ },
31
+ "scripts": {
32
+ "test": "node --test '**/*.test.ts'"
33
+ }
34
+ }