@brutalway/lint-utils 0.0.0-stage → 0.2.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,33 @@
1
- # Temporary Holding Version
1
+ # @brutalway/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 `@brutalway` lint plugins and configs. Each package installs it as a dev dependency, and tsdown bundles the parts it imports into its `dist`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install --save-dev @brutalway/lint-utils
9
+ ```
10
+
11
+ You probably want one of the packages that use it:
12
+
13
+ - [@brutalway/eslint-plugin-file-named-after-export](https://www.npmjs.com/package/@brutalway/eslint-plugin-file-named-after-export)
14
+ - [@brutalway/eslint-plugin-store-layout](https://www.npmjs.com/package/@brutalway/eslint-plugin-store-layout)
15
+ - [@brutalway/oxlint-config-typescript](https://www.npmjs.com/package/@brutalway/oxlint-config-typescript)
16
+ - [@brutalway/oxlint-config-tailwind](https://www.npmjs.com/package/@brutalway/oxlint-config-tailwind)
17
+ - [@brutalway/stylelint-config](https://www.npmjs.com/package/@brutalway/stylelint-config)
18
+
19
+ ## Reference
20
+
21
+ ### Lint rules
22
+
23
+ - `baseName(filename)`: the file name without folder and extension
24
+ - `exportsOf(program)`: the named exports of a module, with their declaration node
25
+ - `ruleTester`: an oxlint `RuleTester` wired to `node:test`
26
+ - `lintFixture(directory)`: runs oxlint in a folder with its own `oxlint.config.ts` and returns one `file:line rule` entry per diagnostic
27
+
28
+ ### Colors
29
+
30
+ - `oklab(value)`: a hex, `rgb()`, `rgba()` or `oklch()` color in Oklab, or `undefined` for any other value
31
+ - `oklabDistance(left, right)`: the Euclidean distance between two Oklab colors
32
+ - `createColorTokenReader(parse)`: a function that reads a stylesheet, parses its tokens with `parse` and keeps them until the file's mtime changes. A missing file gives no tokens.
33
+ - the `Oklab` and `ColorToken` types
@@ -0,0 +1,6 @@
1
+ import { t as Oklab } from "./OklabTypes-BRQedkzT.js";
2
+ type ColorToken = {
3
+ name: string;
4
+ color: Oklab | undefined;
5
+ };
6
+ export { ColorToken as t };
@@ -0,0 +1,3 @@
1
+ import { t as ColorToken } from "./ColorTokenTypes-DyRcP7Sf.js";
2
+ import { t as Oklab } from "./OklabTypes-BRQedkzT.js";
3
+ export type { ColorToken, Oklab };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ESTree } from "@oxlint/plugins";
2
+ type ExportEntry = {
3
+ name: string;
4
+ node: ESTree.ExportNamedDeclaration;
5
+ };
6
+ export { ExportEntry as t };
@@ -0,0 +1,2 @@
1
+ import { t as ExportEntry } from "./ExportTypes-LP1UP4Gs.js";
2
+ export type { ExportEntry };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ type Oklab = {
2
+ l: number;
3
+ a: number;
4
+ b: number;
5
+ };
6
+ export { Oklab as t };
@@ -0,0 +1,13 @@
1
+ type OxlintDiagnostic = {
2
+ code: string;
3
+ filename: string;
4
+ labels: {
5
+ span: {
6
+ line: number;
7
+ };
8
+ }[];
9
+ };
10
+ type OxlintReport = {
11
+ diagnostics: OxlintDiagnostic[];
12
+ };
13
+ export type { OxlintDiagnostic, OxlintReport };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function baseName(filename: string): string;
@@ -0,0 +1,5 @@
1
+ // src/baseName.ts
2
+ function baseName(filename) {
3
+ return (filename.split("/").pop() ?? "").replace(/\.[^.]+$/u, "");
4
+ }
5
+ export { baseName };
@@ -0,0 +1,2 @@
1
+ import { t as ColorToken } from "./ColorTokenTypes-DyRcP7Sf.js";
2
+ export declare function createColorTokenReader(parse: (css: string) => ColorToken[]): (path: string) => ColorToken[];
@@ -0,0 +1,18 @@
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ // src/createColorTokenReader.ts
3
+ function createColorTokenReader(parse) {
4
+ const cache = /* @__PURE__ */ new Map();
5
+ return (path) => {
6
+ if (!existsSync(path)) return [];
7
+ const mtime = statSync(path).mtimeMs;
8
+ const cached = cache.get(path);
9
+ if (cached?.mtime === mtime) return cached.tokens;
10
+ const tokens = parse(readFileSync(path, "utf8"));
11
+ cache.set(path, {
12
+ mtime,
13
+ tokens
14
+ });
15
+ return tokens;
16
+ };
17
+ }
18
+ export { createColorTokenReader };
@@ -0,0 +1,3 @@
1
+ import { t as ExportEntry } from "./ExportTypes-LP1UP4Gs.js";
2
+ import { ESTree } from "@oxlint/plugins";
3
+ export declare function exportsOf(program: ESTree.Program): ExportEntry[];
@@ -0,0 +1,15 @@
1
+ // src/exportsOf.ts
2
+ function declaredNames(declaration) {
3
+ if (declaration.type === "VariableDeclaration") 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
+ function exportsOf(program) {
7
+ return program.body.flatMap((node) => {
8
+ if (node.type !== "ExportNamedDeclaration") return [];
9
+ return (node.declaration ? declaredNames(node.declaration) : node.specifiers.map((specifier) => specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value)).map((name) => ({
10
+ name,
11
+ node
12
+ }));
13
+ });
14
+ }
15
+ export { exportsOf };
@@ -0,0 +1 @@
1
+ export declare function lintFixture(directory: string): string[];
@@ -0,0 +1,24 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { fileURLToPath } from "node:url";
3
+ // src/lintFixture.ts
4
+ const OXLINT_BIN = fileURLToPath(new URL("bin/oxlint", import.meta.resolve("oxlint/package.json")));
5
+ function lintFixture(directory) {
6
+ const run = spawnSync(process.execPath, [
7
+ OXLINT_BIN,
8
+ "-c",
9
+ "oxlint.config.ts",
10
+ "--format",
11
+ "json",
12
+ "."
13
+ ], {
14
+ cwd: directory,
15
+ encoding: "utf8"
16
+ });
17
+ if (run.error) throw run.error;
18
+ return JSON.parse(run.stdout).diagnostics.map((diagnostic) => ({
19
+ file: diagnostic.filename,
20
+ line: diagnostic.labels[0]?.span.line ?? 0,
21
+ code: diagnostic.code
22
+ })).toSorted((left, right) => left.file.localeCompare(right.file) || left.line - right.line || left.code.localeCompare(right.code)).map(({ file, line, code }) => `${file}:${line} ${code}`);
23
+ }
24
+ export { lintFixture };
@@ -0,0 +1,3 @@
1
+ import { t as Oklab } from "./OklabTypes-BRQedkzT.js";
2
+ export declare function oklab(value: string): Oklab | undefined;
3
+ export declare function oklabDistance(left: Oklab, right: Oklab): number;
package/dist/oklab.js ADDED
@@ -0,0 +1,72 @@
1
+ // src/shared/lib/fromRgb.ts
2
+ function toLinear(channel) {
3
+ return channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4;
4
+ }
5
+ function cubeRootLms(red, green, blue) {
6
+ const [r, g, b] = [
7
+ toLinear(red),
8
+ toLinear(green),
9
+ toLinear(blue)
10
+ ];
11
+ return [
12
+ Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b),
13
+ Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b),
14
+ Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b)
15
+ ];
16
+ }
17
+ function fromRgb(red, green, blue) {
18
+ const [l, m, s] = cubeRootLms(red, green, blue);
19
+ return {
20
+ l: .2104542553 * l + .793617785 * m - .0040720468 * s,
21
+ a: 1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
22
+ b: .0259040371 * l + .7827717662 * m - .808675766 * s
23
+ };
24
+ }
25
+ // src/shared/lib/fromHex.ts
26
+ function fromHex(hex) {
27
+ const short = hex.length <= 5;
28
+ const [red, green, blue] = [
29
+ 1,
30
+ 2,
31
+ 3
32
+ ].map((index) => short ? hex.charAt(index).repeat(2) : hex.slice(index * 2 - 1, index * 2 + 1)).map((pair) => Number.parseInt(pair, 16) / 255);
33
+ if (red === void 0 || green === void 0 || blue === void 0 || [
34
+ red,
35
+ green,
36
+ blue
37
+ ].some(Number.isNaN)) return;
38
+ return fromRgb(red, green, blue);
39
+ }
40
+ // src/shared/lib/fromRgbChannels.ts
41
+ function scale(channel, raw) {
42
+ return raw?.endsWith("%") === true ? channel : channel / 255;
43
+ }
44
+ function fromRgbChannels(body, red, green, blue) {
45
+ const raws = body.split(/[\s,/]+/u).filter(Boolean);
46
+ return fromRgb(scale(red, raws[0]), scale(green, raws[1]), scale(blue, raws[2]));
47
+ }
48
+ // src/oklab.ts
49
+ function channels(body) {
50
+ return body.split(/[\s,/]+/u).filter(Boolean).map((part) => part.endsWith("%") ? Number.parseFloat(part) / 100 : Number.parseFloat(part));
51
+ }
52
+ function fromOklch(lightness, chroma, hueDegrees) {
53
+ const hue = hueDegrees * Math.PI / 180;
54
+ return {
55
+ l: lightness,
56
+ a: chroma * Math.cos(hue),
57
+ b: chroma * Math.sin(hue)
58
+ };
59
+ }
60
+ function oklab(value) {
61
+ const text = value.replaceAll("_", " ").trim().toLowerCase();
62
+ if (/^#[0-9a-f]{3,8}$/u.test(text)) return fromHex(text);
63
+ const call = /^(rgba?|oklch)\((.*)\)$/u.exec(text);
64
+ if (call === null) return void 0;
65
+ const [first, second, third] = channels(call[2] ?? "");
66
+ if (first === void 0 || second === void 0 || third === void 0) return void 0;
67
+ return call[1] === "oklch" ? fromOklch(first, second, third) : fromRgbChannels(call[2] ?? "", first, second, third);
68
+ }
69
+ function oklabDistance(left, right) {
70
+ return Math.hypot(left.l - right.l, left.a - right.a, left.b - right.b);
71
+ }
72
+ export { oklab, oklabDistance };
@@ -0,0 +1,2 @@
1
+ import { RuleTester } from "oxlint/plugins-dev";
2
+ export declare const ruleTester: RuleTester;
@@ -0,0 +1,11 @@
1
+ import { describe, it } from "node:test";
2
+ import { RuleTester } from "oxlint/plugins-dev";
3
+ // src/ruleTester.ts
4
+ RuleTester.describe = (text, fn) => {
5
+ describe(text, fn);
6
+ };
7
+ RuleTester.it = (text, fn) => {
8
+ it(text, fn);
9
+ };
10
+ const ruleTester = new RuleTester();
11
+ export { ruleTester };
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@brutalway/lint-utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Helpers shared by the @brutalway lint configs and plugins: export listing, file base name, oxlint rule and fixture testers, oklab colors and color token reading.",
5
+ "keywords": [
6
+ "oxlint",
7
+ "eslint",
8
+ "lint",
9
+ "oklab"
10
+ ],
11
+ "homepage": "https://github.com/Elnop/brutalway/tree/main/packages/utils/lint-utils#readme",
12
+ "bugs": "https://github.com/Elnop/brutalway/issues",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Elnop/brutalway.git",
16
+ "directory": "packages/utils/lint-utils"
17
+ },
18
+ "license": "MIT",
19
+ "author": "elnop",
20
+ "type": "module",
21
+ "engines": {
22
+ "node": ">=26"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "imports": {
28
+ "#src/*": "./src/*"
29
+ },
30
+ "exports": {
31
+ "./baseName": "./dist/baseName.js",
32
+ "./exportsOf": "./dist/exportsOf.js",
33
+ "./ExportTypes": "./dist/ExportTypes.js",
34
+ "./ruleTester": "./dist/ruleTester.js",
35
+ "./lintFixture": "./dist/lintFixture.js",
36
+ "./OxlintReportTypes": "./dist/OxlintReportTypes.js",
37
+ "./oklab": "./dist/oklab.js",
38
+ "./createColorTokenReader": "./dist/createColorTokenReader.js",
39
+ "./ColorTypes": "./dist/ColorTypes.js"
40
+ },
41
+ "scripts": {
42
+ "build": "tsdown",
43
+ "typecheck": "tsc -p .",
44
+ "lint": "oxlint --type-aware src oxlint.config.ts tsdown.config.ts",
45
+ "deps": "depcruise --output-type err-long src",
46
+ "tree": "check-tree src --root-entries",
47
+ "duplicates": "jscpd src",
48
+ "check": "npm run typecheck && npm run lint && npm run deps && npm run tree && npm run duplicates",
49
+ "test": "node --test 'src/**/*.test.ts'"
50
+ },
51
+ "dependencies": {
52
+ "@oxlint/plugins": "^1.91.0"
53
+ },
54
+ "peerDependencies": {
55
+ "oxlint": "^1.91.0"
56
+ },
57
+ "devDependencies": {
58
+ "@brutalway/check-tree": "0.5.1",
59
+ "@brutalway/dependency-cruiser-config": "0.5.0",
60
+ "@brutalway/oxlint-config-node": "0.2.1",
61
+ "@brutalway/oxlint-config-node-test": "0.1.0",
62
+ "@brutalway/tsconfig": "0.4.0",
63
+ "dependency-cruiser": "18.7.2",
64
+ "jscpd": "5.4.2",
65
+ "oxlint": "1.91.0",
66
+ "oxlint-tsgolint": "7.0.2005",
67
+ "tsdown": "0.23.5",
68
+ "typescript": "7.0.2"
69
+ }
70
+ }