Skip to content

AI-native design editor. Open-source Figma alternative.

feat(oxlint-plugin): ship the recommended configuration OpenPencil's repositories extend (#1708)

Danila Poyarkovf6fd8fa74037
diff --git a/changes/1708/added.md b/changes/1708/added.md
new file mode 100644
index 000000000..fcf975065
--- /dev/null
+++ b/changes/1708/added.md
@@ -0,0 +1 @@
+- `@open-pencil/oxlint-plugin/recommended` is the Oxlint configuration OpenPencil's repositories extend: the TypeScript, import, unicorn, promise, and Node rules they follow and the plugin's own, for a JSON `extends` path or `oxlint.config.ts`.
diff --git a/oxlint.json b/oxlint.json
index ce0acbc0d..e2249a2ad 100644
--- a/oxlint.json
+++ b/oxlint.json
@@ -1,17 +1,8 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
- "plugins": [
- "typescript",
- "import",
- "unicorn",
- "vue",
- "promise",
- "node"
- ],
- "jsPlugins": [
- "./lint/plugin.js",
- "eslint-plugin-compat"
- ],
+ "extends": ["./packages/oxlint-plugin/recommended.json"],
+ "plugins": ["typescript", "import", "unicorn", "vue", "promise", "node"],
+ "jsPlugins": ["./lint/plugin.js", "eslint-plugin-compat"],
"settings": {
"browsers": ["chrome 111", "edge 111", "firefox 128", "safari 16.4", "ios_saf 16.4"]
},
@@ -19,29 +10,17 @@
"browser": true,
"es2024": true
},
+ "categories": {
+ "correctness": "error"
+ },
+ "ignorePatterns": [
+ "node_modules",
+ "dist",
+ "desktop",
+ "packages/mermaid/src/upstream",
+ "*.config.*"
+ ],
"rules": {
- "no-unused-vars": "warn",
- "no-console": [
- "warn",
- {
- "allow": [
- "warn",
- "error",
- "debug",
- "time",
- "timeEnd"
- ]
- }
- ],
- "eqeqeq": [
- "error",
- "always",
- {
- "null": "ignore"
- }
- ],
- "prefer-const": "error",
- "radix": "error",
"no-restricted-imports": [
"error",
{
@@ -52,74 +31,23 @@
},
{
"name": "node:module",
- "importNames": [
- "createRequire"
- ],
+ "importNames": ["createRequire"],
"message": "Use ESM imports or import.meta.resolve instead of createRequire/require."
}
],
"patterns": [
{
- "group": [
- "@/engine/*"
- ],
+ "group": ["@/engine/*"],
"message": "Import from @open-pencil/core unless the module adds platform-specific logic.",
- "allowImportNames": [
- "loadFont",
- "listFamilies",
- "listFonts",
- "preloadFonts"
- ]
+ "allowImportNames": ["loadFont", "listFamilies", "listFonts", "preloadFonts"]
},
{
- "group": [
- "../../packages/*",
- "../../../packages/*"
- ],
+ "group": ["../../packages/*", "../../../packages/*"],
"message": "Use the workspace package name (e.g. @open-pencil/core) instead of relative paths to packages/."
}
]
}
],
- "no-empty-function": "error",
- "max-lines": [
- "warn",
- {
- "max": 600
- }
- ],
- "complexity": [
- "error",
- {
- "max": 20
- }
- ],
- "typescript/no-explicit-any": "error",
- "typescript/no-non-null-assertion": "error",
- "typescript/no-floating-promises": "error",
- "typescript/no-misused-promises": "error",
- "typescript/consistent-type-imports": "error",
- "typescript/consistent-return": "error",
- "typescript/no-unnecessary-condition": "error",
- "typescript/no-unnecessary-type-assertion": "error",
- "typescript/no-unnecessary-type-parameters": "error",
- "typescript/no-unnecessary-boolean-literal-compare": "error",
- "typescript/no-unnecessary-template-expression": "error",
- "typescript/no-unnecessary-type-arguments": "error",
- "typescript/prefer-optional-chain": "error",
- "typescript/prefer-for-of": "error",
- "import/no-cycle": "error",
- "import/no-self-import": "error",
- "import/no-duplicates": "error",
- "import/no-mutable-exports": "error",
- "unicorn/no-instanceof-array": "error",
- "unicorn/no-typeof-undefined": "error",
- "unicorn/no-nested-ternary": "error",
- "unicorn/no-useless-fallback-in-spread": "error",
- "unicorn/no-length-as-slice-end": "error",
- "unicorn/no-unnecessary-await": "error",
- "unicorn/prefer-string-starts-ends-with": "error",
- "unicorn/consistent-existence-index-check": "error",
"vue/no-arrow-functions-in-watch": "error",
"vue/no-deprecated-destroyed-lifecycle": "error",
"vue/no-export-in-script-setup": "error",
@@ -151,7 +79,6 @@
"vue/prop-name-casing": "error",
"vue/valid-define-options": "error",
"vue/valid-next-tick": "error",
- "open-pencil/no-import-type-annotations": "error",
"open-pencil/no-inline-named-types": [
"error",
{
@@ -179,13 +106,11 @@
"open-pencil/no-browser-side-effects-in-vue": "error",
"open-pencil/no-document-query-selector-in-vue": "error",
"open-pencil/no-direct-selection-tool-state-mutation": "error",
- "open-pencil/no-math-random": "error",
"open-pencil/no-hardcoded-color-constants": "error",
"open-pencil/no-unknown-tailwind-classes": "error",
"open-pencil/no-px-tailwind-values": "error",
"open-pencil/no-hand-rolled-color": "error",
"open-pencil/no-raw-console-format": "off",
- "open-pencil/no-silent-catch": "error",
"open-pencil/no-typeof-window-check": "error",
"open-pencil/no-vue-self-package-imports": "error",
"open-pencil/no-cross-package-source-imports": "error",
@@ -193,20 +118,11 @@
"open-pencil/no-core-framework-imports": "error",
"open-pencil/no-inline-tauri-imports": "error",
"open-pencil/no-direct-storage-access": "error",
- "open-pencil/no-deep-parent-relative-imports": "error",
- "open-pencil/no-deep-parent-relative-paths": "error",
- "open-pencil/no-broad-double-cast": "error",
- "open-pencil/no-unknown-record-double-cast": "error",
- "open-pencil/no-broad-unknown-type-assertions": "error",
"open-pencil/no-local-json-object-aliases": "error",
- "open-pencil/no-duplicate-type-shapes": "error",
- "open-pencil/no-ts-suppression-comments": "error",
- "open-pencil/no-reflect-delete-global-this-outside-tests": "error",
"open-pencil/no-core-browser-globals": "error",
"open-pencil/no-zoom-in-scene-drawing": "error",
"open-pencil/no-direct-open-pencil-window-internals": "error",
"open-pencil/no-direct-open-pencil-browser-store": "error",
- "open-pencil/no-function-alias-imports": "error",
"open-pencil/max-composition-root-lines": [
"error",
{
@@ -256,185 +172,6 @@
"open-pencil/no-bun-globals-in-cli": "error",
"open-pencil/no-top-level-prefixed-test-files": "error",
"open-pencil/no-editor-profile-inputs": "error",
- "open-pencil/no-conditional-object-spreads": "error",
- "open-pencil/no-sibling-domain-prefixed-files": "error",
- "array-callback-return": "error",
- "block-scoped-var": "error",
- "default-case-last": "error",
- "default-param-last": "error",
- "guard-for-in": "error",
- "no-array-constructor": "error",
- "no-case-declarations": "error",
- "no-caller": "error",
- "no-constructor-return": "error",
- "no-else-return": "error",
- "no-empty-pattern": "error",
- "no-eval": "error",
- "no-extend-native": "error",
- "no-extra-bind": "error",
- "no-extra-label": "error",
- "no-implied-eval": "error",
- "no-iterator": "error",
- "no-labels": "error",
- "no-lone-blocks": "error",
- "no-multi-str": "error",
- "no-new": "error",
- "no-new-wrappers": "error",
- "no-object-constructor": "error",
- "no-proto": "error",
- "no-return-assign": "error",
- "no-script-url": "error",
- "no-self-compare": "error",
- "no-sequences": "error",
- "no-template-curly-in-string": "error",
- "no-unmodified-loop-condition": "error",
- "no-unneeded-ternary": "error",
- "no-unused-expressions": "error",
- "no-useless-assignment": "error",
- "no-useless-call": "error",
- "no-useless-computed-key": "error",
- "no-useless-concat": "error",
- "no-useless-constructor": "error",
- "no-useless-rename": "error",
- "no-useless-return": "error",
- "prefer-numeric-literals": "error",
- "prefer-object-has-own": "error",
- "prefer-promise-reject-errors": "error",
- "prefer-regex-literals": "error",
- "prefer-rest-params": "error",
- "prefer-spread": "error",
- "symbol-description": "error",
- "unicode-bom": "error",
- "yoda": "error",
- "typescript/adjacent-overload-signatures": "error",
- "typescript/await-thenable": "error",
- "typescript/ban-ts-comment": "error",
- "typescript/ban-tslint-comment": "error",
- "typescript/no-array-delete": "error",
- "typescript/no-base-to-string": "error",
- "typescript/no-confusing-non-null-assertion": "error",
- "typescript/no-duplicate-enum-values": "error",
- "typescript/no-duplicate-type-constituents": "error",
- "typescript/no-extraneous-class": "error",
- "typescript/no-extra-non-null-assertion": "error",
- "typescript/no-for-in-array": "error",
- "typescript/no-implied-eval": "error",
- "typescript/no-invalid-void-type": "error",
- "typescript/no-meaningless-void-operator": "error",
- "typescript/no-misused-new": "error",
- "typescript/no-misused-spread": "error",
- "typescript/no-mixed-enums": "error",
- "typescript/no-non-null-asserted-nullish-coalescing": "error",
- "typescript/no-non-null-asserted-optional-chain": "error",
- "typescript/no-redundant-type-constituents": "error",
- "typescript/no-this-alias": "error",
- "typescript/no-unnecessary-parameter-property-assignment": "error",
- "typescript/no-unnecessary-qualifier": "error",
- "typescript/no-unnecessary-type-constraint": "error",
- "typescript/no-unsafe-enum-comparison": "error",
- "typescript/no-unsafe-function-type": "error",
- "typescript/no-unsafe-unary-minus": "error",
- "typescript/no-useless-default-assignment": "error",
- "typescript/no-useless-empty-export": "error",
- "typescript/no-var-requires": "error",
- "typescript/no-wrapper-object-types": "error",
- "typescript/only-throw-error": "error",
- "typescript/prefer-as-const": "error",
- "typescript/prefer-find": "error",
- "typescript/prefer-function-type": "error",
- "typescript/prefer-promise-reject-errors": "error",
- "typescript/prefer-reduce-type-parameter": "error",
- "typescript/prefer-return-this-type": "error",
- "typescript/prefer-ts-expect-error": "error",
- "typescript/require-array-sort-compare": "error",
- "typescript/triple-slash-reference": "error",
- "import/no-absolute-path": "error",
- "import/no-amd": "error",
- "import/no-commonjs": "error",
- "import/no-dynamic-require": "error",
- "import/no-empty-named-blocks": "error",
- "import/no-webpack-loader-syntax": "error",
- "promise/always-return": "error",
- "promise/catch-or-return": "error",
- "promise/no-callback-in-promise": "error",
- "promise/no-multiple-resolved": "error",
- "promise/no-new-statics": "error",
- "promise/no-promise-in-callback": "error",
- "promise/no-return-in-finally": "error",
- "promise/no-return-wrap": "error",
- "promise/valid-params": "error",
- "node/no-exports-assign": "error",
- "node/no-new-require": "error",
- "node/no-path-concat": "error",
- "oxc/approx-constant": "error",
- "oxc/missing-throw": "error",
- "oxc/no-accumulating-spread": "error",
- "oxc/no-async-endpoint-handlers": "error",
- "oxc/no-map-spread": "error",
- "oxc/number-arg-out-of-range": "error",
- "oxc/uninvoked-array-callback": "error",
- "unicorn/consistent-assert": "error",
- "unicorn/consistent-date-clone": "error",
- "unicorn/consistent-empty-array-spread": "error",
- "unicorn/consistent-template-literal-escape": "error",
- "unicorn/custom-error-definition": "error",
- "unicorn/error-message": "error",
- "unicorn/new-for-builtins": "error",
- "unicorn/no-abusive-eslint-disable": "error",
- "unicorn/no-accessor-recursion": "error",
- "unicorn/no-anonymous-default-export": "error",
- "unicorn/no-array-method-this-argument": "error",
- "unicorn/no-await-in-promise-methods": "error",
- "unicorn/no-console-spaces": "error",
- "unicorn/no-document-cookie": "error",
- "unicorn/no-empty-file": "error",
- "unicorn/no-instanceof-builtins": "error",
- "unicorn/no-invalid-fetch-options": "error",
- "unicorn/no-invalid-remove-event-listener": "error",
- "unicorn/no-magic-array-flat-depth": "error",
- "unicorn/no-negation-in-equality-check": "error",
- "unicorn/no-new-array": "error",
- "unicorn/no-new-buffer": "error",
- "unicorn/no-single-promise-in-promise-methods": "error",
- "unicorn/no-static-only-class": "error",
- "unicorn/no-thenable": "error",
- "unicorn/no-this-assignment": "error",
- "unicorn/no-unnecessary-array-flat-depth": "error",
- "unicorn/no-unnecessary-array-splice-count": "error",
- "unicorn/no-unnecessary-slice-end": "error",
- "unicorn/no-unreadable-iife": "error",
- "unicorn/no-useless-collection-argument": "error",
- "unicorn/no-useless-error-capture-stack-trace": "error",
- "unicorn/no-useless-iterator-to-array": "error",
- "unicorn/no-useless-length-check": "error",
- "unicorn/no-useless-promise-resolve-reject": "error",
- "unicorn/no-useless-spread": "error",
- "unicorn/no-useless-switch-case": "error",
- "unicorn/prefer-array-find": "error",
- "unicorn/prefer-array-flat": "error",
- "unicorn/prefer-array-flat-map": "error",
- "unicorn/prefer-array-index-of": "error",
- "unicorn/prefer-array-some": "error",
- "unicorn/prefer-blob-reading-methods": "error",
- "unicorn/prefer-classlist-toggle": "error",
- "unicorn/prefer-date-now": "error",
- "unicorn/prefer-event-target": "error",
- "unicorn/prefer-keyboard-event-key": "error",
- "unicorn/prefer-modern-dom-apis": "error",
- "unicorn/prefer-negative-index": "error",
- "unicorn/prefer-native-coercion-functions": "error",
- "unicorn/prefer-object-from-entries": "error",
- "unicorn/prefer-optional-catch-binding": "error",
- "unicorn/prefer-prototype-methods": "error",
- "unicorn/prefer-regexp-test": "error",
- "unicorn/prefer-set-size": "error",
- "unicorn/prefer-string-slice": "error",
- "unicorn/prefer-string-trim-start-end": "error",
- "unicorn/prefer-structured-clone": "error",
- "unicorn/prefer-type-error": "error",
- "unicorn/require-array-join-separator": "error",
- "unicorn/require-number-to-fixed-digits-argument": "error",
- "unicorn/throw-new-error": "error",
"vue/no-deprecated-data-object-declaration": "error",
"vue/no-deprecated-delete-set": "error",
"vue/no-deprecated-events-api": "error",
@@ -442,48 +179,59 @@
"vue/no-deprecated-vue-config-keycodes": "error",
"vue/no-this-in-before-route-enter": "error",
"vue/return-in-computed-property": "error",
- "unicorn/require-post-message-target-origin": "error",
- "unicorn/prefer-set-has": "error",
- "unicorn/prefer-modern-math-apis": "error",
- "unicorn/prefer-node-protocol": "error",
- "unicorn/prefer-number-properties": "error",
- "prefer-exponentiation-operator": "error",
- "no-promise-executor-return": "error",
- "typescript/no-empty-object-type": "error",
- "typescript/return-await": "error",
- "typescript/restrict-plus-operands": "error",
- "unicorn/prefer-includes": "error",
- "no-loop-func": "error",
- "typescript/no-dynamic-delete": "error",
- "open-pencil/no-hand-rolled-base64": "error",
- "open-pencil/prefer-es-toolkit": "error",
- "open-pencil/no-module-mocking": "error",
- "open-pencil/no-reduce-accumulator-copy": "error",
- "open-pencil/no-widen-then-assert": "error"
+ "open-pencil/no-unvalidated-json-parse": "off",
+ "open-pencil/valibot-schema-conventions": "off",
+ "open-pencil/no-useless-pass-through-wrappers": "off",
+ "open-pencil/no-secret-in-query": "off",
+ "open-pencil/no-secret-logging": "off"
},
"overrides": [
{
"files": ["packages/core/src/**"],
"rules": {
- "open-pencil/no-deep-parent-relative-imports": ["error", { "minDepth": 1, "alias": "#core/*" }]
+ "open-pencil/no-deep-parent-relative-imports": [
+ "error",
+ {
+ "minDepth": 1,
+ "alias": "#core/*"
+ }
+ ]
}
},
{
"files": ["packages/mcp/src/**"],
"rules": {
- "open-pencil/no-deep-parent-relative-imports": ["error", { "minDepth": 1, "alias": "#mcp/*" }]
+ "open-pencil/no-deep-parent-relative-imports": [
+ "error",
+ {
+ "minDepth": 1,
+ "alias": "#mcp/*"
+ }
+ ]
}
},
{
"files": ["packages/vue/src/**"],
"rules": {
- "open-pencil/no-deep-parent-relative-imports": ["error", { "minDepth": 1, "alias": "#vue/*" }]
+ "open-pencil/no-deep-parent-relative-imports": [
+ "error",
+ {
+ "minDepth": 1,
+ "alias": "#vue/*"
+ }
+ ]
}
},
{
"files": ["packages/cli/src/**"],
"rules": {
- "open-pencil/no-deep-parent-relative-imports": ["error", { "minDepth": 1, "alias": "#cli/*" }]
+ "open-pencil/no-deep-parent-relative-imports": [
+ "error",
+ {
+ "minDepth": 1,
+ "alias": "#cli/*"
+ }
+ ]
}
},
{
@@ -499,9 +247,7 @@
}
},
{
- "files": [
- "packages/cloud/src/**/*.ts"
- ],
+ "files": ["packages/cloud/src/**/*.ts"],
"rules": {
"typescript/no-unsafe-assignment": "error",
"typescript/no-unsafe-argument": "error",
@@ -573,10 +319,7 @@
}
},
{
- "files": [
- "src/**/*.ts",
- "packages/*/src/**/*.ts"
- ],
+ "files": ["src/**/*.ts", "packages/*/src/**/*.ts"],
"rules": {
"open-pencil/no-useless-pass-through-wrappers": "error"
}
@@ -592,14 +335,21 @@
"rules": {
"open-pencil/valibot-schema-conventions": [
"error",
- { "schemaModules": ["/packages/cloud/src/contract/"] }
+ {
+ "schemaModules": ["/packages/cloud/src/contract/"]
+ }
]
}
},
{
"files": ["tools/*/*/src/**/*.ts"],
"rules": {
- "open-pencil/valibot-schema-conventions": ["error", { "placement": false }]
+ "open-pencil/valibot-schema-conventions": [
+ "error",
+ {
+ "placement": false
+ }
+ ]
}
},
{
@@ -613,10 +363,7 @@
}
},
{
- "files": [
- "**/kiwi/schema-runtime/**",
- "**/kiwi/src/schema-runtime/**"
- ],
+ "files": ["**/kiwi/schema-runtime/**", "**/kiwi/src/schema-runtime/**"],
"rules": {
"typescript/no-explicit-any": "off",
"typescript/no-non-null-assertion": "off",
@@ -644,9 +391,7 @@
}
},
{
- "files": [
- "packages/cli/src/commands/**"
- ],
+ "files": ["packages/cli/src/commands/**"],
"rules": {
"open-pencil/no-raw-console-format": "error"
}
@@ -662,26 +407,19 @@
}
},
{
- "files": [
- "scripts/**/*.ts",
- "tools/**/*.ts"
- ],
+ "files": ["scripts/**/*.ts", "tools/**/*.ts"],
"rules": {
"no-console": "off"
}
},
{
- "files": [
- "packages/scene-graph/src/constants.ts"
- ],
+ "files": ["packages/scene-graph/src/constants.ts"],
"rules": {
"open-pencil/no-hardcoded-color-constants": "off"
}
},
{
- "files": [
- "packages/scene-graph/src/index.ts"
- ],
+ "files": ["packages/scene-graph/src/index.ts"],
"rules": {
"open-pencil/no-direct-graph-emitter-subscriptions": "off"
}
@@ -699,23 +437,10 @@
}
},
{
- "files": [
- "src/app/code/sandbox/evaluate.ts",
- "src/app/code/sandbox/frame.ts"
- ],
+ "files": ["src/app/code/sandbox/evaluate.ts", "src/app/code/sandbox/frame.ts"],
"rules": {
"import/default": "off"
}
}
- ],
- "ignorePatterns": [
- "node_modules",
- "dist",
- "desktop",
- "packages/mermaid/src/upstream",
- "*.config.*"
- ],
- "categories": {
- "correctness": "error"
- }
+ ]
}
diff --git a/packages/oxlint-plugin/AGENTS.md b/packages/oxlint-plugin/AGENTS.md
index 63c75412d..6a637235d 100644
--- a/packages/oxlint-plugin/AGENTS.md
+++ b/packages/oxlint-plugin/AGENTS.md
@@ -5,5 +5,6 @@ The published Oxlint plugin. `lint/plugin.js` combines it with this repository's
- A rule belongs here only when it holds for any TypeScript project. Paths, packages, and names a project chooses are rule options, set in `oxlint.json`, never constants in the rule (`schemaModules` in `src/rules/quality/valibot-schemas.ts`, `ignoredImports` in `src/rules/naming.ts`); rules about the app, Vue, Tauri, or the scene graph stay in `tools/checks/lint`.
- Type rules with `@oxlint/plugins` (`defineRule`, `ESTree`), never `@typescript-eslint/utils`, so the published declarations need no other package (`check:packages`).
- Import the package's own modules through `#oxlint-plugin/*` without an extension: `lint/plugin.js` loads the source under Node, which resolves the alias to the `.ts` file, so `bun run lint` needs no build.
-- A new rule is registered in `src/index.ts`, listed in `README.md`, and tested in `tests/rules/`, mirroring its source file, through `tests/helpers/lint.ts`, which runs Oxlint on the package source.
+- A new rule is registered in `src/index.ts`, listed in `README.md`, turned on in `recommended.json` unless it fits only some code (then it joins `OPT_IN` in `tests/recommended.test.ts`), and tested in `tests/rules/`, mirroring its source file, through `tests/helpers/lint.ts`, which runs Oxlint on the package source.
+- `recommended.json` holds the built-in rules every OpenPencil repository follows; this repository's `oxlint.json` extends it and adds only its own rules, options, and overrides.
- Renaming or removing a rule breaks consumers' configurations; record it under `breaking` in the changelog.
diff --git a/packages/oxlint-plugin/README.md b/packages/oxlint-plugin/README.md
index 38961c374..81c674209 100644
--- a/packages/oxlint-plugin/README.md
+++ b/packages/oxlint-plugin/README.md
@@ -19,6 +19,22 @@ npm install --save-dev oxlint @open-pencil/oxlint-plugin
The plugin is named `open-pencil`. Every rule is off until the configuration turns it on, so a project picks the ones it follows.
+## Recommended configuration
+
+`@open-pencil/oxlint-plugin/recommended` is the configuration OpenPencil's own repositories extend: Oxlint's `typescript`, `import`, `unicorn`, `promise`, and `node` plugins with the built-in rules they follow, and every rule below except `no-raw-sql` and `no-dynamic-html`, which fit only some code. Load the plugin beside it, since a configuration file cannot load a plugin for the one that extends it:
+
+```json
+{
+ "extends": ["./node_modules/@open-pencil/oxlint-plugin/recommended.json"],
+ "jsPlugins": ["@open-pencil/oxlint-plugin"],
+ "rules": {
+ "open-pencil/valibot-schema-conventions": ["error", { "schemaModules": ["/src/contract/"] }]
+ }
+}
+```
+
+An `extends` path resolves from the file that declares it, so a configuration in a nested workspace names the `node_modules` the package is installed in, such as `../../node_modules/@open-pencil/oxlint-plugin/recommended.json` when it is hoisted to the root. In `oxlint.config.ts`, import it instead, which resolves like any module, typed as `OxlintConfig`: `import recommended from '@open-pencil/oxlint-plugin/recommended'`, then `extends: [recommended]`. Some rules, such as `typescript/no-floating-promises`, run only with `oxlint --type-aware`. `max-lines` (600), `complexity` (20), and the `no-console` methods it allows are OpenPencil's choices; override any rule after `extends`.
+
## Rules
### Validation and data
diff --git a/packages/oxlint-plugin/package.json b/packages/oxlint-plugin/package.json
index a64779120..fcc9bd14e 100644
--- a/packages/oxlint-plugin/package.json
+++ b/packages/oxlint-plugin/package.json
@@ -16,6 +16,7 @@
"files": [
"dist",
"src",
+ "recommended.json",
"README.md"
],
"type": "module",
@@ -32,6 +33,12 @@
"bun": "./src/index.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
+ },
+ "./recommended": {
+ "types": "./dist/recommended.d.ts",
+ "bun": "./src/recommended.ts",
+ "import": "./dist/recommended.js",
+ "default": "./dist/recommended.js"
}
},
"publishConfig": {
diff --git a/packages/oxlint-plugin/recommended.d.json.ts b/packages/oxlint-plugin/recommended.d.json.ts
new file mode 100644
index 000000000..af5895eb9
--- /dev/null
+++ b/packages/oxlint-plugin/recommended.d.json.ts
@@ -0,0 +1,5 @@
+import type { OxlintConfig } from 'oxlint'
+
+/** `recommended.json` as Oxlint reads it; `tests/recommended.test.ts` runs Oxlint with it. */
+declare const recommended: OxlintConfig
+export default recommended
diff --git a/packages/oxlint-plugin/recommended.json b/packages/oxlint-plugin/recommended.json
new file mode 100644
index 000000000..7fd1e3b88
--- /dev/null
+++ b/packages/oxlint-plugin/recommended.json
@@ -0,0 +1,282 @@
+{
+ "plugins": ["typescript", "import", "unicorn", "promise", "node"],
+ "categories": {
+ "correctness": "error"
+ },
+ "env": {
+ "es2024": true
+ },
+ "rules": {
+ "no-unused-vars": "warn",
+ "no-console": [
+ "warn",
+ {
+ "allow": ["warn", "error", "debug", "time", "timeEnd"]
+ }
+ ],
+ "eqeqeq": [
+ "error",
+ "always",
+ {
+ "null": "ignore"
+ }
+ ],
+ "prefer-const": "error",
+ "radix": "error",
+ "no-empty-function": "error",
+ "max-lines": [
+ "warn",
+ {
+ "max": 600
+ }
+ ],
+ "complexity": [
+ "error",
+ {
+ "max": 20
+ }
+ ],
+ "typescript/no-explicit-any": "error",
+ "typescript/no-non-null-assertion": "error",
+ "typescript/no-floating-promises": "error",
+ "typescript/no-misused-promises": "error",
+ "typescript/consistent-type-imports": "error",
+ "typescript/consistent-return": "error",
+ "typescript/no-unnecessary-condition": "error",
+ "typescript/no-unnecessary-type-assertion": "error",
+ "typescript/no-unnecessary-type-parameters": "error",
+ "typescript/no-unnecessary-boolean-literal-compare": "error",
+ "typescript/no-unnecessary-template-expression": "error",
+ "typescript/no-unnecessary-type-arguments": "error",
+ "typescript/prefer-optional-chain": "error",
+ "typescript/prefer-for-of": "error",
+ "import/no-cycle": "error",
+ "import/no-self-import": "error",
+ "import/no-duplicates": "error",
+ "import/no-mutable-exports": "error",
+ "unicorn/no-instanceof-array": "error",
+ "unicorn/no-typeof-undefined": "error",
+ "unicorn/no-nested-ternary": "error",
+ "unicorn/no-useless-fallback-in-spread": "error",
+ "unicorn/no-length-as-slice-end": "error",
+ "unicorn/no-unnecessary-await": "error",
+ "unicorn/prefer-string-starts-ends-with": "error",
+ "unicorn/consistent-existence-index-check": "error",
+ "open-pencil/no-import-type-annotations": "error",
+ "open-pencil/no-math-random": "error",
+ "open-pencil/no-silent-catch": "error",
+ "open-pencil/no-deep-parent-relative-imports": "error",
+ "open-pencil/no-deep-parent-relative-paths": "error",
+ "open-pencil/no-broad-double-cast": "error",
+ "open-pencil/no-unknown-record-double-cast": "error",
+ "open-pencil/no-broad-unknown-type-assertions": "error",
+ "open-pencil/no-duplicate-type-shapes": "error",
+ "open-pencil/no-ts-suppression-comments": "error",
+ "open-pencil/no-reflect-delete-global-this-outside-tests": "error",
+ "open-pencil/no-function-alias-imports": "error",
+ "open-pencil/no-mixed-case-acronym-identifiers": "error",
+ "open-pencil/no-conditional-object-spreads": "error",
+ "open-pencil/no-sibling-domain-prefixed-files": "error",
+ "array-callback-return": "error",
+ "block-scoped-var": "error",
+ "default-case-last": "error",
+ "default-param-last": "error",
+ "guard-for-in": "error",
+ "no-array-constructor": "error",
+ "no-case-declarations": "error",
+ "no-caller": "error",
+ "no-constructor-return": "error",
+ "no-else-return": "error",
+ "no-empty-pattern": "error",
+ "no-eval": "error",
+ "no-extend-native": "error",
+ "no-extra-bind": "error",
+ "no-extra-label": "error",
+ "no-implied-eval": "error",
+ "no-iterator": "error",
+ "no-labels": "error",
+ "no-lone-blocks": "error",
+ "no-multi-str": "error",
+ "no-new": "error",
+ "no-new-wrappers": "error",
+ "no-object-constructor": "error",
+ "no-proto": "error",
+ "no-return-assign": "error",
+ "no-script-url": "error",
+ "no-self-compare": "error",
+ "no-sequences": "error",
+ "no-template-curly-in-string": "error",
+ "no-unmodified-loop-condition": "error",
+ "no-unneeded-ternary": "error",
+ "no-unused-expressions": "error",
+ "no-useless-assignment": "error",
+ "no-useless-call": "error",
+ "no-useless-computed-key": "error",
+ "no-useless-concat": "error",
+ "no-useless-constructor": "error",
+ "no-useless-rename": "error",
+ "no-useless-return": "error",
+ "prefer-numeric-literals": "error",
+ "prefer-object-has-own": "error",
+ "prefer-promise-reject-errors": "error",
+ "prefer-regex-literals": "error",
+ "prefer-rest-params": "error",
+ "prefer-spread": "error",
+ "symbol-description": "error",
+ "unicode-bom": "error",
+ "yoda": "error",
+ "typescript/adjacent-overload-signatures": "error",
+ "typescript/await-thenable": "error",
+ "typescript/ban-ts-comment": "error",
+ "typescript/ban-tslint-comment": "error",
+ "typescript/no-array-delete": "error",
+ "typescript/no-base-to-string": "error",
+ "typescript/no-confusing-non-null-assertion": "error",
+ "typescript/no-duplicate-enum-values": "error",
+ "typescript/no-duplicate-type-constituents": "error",
+ "typescript/no-extraneous-class": "error",
+ "typescript/no-extra-non-null-assertion": "error",
+ "typescript/no-for-in-array": "error",
+ "typescript/no-implied-eval": "error",
+ "typescript/no-invalid-void-type": "error",
+ "typescript/no-meaningless-void-operator": "error",
+ "typescript/no-misused-new": "error",
+ "typescript/no-misused-spread": "error",
+ "typescript/no-mixed-enums": "error",
+ "typescript/no-non-null-asserted-nullish-coalescing": "error",
+ "typescript/no-non-null-asserted-optional-chain": "error",
+ "typescript/no-redundant-type-constituents": "error",
+ "typescript/no-this-alias": "error",
+ "typescript/no-unnecessary-parameter-property-assignment": "error",
+ "typescript/no-unnecessary-qualifier": "error",
+ "typescript/no-unnecessary-type-constraint": "error",
+ "typescript/no-unsafe-enum-comparison": "error",
+ "typescript/no-unsafe-function-type": "error",
+ "typescript/no-unsafe-unary-minus": "error",
+ "typescript/no-useless-default-assignment": "error",
+ "typescript/no-useless-empty-export": "error",
+ "typescript/no-var-requires": "error",
+ "typescript/no-wrapper-object-types": "error",
+ "typescript/only-throw-error": "error",
+ "typescript/prefer-as-const": "error",
+ "typescript/prefer-find": "error",
+ "typescript/prefer-function-type": "error",
+ "typescript/prefer-promise-reject-errors": "error",
+ "typescript/prefer-reduce-type-parameter": "error",
+ "typescript/prefer-return-this-type": "error",
+ "typescript/prefer-ts-expect-error": "error",
+ "typescript/require-array-sort-compare": "error",
+ "typescript/triple-slash-reference": "error",
+ "import/no-absolute-path": "error",
+ "import/no-amd": "error",
+ "import/no-commonjs": "error",
+ "import/no-dynamic-require": "error",
+ "import/no-empty-named-blocks": "error",
+ "import/no-webpack-loader-syntax": "error",
+ "promise/always-return": "error",
+ "promise/catch-or-return": "error",
+ "promise/no-callback-in-promise": "error",
+ "promise/no-multiple-resolved": "error",
+ "promise/no-new-statics": "error",
+ "promise/no-promise-in-callback": "error",
+ "promise/no-return-in-finally": "error",
+ "promise/no-return-wrap": "error",
+ "promise/valid-params": "error",
+ "node/no-exports-assign": "error",
+ "node/no-new-require": "error",
+ "node/no-path-concat": "error",
+ "oxc/approx-constant": "error",
+ "oxc/missing-throw": "error",
+ "oxc/no-accumulating-spread": "error",
+ "oxc/no-async-endpoint-handlers": "error",
+ "oxc/no-map-spread": "error",
+ "oxc/number-arg-out-of-range": "error",
+ "oxc/uninvoked-array-callback": "error",
+ "unicorn/consistent-assert": "error",
+ "unicorn/consistent-date-clone": "error",
+ "unicorn/consistent-empty-array-spread": "error",
+ "unicorn/consistent-template-literal-escape": "error",
+ "unicorn/custom-error-definition": "error",
+ "unicorn/error-message": "error",
+ "unicorn/new-for-builtins": "error",
+ "unicorn/no-abusive-eslint-disable": "error",
+ "unicorn/no-accessor-recursion": "error",
+ "unicorn/no-anonymous-default-export": "error",
+ "unicorn/no-array-method-this-argument": "error",
+ "unicorn/no-await-in-promise-methods": "error",
+ "unicorn/no-console-spaces": "error",
+ "unicorn/no-document-cookie": "error",
+ "unicorn/no-empty-file": "error",
+ "unicorn/no-instanceof-builtins": "error",
+ "unicorn/no-invalid-fetch-options": "error",
+ "unicorn/no-invalid-remove-event-listener": "error",
+ "unicorn/no-magic-array-flat-depth": "error",
+ "unicorn/no-negation-in-equality-check": "error",
+ "unicorn/no-new-array": "error",
+ "unicorn/no-new-buffer": "error",
+ "unicorn/no-single-promise-in-promise-methods": "error",
+ "unicorn/no-static-only-class": "error",
+ "unicorn/no-thenable": "error",
+ "unicorn/no-this-assignment": "error",
+ "unicorn/no-unnecessary-array-flat-depth": "error",
+ "unicorn/no-unnecessary-array-splice-count": "error",
+ "unicorn/no-unnecessary-slice-end": "error",
+ "unicorn/no-unreadable-iife": "error",
+ "unicorn/no-useless-collection-argument": "error",
+ "unicorn/no-useless-error-capture-stack-trace": "error",
+ "unicorn/no-useless-iterator-to-array": "error",
+ "unicorn/no-useless-length-check": "error",
+ "unicorn/no-useless-promise-resolve-reject": "error",
+ "unicorn/no-useless-spread": "error",
+ "unicorn/no-useless-switch-case": "error",
+ "unicorn/prefer-array-find": "error",
+ "unicorn/prefer-array-flat": "error",
+ "unicorn/prefer-array-flat-map": "error",
+ "unicorn/prefer-array-index-of": "error",
+ "unicorn/prefer-array-some": "error",
+ "unicorn/prefer-blob-reading-methods": "error",
+ "unicorn/prefer-classlist-toggle": "error",
+ "unicorn/prefer-date-now": "error",
+ "unicorn/prefer-event-target": "error",
+ "unicorn/prefer-keyboard-event-key": "error",
+ "unicorn/prefer-modern-dom-apis": "error",
+ "unicorn/prefer-negative-index": "error",
+ "unicorn/prefer-native-coercion-functions": "error",
+ "unicorn/prefer-object-from-entries": "error",
+ "unicorn/prefer-optional-catch-binding": "error",
+ "unicorn/prefer-prototype-methods": "error",
+ "unicorn/prefer-regexp-test": "error",
+ "unicorn/prefer-set-size": "error",
+ "unicorn/prefer-string-slice": "error",
+ "unicorn/prefer-string-trim-start-end": "error",
+ "unicorn/prefer-structured-clone": "error",
+ "unicorn/prefer-type-error": "error",
+ "unicorn/require-array-join-separator": "error",
+ "unicorn/require-number-to-fixed-digits-argument": "error",
+ "unicorn/throw-new-error": "error",
+ "unicorn/require-post-message-target-origin": "error",
+ "unicorn/prefer-set-has": "error",
+ "unicorn/prefer-modern-math-apis": "error",
+ "unicorn/prefer-node-protocol": "error",
+ "unicorn/prefer-number-properties": "error",
+ "prefer-exponentiation-operator": "error",
+ "no-promise-executor-return": "error",
+ "typescript/no-empty-object-type": "error",
+ "typescript/return-await": "error",
+ "typescript/restrict-plus-operands": "error",
+ "unicorn/prefer-includes": "error",
+ "no-loop-func": "error",
+ "typescript/no-dynamic-delete": "error",
+ "open-pencil/no-hand-rolled-base64": "error",
+ "open-pencil/prefer-es-toolkit": "error",
+ "open-pencil/no-module-mocking": "error",
+ "open-pencil/no-reduce-accumulator-copy": "error",
+ "open-pencil/no-widen-then-assert": "error",
+ "open-pencil/no-unvalidated-json-parse": "error",
+ "open-pencil/valibot-schema-conventions": "error",
+ "open-pencil/no-useless-pass-through-wrappers": "error",
+ "open-pencil/no-secret-in-query": "error",
+ "open-pencil/no-secret-logging": "error",
+ "open-pencil/no-function-type": "error"
+ }
+}
diff --git a/packages/oxlint-plugin/src/recommended.ts b/packages/oxlint-plugin/src/recommended.ts
new file mode 100644
index 000000000..55f6fdeed
--- /dev/null
+++ b/packages/oxlint-plugin/src/recommended.ts
@@ -0,0 +1,12 @@
+import type { OxlintConfig } from 'oxlint'
+
+// Typed by recommended.d.json.ts.
+import config from '../recommended.json' with { type: 'json' }
+
+/**
+ * The configuration OpenPencil's repositories extend, for `oxlint.config.ts`. It does not load the
+ * plugin; add `jsPlugins: ['@open-pencil/oxlint-plugin']` beside it.
+ */
+const recommended: OxlintConfig = config
+
+export default recommended
diff --git a/packages/oxlint-plugin/tests/helpers/lint.ts b/packages/oxlint-plugin/tests/helpers/lint.ts
index cb567a61c..cdd9ab8df 100644
--- a/packages/oxlint-plugin/tests/helpers/lint.ts
+++ b/packages/oxlint-plugin/tests/helpers/lint.ts
@@ -48,35 +48,44 @@ export async function lintFiles(
return sourcePath
})
)
- const configPath = join(directory, 'oxlint.json')
- await writeFile(
- configPath,
- JSON.stringify({ plugins: ['typescript'], jsPlugins: [PLUGIN], rules })
- )
- const child = Bun.spawn([OXLINT, '-c', configPath, '--format', 'json', ...sourcePaths], {
- cwd: directory,
- stdout: 'pipe',
- stderr: 'pipe'
- })
- const [stdout, stderr, code] = await Promise.all([
- new Response(child.stdout).text(),
- new Response(child.stderr).text(),
- child.exited
- ])
- if (code !== 0 && code !== 1) throw new Error(`Oxlint exited ${code}: ${stderr}`)
- const { diagnostics } = v.parse(resultSchema, stdout)
- const parserFailure = diagnostics.find(
- (item) => item.severity === 'error' && item.code === undefined
- )
- if (parserFailure) {
- throw new Error(`Oxlint could not parse the fixture: ${parserFailure.message}`)
- }
- return diagnostics
+ return await lintWithConfig({ plugins: ['typescript'], rules }, directory, sourcePaths)
} finally {
await rm(directory, { recursive: true, force: true })
}
}
+/**
+ * Run Oxlint over files with a configuration written into `directory`, adding this plugin from
+ * source.
+ */
+export async function lintWithConfig(
+ config: Record<string, unknown>,
+ directory: string,
+ files: string[]
+): Promise<Diagnostic[]> {
+ const configPath = join(directory, 'oxlint.json')
+ await writeFile(configPath, JSON.stringify({ ...config, jsPlugins: [PLUGIN] }))
+ const child = Bun.spawn([OXLINT, '-c', configPath, '--format', 'json', ...files], {
+ cwd: directory,
+ stdout: 'pipe',
+ stderr: 'pipe'
+ })
+ const [stdout, stderr, code] = await Promise.all([
+ new Response(child.stdout).text(),
+ new Response(child.stderr).text(),
+ child.exited
+ ])
+ if (code !== 0 && code !== 1) throw new Error(`Oxlint exited ${code}: ${stderr}`)
+ const { diagnostics } = v.parse(resultSchema, stdout)
+ const parserFailure = diagnostics.find(
+ (item) => item.severity === 'error' && item.code === undefined
+ )
+ if (parserFailure) {
+ throw new Error(`Oxlint could not parse the fixture: ${parserFailure.message}`)
+ }
+ return diagnostics
+}
+
export function ruleDiagnostics(diagnostics: Diagnostic[], rule: string): Diagnostic[] {
return diagnostics.filter((diagnostic) => diagnostic.code === `open-pencil(${rule})`)
}
diff --git a/packages/oxlint-plugin/tests/recommended.test.ts b/packages/oxlint-plugin/tests/recommended.test.ts
new file mode 100644
index 000000000..e222c376e
--- /dev/null
+++ b/packages/oxlint-plugin/tests/recommended.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, test } from 'bun:test'
+import { mkdtemp, rm, writeFile } from 'node:fs/promises'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import { lintWithConfig } from '#oxlint-plugin-tests/helpers/lint'
+import plugin from '#oxlint-plugin/index'
+import recommended from '#oxlint-plugin/recommended'
+import * as v from 'valibot'
+
+/** The file JSON configurations extend by path. */
+const PRESET = fileURLToPath(new URL('../recommended.json', import.meta.url))
+const presetSchema = v.pipe(
+ v.string(),
+ v.parseJson(),
+ v.looseObject({ plugins: v.array(v.string()), rules: v.record(v.string(), v.unknown()) })
+)
+/** Rules that fit only some code, which a project turns on where they apply. */
+const OPT_IN = new Set(['no-dynamic-html', 'no-raw-sql'])
+
+async function preset() {
+ return v.parse(presetSchema, await Bun.file(PRESET).text())
+}
+
+describe('recommended', () => {
+ test('turns on every plugin rule but the opt-in ones, and only rules the plugin has', async () => {
+ const { rules } = await preset()
+ const pluginRules = Object.keys(plugin.rules)
+ const enabled = Object.keys(rules)
+ .filter((rule) => rule.startsWith('open-pencil/'))
+ .map((rule) => rule.slice('open-pencil/'.length))
+ expect(enabled.toSorted()).toEqual(pluginRules.filter((rule) => !OPT_IN.has(rule)).toSorted())
+ })
+
+ test('the module export is the JSON file', async () => {
+ const exported: unknown = recommended
+ expect(exported).toEqual(await preset())
+ })
+
+ test('Oxlint accepts it with the plugin and reports built-in and plugin rules', async () => {
+ const directory = await mkdtemp(join(tmpdir(), 'open-pencil-oxlint-recommended-'))
+ try {
+ const fixture = join(directory, 'fixture.ts')
+ await writeFile(
+ fixture,
+ 'export function f(x: number) {\n try { if (x == 1) run() } catch {}\n}\n'
+ )
+ const codes = (await lintWithConfig({ extends: [PRESET] }, directory, [fixture])).map(
+ (diagnostic) => diagnostic.code
+ )
+ expect(codes).toContain('eslint(eqeqeq)')
+ expect(codes).toContain('open-pencil(no-silent-catch)')
+ } finally {
+ await rm(directory, { recursive: true, force: true })
+ }
+ })
+})
diff --git a/packages/oxlint-plugin/tsconfig.json b/packages/oxlint-plugin/tsconfig.json
index a9bfaf699..f6feff5a2 100644
--- a/packages/oxlint-plugin/tsconfig.json
+++ b/packages/oxlint-plugin/tsconfig.json
@@ -11,12 +11,14 @@
"declarationMap": true,
"outDir": "./dist",
"skipLibCheck": true,
+ "resolveJsonModule": true,
+ "allowArbitraryExtensions": true,
"types": ["bun"],
"paths": {
"#oxlint-plugin/*": ["./src/*"],
"#oxlint-plugin-tests/*": ["./tests/*"]
}
},
- "include": ["src/**/*.ts", "tests/**/*.ts"],
+ "include": ["src/**/*.ts", "tests/**/*.ts", "recommended.d.json.ts"],
"exclude": ["node_modules", "dist"]
}
diff --git a/packages/oxlint-plugin/tsdown.config.ts b/packages/oxlint-plugin/tsdown.config.ts
index a76e67c4b..a826eceec 100644
--- a/packages/oxlint-plugin/tsdown.config.ts
+++ b/packages/oxlint-plugin/tsdown.config.ts
@@ -2,7 +2,8 @@ import { defineConfig } from 'tsdown'
export default defineConfig({
entry: {
- index: './src/index.ts'
+ index: './src/index.ts',
+ recommended: './src/recommended.ts'
},
platform: 'neutral',
format: ['esm'],
diff --git a/tools/checks/package-quality/src/smoke/scenarios.ts b/tools/checks/package-quality/src/smoke/scenarios.ts
index 2f56523d7..8a5cd8c11 100644
--- a/tools/checks/package-quality/src/smoke/scenarios.ts
+++ b/tools/checks/package-quality/src/smoke/scenarios.ts
@@ -68,6 +68,10 @@ export const runtimeScenarios: RuntimeScenario[] = [
name: 'Oxlint plugin',
code: "const { default: plugin } = await import('@open-pencil/oxlint-plugin'); if (plugin.meta.name !== 'open-pencil' || Object.keys(plugin.rules).length < 28 || !plugin.rules['no-unvalidated-json-parse']?.meta) throw new Error('Oxlint plugin smoke failed')"
},
+ {
+ name: 'Oxlint recommended configuration',
+ code: "const { default: preset } = await import('@open-pencil/oxlint-plugin/recommended'); if (preset.rules['open-pencil/no-silent-catch'] !== 'error' || !preset.plugins.includes('typescript')) throw new Error('Oxlint recommended configuration smoke failed')"
+ },
{
name: 'Cloud contract',
code: "const { CLOUD_AI_TOKEN_AUDIENCE, aiWalletSchema } = await import('@open-pencil/cloud/contract'); const { safeParse } = await import('valibot'); if (CLOUD_AI_TOKEN_AUDIENCE !== 'openpencil-ai' || !safeParse(aiWalletSchema, { balance: 5, buckets: [] }).success) throw new Error('Cloud contract smoke failed')"