@elnop/lint-utils 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,14 @@
1
- # Temporary Holding Version
1
+ # @elnop/lint-utils
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
+ Helpers shared by the `@elnop` lint plugins and configs. You probably want one of those instead:
4
+
5
+ - [@elnop/eslint-plugin-file-named-after-export](https://www.npmjs.com/package/@elnop/eslint-plugin-file-named-after-export)
6
+ - [@elnop/eslint-plugin-store-layout](https://www.npmjs.com/package/@elnop/eslint-plugin-store-layout)
7
+ - [@elnop/oxlint-config-typescript](https://www.npmjs.com/package/@elnop/oxlint-config-typescript)
8
+
9
+ It exports:
10
+
11
+ - `baseName(filename)`: the file name without folder and extension
12
+ - `exportsOf(program)`: the named exports of a module, with their declaration node
13
+ - `ruleTester`: an oxlint `RuleTester` wired to `node:test`
14
+ - `lintFixture(directory)`: runs oxlint in a folder with its own `oxlint.config.ts` and returns one `file:line rule` entry per diagnostic
@@ -0,0 +1,5 @@
1
+ import type { ESTree } from '@oxlint/plugins';
2
+ export type ExportEntry = {
3
+ name: string;
4
+ node: ESTree.ExportNamedDeclaration;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export type OxlintDiagnostic = {
2
+ code: string;
3
+ filename: string;
4
+ labels: {
5
+ span: {
6
+ line: number;
7
+ };
8
+ }[];
9
+ };
10
+ export type OxlintReport = {
11
+ diagnostics: OxlintDiagnostic[];
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function baseName(filename: string): string;
@@ -0,0 +1,3 @@
1
+ export function baseName(filename) {
2
+ return (filename.split('/').pop() ?? '').replace(/\.[^.]+$/, '');
3
+ }
@@ -0,0 +1,3 @@
1
+ import type { ESTree } from '@oxlint/plugins';
2
+ import type { ExportEntry } from './ExportTypes.ts';
3
+ export declare function exportsOf(program: ESTree.Program): ExportEntry[];
@@ -0,0 +1,15 @@
1
+ function declaredNames(declaration) {
2
+ if (declaration.type === 'VariableDeclaration')
3
+ return declaration.declarations.flatMap((declarator) => (declarator.id.type === 'Identifier' ? [declarator.id.name] : []));
4
+ return 'id' in declaration && declaration.id && 'name' in declaration.id ? [declaration.id.name] : [];
5
+ }
6
+ export function exportsOf(program) {
7
+ return program.body.flatMap((node) => {
8
+ if (node.type !== 'ExportNamedDeclaration')
9
+ return [];
10
+ const names = node.declaration
11
+ ? declaredNames(node.declaration)
12
+ : node.specifiers.map((specifier) => (specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value));
13
+ return names.map((name) => ({ name, node }));
14
+ });
15
+ }
@@ -0,0 +1 @@
1
+ export declare function lintFixture(directory: string): string[];
@@ -0,0 +1,13 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { fileURLToPath } from 'node:url';
3
+ const OXLINT_BIN = fileURLToPath(new URL('bin/oxlint', import.meta.resolve('oxlint/package.json')));
4
+ export function lintFixture(directory) {
5
+ const run = spawnSync(process.execPath, [OXLINT_BIN, '-c', 'oxlint.config.ts', '--format', 'json', '.'], { cwd: directory, encoding: 'utf8' });
6
+ if (run.error)
7
+ throw run.error;
8
+ const report = JSON.parse(run.stdout);
9
+ return report.diagnostics
10
+ .map((diagnostic) => ({ file: diagnostic.filename, line: diagnostic.labels[0]?.span.line ?? 0, code: diagnostic.code }))
11
+ .toSorted((left, right) => left.file.localeCompare(right.file) || left.line - right.line || left.code.localeCompare(right.code))
12
+ .map(({ file, line, code }) => `${file}:${line} ${code}`);
13
+ }
@@ -0,0 +1,2 @@
1
+ import { RuleTester } from 'oxlint/plugins-dev';
2
+ export declare const ruleTester: RuleTester;
@@ -0,0 +1,9 @@
1
+ import { describe, it } from 'node:test';
2
+ import { RuleTester } from 'oxlint/plugins-dev';
3
+ RuleTester.describe = (text, fn) => {
4
+ void describe(text, fn);
5
+ };
6
+ RuleTester.it = (text, fn) => {
7
+ void it(text, fn);
8
+ };
9
+ export const ruleTester = new RuleTester();
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@elnop/lint-utils",
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": "Helpers shared by the @elnop lint plugins: export listing, file base name, oxlint rule and fixture testers.",
5
+ "keywords": [
6
+ "oxlint",
7
+ "eslint",
8
+ "lint"
9
+ ],
10
+ "homepage": "https://github.com/Elnop/eslint-plugins/tree/main/packages/utils/lint-utils#readme",
11
+ "bugs": "https://github.com/Elnop/eslint-plugins/issues",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Elnop/eslint-plugins.git",
15
+ "directory": "packages/utils/lint-utils"
16
+ },
17
+ "license": "MIT",
18
+ "author": "elnop",
19
+ "type": "module",
20
+ "files": [
21
+ "dist",
22
+ "!dist/tsconfig.tsbuildinfo"
23
+ ],
24
+ "exports": {
25
+ "./baseName": "./dist/baseName.js",
26
+ "./exportsOf": "./dist/exportsOf.js",
27
+ "./ExportTypes": "./dist/ExportTypes.js",
28
+ "./ruleTester": "./dist/ruleTester.js",
29
+ "./lintFixture": "./dist/lintFixture.js",
30
+ "./OxlintReportTypes": "./dist/OxlintReportTypes.js"
31
+ },
32
+ "dependencies": {
33
+ "@oxlint/plugins": "^1.91.0"
34
+ },
35
+ "peerDependencies": {
36
+ "oxlint": "^1.91.0"
37
+ },
38
+ "devDependencies": {
39
+ "oxlint": "^1.91.0"
40
+ }
41
+ }