@matthewbub/toolshed 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 Matthew Bub
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 ADDED
@@ -0,0 +1,4 @@
1
+ # toolshed
2
+
3
+ > [!NOTE]
4
+ > This repository is published for reference and reuse. I am not accepting pull requests or feature requests at this time.
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@matthewbub/toolshed",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "a digital toolshed — shared ESLint presets and Prettier config",
6
+ "keywords": [
7
+ "eslint",
8
+ "eslint-config",
9
+ "flat-config",
10
+ "prettier",
11
+ "prettier-config",
12
+ "config"
13
+ ],
14
+ "homepage": "https://github.com/matthewbub/toolshed#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/matthewbub/toolshed.git"
18
+ },
19
+ "author": "matthewbub",
20
+ "license": "MIT",
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "exports": {
25
+ "./eslint-config": "./packages/eslint-config/index.mjs",
26
+ "./eslint-config/base": "./packages/eslint-config/base.mjs",
27
+ "./eslint-config/react": "./packages/eslint-config/react.mjs",
28
+ "./eslint-config/vite": "./packages/eslint-config/vite.mjs",
29
+ "./eslint-config/next": "./packages/eslint-config/next.mjs",
30
+ "./eslint-config/hono": "./packages/eslint-config/hono.mjs",
31
+ "./eslint-config/storybook": "./packages/eslint-config/storybook.mjs",
32
+ "./eslint-config/package-json": "./packages/eslint-config/package-json.mjs",
33
+ "./eslint-config/plugin": "./packages/eslint-config/plugin/index.mjs",
34
+ "./prettier-config": "./packages/prettier-config/index.mjs"
35
+ },
36
+ "files": [
37
+ "packages/eslint-config/*.mjs",
38
+ "packages/eslint-config/plugin/**/*.mjs",
39
+ "packages/eslint-config/README.md",
40
+ "packages/prettier-config/index.mjs",
41
+ "packages/prettier-config/README.md"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "prettier": "@matthewbub/toolshed/prettier-config",
47
+ "dependencies": {
48
+ "@eslint/js": "9.39.4",
49
+ "@eslint/json": "2.0.0",
50
+ "eslint-config-next": "16.2.7",
51
+ "eslint-config-prettier": "10.1.8",
52
+ "eslint-plugin-react-hooks": "7.1.1",
53
+ "eslint-plugin-react-refresh": "0.5.2",
54
+ "eslint-plugin-storybook": "10.4.4",
55
+ "globals": "17.6.0",
56
+ "typescript-eslint": "8.62.0",
57
+ "yaml-eslint-parser": "2.0.0"
58
+ },
59
+ "peerDependencies": {
60
+ "eslint": "9.39.4",
61
+ "prettier": "3.8.3"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "eslint": {
65
+ "optional": true
66
+ },
67
+ "prettier": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "devDependencies": {
72
+ "@changesets/cli": "2.31.0",
73
+ "eslint": "9.39.4",
74
+ "prettier": "3.8.3",
75
+ "turbo": "2.9.18"
76
+ },
77
+ "scripts": {
78
+ "lint": "eslint .",
79
+ "lint:fix": "eslint . --fix",
80
+ "format": "turbo run prettier",
81
+ "format:check": "prettier --check . --ignore-path .prettierignore",
82
+ "check": "turbo run lint && pnpm format:check",
83
+ "release": "pnpm publish --access public --no-git-checks"
84
+ }
85
+ }
@@ -0,0 +1,52 @@
1
+ # @matthewbub/toolshed/eslint-config
2
+
3
+ Shared [flat-config](https://eslint.org/docs/latest/use/configure/configuration-files) ESLint presets, plus exact-version governance for `package.json` and the pnpm `catalog:`. Shipped as part of [`@matthewbub/toolshed`](../../README.md).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install --save-dev @matthewbub/toolshed eslint
9
+ ```
10
+
11
+ ## Presets
12
+
13
+ Each preset is a factory you spread into your flat config. Pass `tsconfigRootDir: import.meta.dirname` when you want type-aware parsing rooted at the config file.
14
+
15
+ | Export | Use for |
16
+ | ------------------------------------------------------------ | ------------------------------------------------------------------ |
17
+ | `base` (`/eslint-config/base`) | Any TS project — JS + typescript-eslint recommended + house style. |
18
+ | `react` (`/eslint-config/react`) | React libraries — `base` + react-hooks. |
19
+ | `vite` (`/eslint-config/vite`) | Vite + React apps — `react` + react-refresh (Fast Refresh). |
20
+ | `next` (`/eslint-config/next`) | Next.js apps — core-web-vitals + typescript, Prettier-deferred. |
21
+ | `hono` (`/eslint-config/hono`) | Hono / Cloudflare Worker source — `base` + worker globals. |
22
+ | `storybook` (`/eslint-config/storybook`) | `vite` + eslint-plugin-storybook. |
23
+ | `packageJson`, `pnpmCatalog` (`/eslint-config/package-json`) | Exact-version governance (see below). |
24
+
25
+ The presets are also re-exported as named members of `@matthewbub/toolshed/eslint-config` (except `next`, which loads the `next` package eagerly — import it from `@matthewbub/toolshed/eslint-config/next`).
26
+
27
+ ### Example: a Vite app
28
+
29
+ ```js
30
+ // eslint.config.mjs
31
+ import {vite} from "@matthewbub/toolshed/eslint-config/vite";
32
+
33
+ export default vite({tsconfigRootDir: import.meta.dirname});
34
+ ```
35
+
36
+ ### Example: repo-root version governance
37
+
38
+ Enforces exact versions (no `^`/`~`/ranges) across every `package.json` and the `pnpm-workspace.yaml` catalog(s):
39
+
40
+ ```js
41
+ // eslint.config.mjs
42
+ import {packageJson, pnpmCatalog} from "@matthewbub/toolshed/eslint-config/package-json";
43
+
44
+ export default [...packageJson(), ...pnpmCatalog()];
45
+ ```
46
+
47
+ ## Custom rules
48
+
49
+ The bundled `local/` plugin (also exported as `localPlugin`) ships two rules, both wired up by the governance presets above:
50
+
51
+ - `local/exact-dependency-versions` — every specifier in `package.json` dependency blocks must be an exact pin (or a `workspace:`/`catalog:`/`link:`/`file:` protocol).
52
+ - `local/exact-catalog-versions` — every entry under the pnpm `catalog:` / `catalogs:` maps must be an exact version.
@@ -0,0 +1,45 @@
1
+ import js from "@eslint/js";
2
+ import tseslint from "typescript-eslint";
3
+ import {defineConfig, globalIgnores} from "eslint/config";
4
+
5
+ const DEFAULT_IGNORES = ["dist/**", "out/**", "node_modules/**", "storybook-static/**"];
6
+
7
+ export const globalRules = {
8
+ "curly": ["error", "all"],
9
+ "no-trailing-spaces": "error",
10
+ "object-curly-newline": [
11
+ "error",
12
+ {
13
+ ObjectExpression: {
14
+ multiline: true,
15
+ minProperties: 1,
16
+ },
17
+ },
18
+ ],
19
+ "object-property-newline": [
20
+ "error",
21
+ {
22
+ allowAllPropertiesOnSameLine: false,
23
+ },
24
+ ],
25
+ };
26
+
27
+ export function base({ignores = [], files = ["**/*.{ts,tsx}"], tsconfigRootDir} = {}) {
28
+ return defineConfig([
29
+ globalIgnores([...DEFAULT_IGNORES, ...ignores]),
30
+ {
31
+ files,
32
+ extends: [js.configs.recommended, tseslint.configs.recommended],
33
+ languageOptions: tsconfigRootDir
34
+ ? {
35
+ parserOptions: {
36
+ tsconfigRootDir,
37
+ },
38
+ }
39
+ : {},
40
+ rules: globalRules,
41
+ },
42
+ ]);
43
+ }
44
+
45
+ export default base;
@@ -0,0 +1,24 @@
1
+ import globals from "globals";
2
+ import {defineConfig} from "eslint/config";
3
+ import {base} from "./base.mjs";
4
+
5
+ export function hono({ignores, files = ["**/*.ts"], tsconfigRootDir} = {}) {
6
+ return defineConfig([
7
+ ...base({
8
+ ignores,
9
+ files,
10
+ tsconfigRootDir,
11
+ }),
12
+ {
13
+ files,
14
+ languageOptions: {
15
+ globals: {
16
+ ...globals.serviceworker,
17
+ ...globals.node,
18
+ },
19
+ },
20
+ },
21
+ ]);
22
+ }
23
+
24
+ export default hono;
@@ -0,0 +1,10 @@
1
+ export {base, globalRules} from "./base.mjs";
2
+ export {react} from "./react.mjs";
3
+ export {vite} from "./vite.mjs";
4
+ export {storybook} from "./storybook.mjs";
5
+ export {hono} from "./hono.mjs";
6
+ export {packageJson, pnpmCatalog} from "./package-json.mjs";
7
+ export {default as localPlugin} from "./plugin/index.mjs";
8
+
9
+ // `next` is not re-exported: eslint-config-next loads the `next` package eagerly,
10
+ // which breaks non-Next consumers. Import from "@matthewbub/toolshed/eslint-config/next".
@@ -0,0 +1,50 @@
1
+ import nextVitals from "eslint-config-next/core-web-vitals";
2
+ import nextTs from "eslint-config-next/typescript";
3
+ import prettier from "eslint-config-prettier/flat";
4
+ import storybookPlugin from "eslint-plugin-storybook";
5
+ import {defineConfig, globalIgnores} from "eslint/config";
6
+ import {globalRules} from "./base.mjs";
7
+
8
+ // Default ignores for a Next.js app (mirrors eslint-config-next's own defaults,
9
+ // which `globalIgnores` here re-asserts so they survive our extra entries).
10
+ const NEXT_IGNORES = [".next/**", "out/**", "build/**", "next-env.d.ts", "external/**"];
11
+
12
+ /**
13
+ * Next.js preset: core-web-vitals + typescript configs, with eslint-config-prettier
14
+ * to defer formatting to Prettier. `globalRules` is re-asserted AFTER prettier,
15
+ * since eslint-config-prettier disables those rules and they are global — enforced
16
+ * here as everywhere else.
17
+ *
18
+ * @param {object} [options]
19
+ * @param {boolean} [options.storybook] append eslint-plugin-storybook flat/recommended
20
+ * @param {string[]} [options.ignores] extra ignore globs
21
+ * @param {string} [options.tsconfigRootDir] usually `import.meta.dirname`
22
+ */
23
+ export function next({storybook = false, ignores = [], tsconfigRootDir} = {}) {
24
+ return defineConfig([
25
+ ...nextVitals,
26
+ ...nextTs,
27
+ {
28
+ ...(tsconfigRootDir
29
+ ? {
30
+ languageOptions: {
31
+ parserOptions: {
32
+ tsconfigRootDir,
33
+ },
34
+ },
35
+ }
36
+ : {}),
37
+ rules: {
38
+ "react/no-unescaped-entities": "off",
39
+ },
40
+ },
41
+ prettier,
42
+ {
43
+ rules: globalRules,
44
+ },
45
+ globalIgnores([...NEXT_IGNORES, ...(storybook ? ["storybook-static/**"] : []), ...ignores]),
46
+ ...(storybook ? storybookPlugin.configs["flat/recommended"] : []),
47
+ ]);
48
+ }
49
+
50
+ export default next;
@@ -0,0 +1,40 @@
1
+ import json from "@eslint/json";
2
+ import * as yamlParser from "yaml-eslint-parser";
3
+ import {defineConfig} from "eslint/config";
4
+ import localPlugin from "./plugin/index.mjs";
5
+
6
+ export function packageJson({files = ["**/package.json"], ignores = []} = {}) {
7
+ return defineConfig([
8
+ {
9
+ files,
10
+ ignores: ["**/node_modules/**", ...ignores],
11
+ language: "json/json",
12
+ plugins: {
13
+ json,
14
+ local: localPlugin,
15
+ },
16
+ rules: {
17
+ "local/exact-dependency-versions": "error",
18
+ },
19
+ },
20
+ ]);
21
+ }
22
+
23
+ export function pnpmCatalog({files = ["pnpm-workspace.yaml"]} = {}) {
24
+ return defineConfig([
25
+ {
26
+ files,
27
+ languageOptions: {
28
+ parser: yamlParser,
29
+ },
30
+ plugins: {
31
+ local: localPlugin,
32
+ },
33
+ rules: {
34
+ "local/exact-catalog-versions": "error",
35
+ },
36
+ },
37
+ ]);
38
+ }
39
+
40
+ export default packageJson;
@@ -0,0 +1,15 @@
1
+ export const ALLOWED_PROTOCOLS = ["workspace:", "catalog:", "link:", "file:"];
2
+
3
+ // Exact semver: 1.2.3, optionally with -prerelease and/or +build metadata.
4
+ export const EXACT_SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;
5
+
6
+ export function isExact(spec) {
7
+ if (typeof spec !== "string") {
8
+ return false;
9
+ }
10
+ const trimmed = spec.trim();
11
+ if (ALLOWED_PROTOCOLS.some((protocol) => trimmed.startsWith(protocol))) {
12
+ return true;
13
+ }
14
+ return EXACT_SEMVER.test(trimmed);
15
+ }
@@ -0,0 +1,12 @@
1
+ import exactDependencyVersions from "./rules/exact-dependency-versions.mjs";
2
+ import exactCatalogVersions from "./rules/exact-catalog-versions.mjs";
3
+
4
+ export default {
5
+ meta: {
6
+ name: "@matthewbub/eslint-config/plugin",
7
+ },
8
+ rules: {
9
+ "exact-dependency-versions": exactDependencyVersions,
10
+ "exact-catalog-versions": exactCatalogVersions,
11
+ },
12
+ };
@@ -0,0 +1,66 @@
1
+ import {isExact} from "../exact-version.mjs";
2
+
3
+ function keyName(pair) {
4
+ return pair.key && "value" in pair.key ? String(pair.key.value) : "";
5
+ }
6
+
7
+ export default {
8
+ meta: {
9
+ type: "problem",
10
+ docs: {
11
+ description: "Require exact versions in the pnpm-workspace catalog(s) (no ^, ~, ranges).",
12
+ },
13
+ messages: {
14
+ notExact:
15
+ '"{{name}}": "{{spec}}" in {{catalog}} must be an exact version (e.g. 1.2.3) — ' +
16
+ "no ranges (^, ~, >=, *, ||).",
17
+ },
18
+ schema: [],
19
+ },
20
+ create(context) {
21
+ function checkCatalogMapping(mapping, catalogLabel) {
22
+ if (!mapping || mapping.type !== "YAMLMapping") {
23
+ return;
24
+ }
25
+ for (const pair of mapping.pairs) {
26
+ const value = pair.value;
27
+ if (!value || value.type !== "YAMLScalar") {
28
+ continue;
29
+ }
30
+ const spec = String(value.value);
31
+ if (isExact(spec)) {
32
+ continue;
33
+ }
34
+ context.report({
35
+ loc: value.loc,
36
+ messageId: "notExact",
37
+ data: {
38
+ name: keyName(pair),
39
+ spec,
40
+ catalog: catalogLabel,
41
+ },
42
+ });
43
+ }
44
+ }
45
+
46
+ return {
47
+ YAMLDocument(node) {
48
+ const root = node.content;
49
+ if (!root || root.type !== "YAMLMapping") {
50
+ return;
51
+ }
52
+ for (const pair of root.pairs) {
53
+ const key = keyName(pair);
54
+ // Only `catalog`/`catalogs`; `overrides:` keys are range selectors, not pins.
55
+ if (key === "catalog") {
56
+ checkCatalogMapping(pair.value, "catalog");
57
+ } else if (key === "catalogs" && pair.value?.type === "YAMLMapping") {
58
+ for (const named of pair.value.pairs) {
59
+ checkCatalogMapping(named.value, `catalogs.${keyName(named)}`);
60
+ }
61
+ }
62
+ }
63
+ },
64
+ };
65
+ },
66
+ };
@@ -0,0 +1,53 @@
1
+ import {isExact} from "../exact-version.mjs";
2
+
3
+ const DEP_SECTIONS = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]);
4
+
5
+ export default {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Require exact dependency versions in package.json (no ^, ~, >=, *, or other ranges).",
10
+ },
11
+ messages: {
12
+ notExact:
13
+ '"{{name}}": "{{spec}}" in {{section}} must be an exact version (e.g. 1.2.3) — ' +
14
+ "no ranges (^, ~, >=, *, ||). Pin the version, or use workspace:/catalog: for internal refs.",
15
+ },
16
+ schema: [],
17
+ },
18
+ create(context) {
19
+ return {
20
+ Document(node) {
21
+ const root = node.body;
22
+ if (!root || root.type !== "Object") {
23
+ return;
24
+ }
25
+ for (const section of root.members) {
26
+ if (!DEP_SECTIONS.has(section.name?.value)) {
27
+ continue;
28
+ }
29
+ if (section.value?.type !== "Object") {
30
+ continue;
31
+ }
32
+ for (const dependency of section.value.members) {
33
+ if (dependency.value?.type !== "String") {
34
+ continue;
35
+ }
36
+ if (isExact(dependency.value.value)) {
37
+ continue;
38
+ }
39
+ context.report({
40
+ loc: dependency.value.loc,
41
+ messageId: "notExact",
42
+ data: {
43
+ name: dependency.name?.value ?? "",
44
+ spec: dependency.value.value,
45
+ section: section.name.value,
46
+ },
47
+ });
48
+ }
49
+ }
50
+ },
51
+ };
52
+ },
53
+ };
@@ -0,0 +1,23 @@
1
+ import globals from "globals";
2
+ import reactHooks from "eslint-plugin-react-hooks";
3
+ import {defineConfig} from "eslint/config";
4
+ import {base} from "./base.mjs";
5
+
6
+ export function react({ignores, files = ["**/*.{ts,tsx}"], tsconfigRootDir} = {}) {
7
+ return defineConfig([
8
+ ...base({
9
+ ignores,
10
+ files,
11
+ tsconfigRootDir,
12
+ }),
13
+ {
14
+ files,
15
+ extends: [reactHooks.configs.flat["recommended-latest"]],
16
+ languageOptions: {
17
+ globals: globals.browser,
18
+ },
19
+ },
20
+ ]);
21
+ }
22
+
23
+ export default react;
@@ -0,0 +1,9 @@
1
+ import storybookPlugin from "eslint-plugin-storybook";
2
+ import {defineConfig} from "eslint/config";
3
+ import {vite} from "./vite.mjs";
4
+
5
+ export function storybook(options = {}) {
6
+ return defineConfig([...vite(options), ...storybookPlugin.configs["flat/recommended"]]);
7
+ }
8
+
9
+ export default storybook;
@@ -0,0 +1,22 @@
1
+ import reactRefresh from "eslint-plugin-react-refresh";
2
+ import {defineConfig} from "eslint/config";
3
+ import {react} from "./react.mjs";
4
+
5
+ export function vite({ignores, files = ["**/*.{ts,tsx}"], tsconfigRootDir} = {}) {
6
+ return defineConfig([
7
+ ...react({
8
+ ignores,
9
+ files,
10
+ tsconfigRootDir,
11
+ }),
12
+ {
13
+ files,
14
+ extends: [reactRefresh.configs.vite],
15
+ rules: {
16
+ "react-refresh/only-export-components": "warn",
17
+ },
18
+ },
19
+ ]);
20
+ }
21
+
22
+ export default vite;
@@ -0,0 +1,40 @@
1
+ # @matthewbub/toolshed/prettier-config
2
+
3
+ Shared [Prettier](https://prettier.io) configuration. Shipped as part of [`@matthewbub/toolshed`](../../README.md).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install --save-dev @matthewbub/toolshed prettier
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Reference it from the `prettier` field of your `package.json`:
14
+
15
+ ```json
16
+ {
17
+ "prettier": "@matthewbub/toolshed/prettier-config"
18
+ }
19
+ ```
20
+
21
+ To extend it, create a `prettier.config.mjs` instead:
22
+
23
+ ```js
24
+ import base from "@matthewbub/toolshed/prettier-config";
25
+
26
+ /** @type {import("prettier").Config} */
27
+ export default {
28
+ ...base,
29
+ // your overrides
30
+ };
31
+ ```
32
+
33
+ ## What it sets
34
+
35
+ | Option | Value |
36
+ | ---------------- | -------------- |
37
+ | `quoteProps` | `"consistent"` |
38
+ | `bracketSpacing` | `false` |
39
+ | `objectWrap` | `"preserve"` |
40
+ | `printWidth` | `120` |
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Shared Prettier configuration for the toolshed monorepo.
3
+ *
4
+ * Single source of truth — every consumer references this via the `prettier`
5
+ * field in its package.json. To change formatting repo-wide, edit it here.
6
+ *
7
+ * @type {import("prettier").Config}
8
+ */
9
+ export default {
10
+ quoteProps: "consistent",
11
+ bracketSpacing: false,
12
+ objectWrap: "preserve",
13
+ printWidth: 120,
14
+ };