larrylint 0.1.0 → 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/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
  [![NPM last update][npm-last-update-src]][npm-last-update-href]
6
6
  [![License][license-src]][license-href]
7
7
 
8
- Opinionated structure rules for [Laioutr](https://laioutr.com) apps: an ESLint preset for your editor and a CLI for CI.
8
+ Opinionated rules for [Laioutr](https://laioutr.com) apps: an ESLint preset for your editor and a CLI for CI.
9
9
 
10
- Laioutr apps are Nuxt modules with a lot of moving parts: sections and blocks, orchestr handlers, middleware, API clients, server routes. larrylint keeps them where they belong and stops the imports that make a codebase drift, like app code pulling in server code, handlers importing each other, or one business domain reaching into another.
10
+ Laioutr apps are Nuxt modules with a lot of moving parts: sections and blocks, orchestr handlers, middleware, API clients, server routes. larrylint keeps them where they belong and stops the imports that make a codebase drift, like app code pulling in server code, handlers importing each other, or one business domain reaching into another. It also catches the mistakes that only show up in Studio or in production, like schema fields that never reach the component, links Studio can't follow, or cookies the page cache hands to every visitor.
11
11
 
12
12
  ## Usage
13
13
 
@@ -25,17 +25,76 @@ npx larrylint init
25
25
 
26
26
  After that, `eslint .` and your editor report larrylint's rules next to your own.
27
27
 
28
+ `ui-kit-tags` and `token-namespaces` read the app's installed `@laioutr-core/ui-kit`, `@laioutr-core/ui` and `@laioutr-core/canonical-types`, so install the app's dependencies first. larrylint stops with an error when one of them is missing.
29
+
28
30
  ## Rules
29
31
 
30
- | Rule | What it checks |
31
- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
32
- | `larrylint/layers` | App code doesn't import server code and vice versa; shared code imports neither. Runtime code doesn't import build-time code. Nothing imports orchestr handlers. Handlers and server utils don't import from `server/client/`, and only handlers and media libraries import middleware. Utils are the bottom layer. Domains stay apart. |
33
- | `larrylint/orchestr-files` | Laioutr loads every file in `orchestr/` as a server plugin, so only handler files belong there, in a domain folder, exporting nothing but their handler. |
34
- | `larrylint/definitions` | `defineSection()` lives in `app/sections/Section*.vue`, `defineBlock()` in `app/blocks/Block*.vue`, with a `component` name that matches the file and no top-level schema fields named `style`, `class`, `key`, `ref`, `is`, `slot`, `refFor` or `refKey`, which Vue swallows before they reach the component. |
35
- | `larrylint/button-type` | No `type` on the ui-kit button: it always renders its `button-type` prop, so `type="submit"` silently renders a dead button. Autofixable. |
32
+ ### Structure
33
+
34
+ | Rule | Description |
35
+ | --- | --- |
36
+ | `larrylint/layers` | App, server and shared code stay apart, and runtime code doesn't import build-time code, or `node:` modules outside the server. Nothing imports orchestr handlers, only handlers and media libraries import middleware, and API clients stay out of handlers and server utils. Utils are the bottom layer, followed by composables, components and sections. Domains stay apart. |
37
+ | `larrylint/known-folders` | Runtime files live in the folders of the [layout](#layout), where the other rules know what to check. |
38
+ | `larrylint/heavy-imports` | Sections, blocks and plugins load the packages in `heavyPackages` with `import()`. Laioutr registers them globally, so a static import lands in the chunk every page loads. |
39
+ | `larrylint/config-keys` | Runtime config keys like `'@laioutr-app/shopware'` are the app itself or one of its dependencies, otherwise the config is missing at runtime. |
40
+ | `larrylint/public-config` | The module doesn't copy its options into `runtimeConfig.public`, which reaches the browser with every token among them. |
36
41
 
37
42
  Type imports are fine across most layers, since they don't end up in the bundle.
38
43
 
44
+ ### Orchestr
45
+
46
+ | Rule | Description |
47
+ | --- | --- |
48
+ | `larrylint/orchestr-files` | Laioutr loads every file in `orchestr/` as a server plugin, so only handler files belong there. |
49
+ | `larrylint/orchestr-cookies` | Handlers and middleware don't set cookies or redirect, since the page cache replays the response to every visitor. |
50
+ | `larrylint/handler-domains` | Handlers live in a domain folder, e.g. `orchestr/<domain>/`. |
51
+ | `larrylint/handler-exports` | Handler files export their handler as default and nothing else. |
52
+ | `larrylint/handler-context` | Handlers take config and clients from the middleware context and the request from their arguments, not from `useRuntimeConfig()` or `useEvent()`. |
53
+ | `larrylint/resolver-undefined` | Component resolvers resolve fields to empty values like `''`, not `undefined` or `null`, which Studio shows as "...". |
54
+ | `larrylint/resolver-passthrough` | Component resolvers use `passthrough.get()`: `require()` fails the whole resolver when another query didn't set the value. |
55
+ | `larrylint/action-errors` | Actions return client errors as a status in their output. A thrown 4xx arrives as a failed action, since the action transport drops status codes. |
56
+ | `larrylint/middleware-files` | `server/middleware/` only holds orchestr and Nitro middleware; helpers go to `server/utils/`. |
57
+ | `larrylint/initware-throws` | `extendRequest()` doesn't throw, directly or through a function it calls: it runs before every query, so a throw takes down every page. |
58
+ | `larrylint/orchestr-meta` | `defineOrchestr.meta({ app })` is the package name, which traces use to tell which app's middleware ran. |
59
+ | `larrylint/token-namespaces` | Your own tokens stay out of the namespaces of Laioutr's canonical types, like `ecommerce/`, where registration order decides which handler wins. |
60
+ | `larrylint/token-nullable` | Entity component tokens have no nullable top-level fields, which Studio can't bind. |
61
+
62
+ ### Sections and blocks
63
+
64
+ | Rule | Description |
65
+ | --- | --- |
66
+ | `larrylint/definition-folder` | `defineSection()` lives in `app/sections/` and `defineBlock()` in `app/blocks/`, and every `.vue` there has one. |
67
+ | `larrylint/definition-prefix` | Sections are named `Section*.vue`, blocks `Block*.vue`. |
68
+ | `larrylint/component-name` | The `component` of a definition matches its file name. |
69
+ | `larrylint/definition-description` | Definitions have a `studio.description`, which Studio shows in its section and block picker. |
70
+ | `larrylint/root-id` | The root element has no `id`: frontend-core replaces it with its own. |
71
+ | `larrylint/single-root` | Sections and blocks render one root element, also through a component they wrap. Otherwise Vue drops the `data-lfc-*` markers frontend-core adds. |
72
+ | `larrylint/slot-children` | Nothing counts slot children with `.length`: Studio passes all blocks of a slot as one Fragment. |
73
+ | `larrylint/reserved-field-names` | No top-level schema fields named `style`, `class`, `key`, `ref`, `is`, `slot`, `refFor` or `refKey`, which Vue swallows before they reach the component. |
74
+ | `larrylint/field-name-case` | Top-level schema fields are camelCase, since they become props. |
75
+ | `larrylint/required-fields` | Schema fields have no `required`, which Studio ignores. Give them a `default` instead. |
76
+ | `larrylint/schema-groups` | Schema groups are Studio's panels, in the order Content, Design, Rules. |
77
+ | `larrylint/unused-fields` | The component reads every schema field it defines, so editors don't get fields that do nothing. |
78
+ | `larrylint/dead-fallbacks` | No `??` fallbacks or `undefined` checks on props that are never `undefined`: unset checkbox, select, radio and toggle fields arrive as `false`, unset text fields as `''`. |
79
+
80
+ ### Frontend
81
+
82
+ | Rule | Description |
83
+ | --- | --- |
84
+ | `larrylint/button-type` | No `type` on the ui-kit button: it always renders its `button-type` prop, so `type="submit"` silently renders a dead button. Autofixable. |
85
+ | `larrylint/ui-kit-tags` | `<l-*>` tags are ui-kit or ui components. Anything else renders nothing. |
86
+ | `larrylint/mutation-errors` | An awaited or dropped `mutateAsync()` handles its error. Otherwise a failed mutation replaces the whole section or block with frontend-core's "Retry" state. |
87
+ | `larrylint/orchestr-store` | Components read orchestr data through composables, not `useOrchestrStore()`. |
88
+ | `larrylint/resolve-result` | Nothing tests the result of `linkResolver.resolve()`, which is never empty: a link it can't resolve comes back as a `#missing-required-params…` string. |
89
+ | `larrylint/hand-built-links` | Internal links come from `linkResolver`, not from paths like `` `/hotels/${slug}` ``, which break when a page type's route changes. |
90
+ | `larrylint/internal-anchors` | Internal links use `<NuxtLink>`: a plain `<a>` reloads the page and breaks Studio's navigation sync. |
91
+
92
+ ### Canonical types
93
+
94
+ | Rule | What it checks |
95
+ | --- | --- |
96
+ | `larrylint/money` | Money amounts are integers in minor units, e.g. `1999` for 19.99, and currencies are ISO 4217 codes like `EUR`. |
97
+
39
98
  ## Layout
40
99
 
41
100
  larrylint expects the layout of Laioutr's [app starter](https://github.com/laioutr/app-starter):
@@ -51,6 +110,8 @@ src/
51
110
  │ ├── composables/
52
111
  │ ├── overrides/ # replacements for upstream components
53
112
  │ ├── plugins/
113
+ │ ├── shared-fields/ # schema fields sections and blocks share
114
+ │ ├── theme/
54
115
  │ └── utils/
55
116
  ├── server/
56
117
  │ ├── orchestr/
@@ -58,9 +119,9 @@ src/
58
119
  │ │ └── plugins/
59
120
  │ ├── middleware/ # orchestr middleware and the builders handlers use
60
121
  │ ├── client/ # API clients, nothing else
61
- │ ├── api/ # server routes
122
+ │ ├── api/ # server routes, or routes/
62
123
  │ ├── plugins/ # Nitro plugins
63
- │ ├── media-library/
124
+ │ ├── media-library/ # or media-libraries/
64
125
  │ └── utils/
65
126
  │ └── <domain>/
66
127
  └── shared/ # code for both the app and the server
@@ -80,12 +141,18 @@ npx larrylint --baseline
80
141
 
81
142
  ## Configuration
82
143
 
83
- Most apps need none. To let every domain import a domain, add it to `sharedDomains` in your `package.json`:
144
+ Most apps need none. Two options tune the rules:
145
+
146
+ - `sharedDomains`: domains every other domain may import, for `layers`.
147
+ - `heavyPackages`: packages that sections, blocks and plugins must load with `import()`, for `heavy-imports`.
148
+
149
+ Set them in your `package.json`:
84
150
 
85
151
  ```json
86
152
  {
87
153
  "larrylint": {
88
- "sharedDomains": ["product"]
154
+ "sharedDomains": ["product"],
155
+ "heavyPackages": ["leaflet"]
89
156
  }
90
157
  }
91
158
  ```
@@ -97,6 +164,7 @@ import { defineLarrylintConfig } from 'larrylint'
97
164
 
98
165
  export default defineLarrylintConfig({
99
166
  sharedDomains: ['product'],
167
+ heavyPackages: ['leaflet'],
100
168
  })
101
169
  ```
102
170
 
@@ -1,8 +1,7 @@
1
- import { larrylint, readBaseline } from "./preset.mjs";
2
- import { relative } from "pathe";
1
+ import { applyBaseline, larrylint } from "./preset.mjs";
3
2
  import tsParser from "@typescript-eslint/parser";
4
- import { ESLint } from "eslint";
5
3
  import vueParser from "vue-eslint-parser";
4
+ import { ESLint } from "eslint";
6
5
  const PARSERS = [
7
6
  { ignores: ["**/*.d.ts"] },
8
7
  {
@@ -42,35 +41,4 @@ async function check(cwd, options = {}) {
42
41
  ...applyBaseline(cwd, results)
43
42
  };
44
43
  }
45
- function applyBaseline(cwd, results) {
46
- const baseline = readBaseline(cwd);
47
- const violations = {};
48
- let baselined = 0;
49
- let improved = 0;
50
- const filtered = results.map((result) => {
51
- const path = relative(cwd, result.filePath);
52
- const perRule = {};
53
- const relevant = result.messages.filter((message) => message.fatal || message.ruleId?.startsWith("larrylint/"));
54
- for (const { ruleId } of relevant) if (ruleId) perRule[ruleId] = (perRule[ruleId] ?? 0) + 1;
55
- if (Object.keys(perRule).length > 0) violations[path] = perRule;
56
- const messages = relevant.filter(({ ruleId }) => !ruleId || perRule[ruleId] > (baseline[path]?.[ruleId] ?? 0));
57
- baselined += relevant.length - messages.length;
58
- return {
59
- ...result,
60
- messages,
61
- errorCount: messages.filter((message) => message.severity === 2).length,
62
- fatalErrorCount: messages.filter((message) => message.fatal).length,
63
- warningCount: messages.filter((message) => message.severity === 1).length,
64
- fixableErrorCount: messages.filter((message) => message.severity === 2 && message.fix).length,
65
- fixableWarningCount: messages.filter((message) => message.severity === 1 && message.fix).length
66
- };
67
- });
68
- for (const [path, rules] of Object.entries(baseline)) for (const [rule, allowed] of Object.entries(rules)) if ((violations[path]?.[rule] ?? 0) < allowed) improved++;
69
- return {
70
- results: filtered,
71
- violations,
72
- baselined,
73
- improved
74
- };
75
- }
76
44
  export { check };
@@ -2,8 +2,8 @@ import { BASELINE_FILE, countViolations, writeBaseline } from "./preset.mjs";
2
2
  import { cwdArgs } from "../cli/index.mjs";
3
3
  import { check } from "./check.mjs";
4
4
  import process from "node:process";
5
- import { existsSync } from "node:fs";
6
5
  import { join, resolve } from "pathe";
6
+ import { existsSync } from "node:fs";
7
7
  import { defineCommand } from "citty";
8
8
  import { consola } from "consola";
9
9
  var check_default = defineCommand({
@@ -2,13 +2,27 @@ import { BASELINE_FILE, countViolations, writeBaseline } from "./preset.mjs";
2
2
  import { cwdArgs } from "../cli/index.mjs";
3
3
  import { check } from "./check.mjs";
4
4
  import process from "node:process";
5
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
6
5
  import { join, relative, resolve } from "pathe";
6
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
7
7
  import { defineCommand } from "citty";
8
8
  import { consola } from "consola";
9
9
  import { addDevDependency, detectPackageManager } from "nypm";
10
10
  import { readPackageJSON } from "pkg-types";
11
11
  import { parseModule } from "magicast";
12
+ function appendItem(code, container, items, text) {
13
+ const closing = container.end - 1;
14
+ const last = items.at(-1);
15
+ const insert = (at, insertion) => ({
16
+ start: at,
17
+ end: at,
18
+ text: insertion
19
+ });
20
+ if (!last) return insert(closing, text);
21
+ if (!code.slice(container.start, container.end).includes("\n")) return insert(last.end, `, ${text}`);
22
+ const indent = code.slice(code.lastIndexOf("\n", last.start) + 1, last.start).match(/^[ \t]*/)[0];
23
+ const comma = code.indexOf(",", last.end);
24
+ return comma !== -1 && comma < closing ? insert(comma + 1, `\n${indent}${text},`) : insert(last.end, `,\n${indent}${text}`);
25
+ }
12
26
  const CONFIG_FILES = [
13
27
  "eslint.config.js",
14
28
  "eslint.config.mjs",
@@ -92,20 +106,6 @@ function isComposer(call, imports) {
92
106
  const factory = node.callee.type === "Identifier" ? imports.find((item) => item.local === node.callee.name) : void 0;
93
107
  return factory ? COMPOSERS.test(factory.from) : false;
94
108
  }
95
- function appendItem(code, container, items, text) {
96
- const closing = container.end - 1;
97
- const last = items.at(-1);
98
- const insert = (at, insertion) => ({
99
- start: at,
100
- end: at,
101
- text: insertion
102
- });
103
- if (!last) return insert(closing, text);
104
- if (!code.slice(container.start, container.end).includes("\n")) return insert(last.end, `, ${text}`);
105
- const indent = code.slice(code.lastIndexOf("\n", last.start) + 1, last.start).match(/^[ \t]*/)[0];
106
- const comma = code.indexOf(",", last.end);
107
- return comma !== -1 && comma < closing ? insert(comma + 1, `\n${indent}${text},`) : insert(last.end, `,\n${indent}${text}`);
108
- }
109
109
  var init_default = defineCommand({
110
110
  meta: {
111
111
  name: "init",
@@ -1,4 +1,4 @@
1
1
  var name = "larrylint";
2
- var version = "0.1.0";
3
- var description = "Opinionated structure rules for Laioutr apps, as an ESLint preset and a CLI.";
2
+ var version = "0.1.1";
3
+ var description = "Opinionated rules for Laioutr apps, as an ESLint preset and a CLI.";
4
4
  export { description, name, version };