@ossido-labs/ossido-eslint-plugin 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 +21 -0
- package/README.md +84 -0
- package/dist/esm/index.d.ts +34 -0
- package/dist/esm/index.js +53 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Schofield
|
|
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,84 @@
|
|
|
1
|
+
# ossido-eslint-plugin
|
|
2
|
+
|
|
3
|
+
Lint rules [ossido](https://ossido.dev) projects should run. It exposes one rule
|
|
4
|
+
today —
|
|
5
|
+
[`react-refresh/only-export-components`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)
|
|
6
|
+
— authored with [oxlint](https://oxc.rs)'s performant `createOnce` API and
|
|
7
|
+
wrapped with `eslintCompatPlugin`, so the **same package runs under both oxlint
|
|
8
|
+
and ESLint**.
|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
React Fast Refresh can only hot-update a module when **every** export is a
|
|
13
|
+
component. A single non-component export (an object, function, or class) next to
|
|
14
|
+
your component turns every edit to that file into a **full page reload** instead
|
|
15
|
+
of a state-preserving hot update — and on an SSR route, that reload refetches the
|
|
16
|
+
route's server data. (Primitive constant exports are fine; Vite handles them.)
|
|
17
|
+
|
|
18
|
+
The default export being the component doesn't help: the refresh boundary is the
|
|
19
|
+
whole module, so one disqualifying export poisons the file. This rule flags that
|
|
20
|
+
at author time, before you feel it in dev.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Install:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install -D @ossido-labs/ossido-eslint-plugin
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### oxlint (`.oxlintrc.json`)
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"jsPlugins": ["@ossido-labs/ossido-eslint-plugin"],
|
|
35
|
+
"rules": {
|
|
36
|
+
"react-refresh/only-export-components": [
|
|
37
|
+
"warn",
|
|
38
|
+
{ "allowConstantExport": true }
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> JS plugins are an alpha oxlint feature — requires an oxlint version that
|
|
45
|
+
> supports `jsPlugins`.
|
|
46
|
+
|
|
47
|
+
### ESLint (`eslint.config.js`, flat config)
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import reactRefresh from '@ossido-labs/ossido-eslint-plugin';
|
|
51
|
+
|
|
52
|
+
export default [
|
|
53
|
+
{
|
|
54
|
+
files: ['**/*.{jsx,tsx}'],
|
|
55
|
+
plugins: { 'react-refresh': reactRefresh },
|
|
56
|
+
rules: {
|
|
57
|
+
'react-refresh/only-export-components': [
|
|
58
|
+
'warn',
|
|
59
|
+
{ allowConstantExport: true },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`allowConstantExport: true` permits `export const FOO = 'bar'` (primitive
|
|
67
|
+
constants), which don't break Fast Refresh — matching the runtime behaviour.
|
|
68
|
+
|
|
69
|
+
## Fixing a warning
|
|
70
|
+
|
|
71
|
+
Move the non-component export to its own module:
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
// page.tsx — clean boundary, hot-updates with state preserved
|
|
75
|
+
import { PAGE_META } from './page.meta';
|
|
76
|
+
export default function Page() {
|
|
77
|
+
/* ... */
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// page.meta.ts
|
|
83
|
+
export const PAGE_META = { title: 'Home' };
|
|
84
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oxlint (and ESLint) plugin for ossido projects.
|
|
3
|
+
*
|
|
4
|
+
* Exposes [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)'s
|
|
5
|
+
* `only-export-components` rule authored with oxlint's performant `createOnce`
|
|
6
|
+
* API, then wrapped with {@link eslintCompatPlugin} so the same package works as
|
|
7
|
+
* both an oxlint JS plugin (`jsPlugins`) and a standard ESLint plugin (the
|
|
8
|
+
* wrapper adds ESLint-compatible `create` methods that delegate to `createOnce`).
|
|
9
|
+
*
|
|
10
|
+
* The rule keeps route/component files valid React Fast Refresh boundaries: it
|
|
11
|
+
* flags a non-component export (object, function, class) co-located with a
|
|
12
|
+
* component, which would otherwise force a full page reload on every edit to
|
|
13
|
+
* that file instead of a state-preserving hot update. Primitive constant exports
|
|
14
|
+
* are permitted via the rule's `allowConstantExport` option (they don't break
|
|
15
|
+
* Fast Refresh under Vite).
|
|
16
|
+
*
|
|
17
|
+
* The plugin is namespaced `react-refresh`, so the rule id is
|
|
18
|
+
* `react-refresh/only-export-components`.
|
|
19
|
+
*
|
|
20
|
+
* @example .oxlintrc.json
|
|
21
|
+
* ```json
|
|
22
|
+
* {
|
|
23
|
+
* "jsPlugins": ["@ossido-labs/ossido-eslint-plugin"],
|
|
24
|
+
* "rules": {
|
|
25
|
+
* "react-refresh/only-export-components": [
|
|
26
|
+
* "warn",
|
|
27
|
+
* { "allowConstantExport": true }
|
|
28
|
+
* ]
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare const plugin: import("@oxlint/plugins").Plugin;
|
|
34
|
+
export default plugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import reactRefresh from "eslint-plugin-react-refresh";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const eslintRule = reactRefresh.rules["only-export-components"];
|
|
6
|
+
const rule = defineRule({
|
|
7
|
+
meta: eslintRule.meta,
|
|
8
|
+
createOnce(context) {
|
|
9
|
+
return { Program(node) {
|
|
10
|
+
eslintRule.create(context).Program?.(node);
|
|
11
|
+
} };
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Oxlint (and ESLint) plugin for ossido projects.
|
|
16
|
+
*
|
|
17
|
+
* Exposes [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)'s
|
|
18
|
+
* `only-export-components` rule authored with oxlint's performant `createOnce`
|
|
19
|
+
* API, then wrapped with {@link eslintCompatPlugin} so the same package works as
|
|
20
|
+
* both an oxlint JS plugin (`jsPlugins`) and a standard ESLint plugin (the
|
|
21
|
+
* wrapper adds ESLint-compatible `create` methods that delegate to `createOnce`).
|
|
22
|
+
*
|
|
23
|
+
* The rule keeps route/component files valid React Fast Refresh boundaries: it
|
|
24
|
+
* flags a non-component export (object, function, class) co-located with a
|
|
25
|
+
* component, which would otherwise force a full page reload on every edit to
|
|
26
|
+
* that file instead of a state-preserving hot update. Primitive constant exports
|
|
27
|
+
* are permitted via the rule's `allowConstantExport` option (they don't break
|
|
28
|
+
* Fast Refresh under Vite).
|
|
29
|
+
*
|
|
30
|
+
* The plugin is namespaced `react-refresh`, so the rule id is
|
|
31
|
+
* `react-refresh/only-export-components`.
|
|
32
|
+
*
|
|
33
|
+
* @example .oxlintrc.json
|
|
34
|
+
* ```json
|
|
35
|
+
* {
|
|
36
|
+
* "jsPlugins": ["@ossido-labs/ossido-eslint-plugin"],
|
|
37
|
+
* "rules": {
|
|
38
|
+
* "react-refresh/only-export-components": [
|
|
39
|
+
* "warn",
|
|
40
|
+
* { "allowConstantExport": true }
|
|
41
|
+
* ]
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const plugin = eslintCompatPlugin({
|
|
47
|
+
meta: { name: "react-refresh" },
|
|
48
|
+
rules: { "only-export-components": rule }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { plugin as default };
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { defineRule, eslintCompatPlugin } from '@oxlint/plugins';\nimport type { Context, RuleMeta } from '@oxlint/plugins';\nimport reactRefresh from 'eslint-plugin-react-refresh';\n\n// eslint-plugin-react-refresh authors the rule with ESLint's per-file\n// `create(context)` API, doing all its work in a single `Program` visitor. We\n// re-expose it through oxlint's performant `createOnce` API (called once, so\n// oxlint can statically see the visited node types), delegating each file's\n// check to the upstream rule. The rule reads per-file context (filename /\n// source) at `create` time, so a fresh instance is created for each `Program`\n// (i.e. per file) — reusing one instance across files reports nothing.\ninterface EslintRuleModule {\n meta?: RuleMeta;\n create: (context: unknown) => { Program?: (node: unknown) => void };\n}\n\nconst eslintRule = reactRefresh.rules[\n 'only-export-components'\n] as unknown as EslintRuleModule;\n\nconst rule = defineRule({\n meta: eslintRule.meta,\n createOnce(context: Context) {\n return {\n Program(node): void {\n eslintRule.create(context).Program?.(node);\n },\n };\n },\n});\n\n/**\n * Oxlint (and ESLint) plugin for ossido projects.\n *\n * Exposes [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)'s\n * `only-export-components` rule authored with oxlint's performant `createOnce`\n * API, then wrapped with {@link eslintCompatPlugin} so the same package works as\n * both an oxlint JS plugin (`jsPlugins`) and a standard ESLint plugin (the\n * wrapper adds ESLint-compatible `create` methods that delegate to `createOnce`).\n *\n * The rule keeps route/component files valid React Fast Refresh boundaries: it\n * flags a non-component export (object, function, class) co-located with a\n * component, which would otherwise force a full page reload on every edit to\n * that file instead of a state-preserving hot update. Primitive constant exports\n * are permitted via the rule's `allowConstantExport` option (they don't break\n * Fast Refresh under Vite).\n *\n * The plugin is namespaced `react-refresh`, so the rule id is\n * `react-refresh/only-export-components`.\n *\n * @example .oxlintrc.json\n * ```json\n * {\n * \"jsPlugins\": [\"@ossido-labs/ossido-eslint-plugin\"],\n * \"rules\": {\n * \"react-refresh/only-export-components\": [\n * \"warn\",\n * { \"allowConstantExport\": true }\n * ]\n * }\n * }\n * ```\n */\nconst plugin = eslintCompatPlugin({\n meta: { name: 'react-refresh' },\n rules: { 'only-export-components': rule },\n});\n\nexport default plugin;\n"],"mappings":";;;;AAgBA,MAAM,aAAa,aAAa,MAC9B;AAGF,MAAM,OAAO,WAAW;CACtB,MAAM,WAAW;CACjB,WAAW,SAAkB;EAC3B,OAAO,EACL,QAAQ,MAAY;GAClB,WAAW,OAAO,OAAO,CAAC,CAAC,UAAU,IAAI;EAC3C,EACF;CACF;AACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCD,MAAM,SAAS,mBAAmB;CAChC,MAAM,EAAE,MAAM,gBAAgB;CAC9B,OAAO,EAAE,0BAA0B,KAAK;AAC1C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ossido-labs/ossido-eslint-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Oxlint plugin bundling the lint rules ossido projects should run. Currently exposes react-refresh's only-export-components so route/component files stay valid React Fast Refresh boundaries. Ossido is the react/rust fullstack framework",
|
|
8
|
+
"homepage": "https://ossido.dev",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "tsdown --watch",
|
|
11
|
+
"build": "tsdown && tsc -p tsconfig.build.json",
|
|
12
|
+
"prepack": "bun run build",
|
|
13
|
+
"lint": "oxlint",
|
|
14
|
+
"format": "oxfmt --check .",
|
|
15
|
+
"format:fix": "oxfmt .",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"test": "vitest run"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ossido-labs/ossido.git",
|
|
23
|
+
"directory": "packages/ossido-eslint-plugin"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "Chris Schofield <chris@childishforces.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"types": "dist/esm/index.d.ts",
|
|
30
|
+
"main": "dist/esm/index.js",
|
|
31
|
+
"module": "dist/esm/index.js",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/esm/index.d.ts",
|
|
39
|
+
"default": "./dist/esm/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"eslint-plugin-react-refresh": "^0.5.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@oxlint/plugins": "^1.76.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@oxlint/plugins": "1.76.0",
|
|
51
|
+
"oxlint": "1.76.0",
|
|
52
|
+
"tsdown": "0.22.14",
|
|
53
|
+
"vite-config": "1.0.0",
|
|
54
|
+
"vitest": "4.1.10"
|
|
55
|
+
}
|
|
56
|
+
}
|