chore: port custom lint rules into local plugin + airbnb correctness set#55
Open
varin-nair-factory wants to merge 2 commits into
Open
chore: port custom lint rules into local plugin + airbnb correctness set#55varin-nair-factory wants to merge 2 commits into
varin-nair-factory wants to merge 2 commits into
Conversation
Port the portable, non-custom, non-React rules from factory-mono-alpha's shared @factory/eslint-config into our ESLint 9 flat config, so the public SDK enforces the same standards as the internal source of truth. Added rules: no-empty-object-type (error), no-require-imports, no-barrel-files, import/no-default-export, import/named, import/no-extraneous-dependencies, import/extensions, eslint-comments/no-unused-disable, no-void, default-case, no-constant-condition, no-param-reassign, no-promise-executor-return, prefer-promise-reject-errors, prefer-arrow-callback, no-restricted-syntax (incl. ExportAllDeclaration ban), and vitest/expect-expect + valid-expect for tests. Excluded the monorepo's factory/* custom-plugin rules (not installable from npm) and React/Next rules (no React here). Refactored to comply: deleted the unused src/protocol/index.ts export* barrel and converted src/index.ts to explicit named re-exports. Public-API barrels are exempted from no-barrel-files (matching the monorepo's index.ts exemption). Fixed all resulting violations. New devDeps: eslint-plugin-no-barrel-files, eslint-plugin-eslint-comments, @vitest/eslint-plugin. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
…ess set Ports 5 self-contained custom ESLint rules from the private monorepo into a local plugin (eslint-rules/) so the public SDK becomes the source of truth for them (Phase 1). Rules authored in CJS so the monorepo can later consume them and drop its copies (Phase 2). Rules ported (ESLint 9-modernized: context.filename / context.sourceCode): - no-shell-injection, no-unsafe-json-parse (error) - vi-mock-absolute-paths, no-unstable-mock-module, vi-mock-import-actual (tests) Enabled no-unsafe-json-parse as error (off-by-default upstream): caught a real bug in src/api.ts where the response body was discarded on JSON parse failure; now reads text first and surfaces rawBody in the error. Added airbnb correctness rules: eqeqeq(smart), no-throw-literal, array-callback-return, @typescript-eslint/no-unused-expressions, @typescript-eslint/no-shadow. Deferred: require-test-files and test-imports-source (assume colocated tests; this repo uses a separate tests/ dir). Verified: lint, typecheck, typecheck:examples, format, 911 tests all pass. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Ports 5 self-contained custom ESLint rules from the private
factory-mono-alphamonorepo into a local plugin (eslint-rules/), making the public SDK the source of truth for these rules. This is Phase 1 of the same source-of-truth strategy we applied to the protocol schemas.Rules are authored in CommonJS (
.cjs, since this repo is ESM) so they work in both ESLint 8 (monorepo) and ESLint 9 (here). In Phase 2 (separate follow-up), the monorepo eslint plugin can import these rules from the published package and delete its local copies — requires the monorepo to consume the public package first.Rules ported
Modernized for ESLint 9 (
context.filename/context.sourceCodewith fallbacks):local/no-shell-injectionlocal/no-unsafe-json-parselocal/vi-mock-absolute-pathslocal/no-unstable-mock-modulelocal/vi-mock-import-actualno-unsafe-json-parseis off-by-default upstream (the monorepo is mid-migration); enabled here as error because the SDK core job is parsing untrusted JSON-RPC off the wire.Real bug found
no-unsafe-json-parseflaggedsrc/api.ts:factoryFetchdiscarded the response body on JSON parse failure, so non-JSON error responses (HTML error pages, gateway timeouts) surfaced as opaque errors. Fixed: read text first, thenJSON.parse, and includerawBodyin the error. Test mocks updated to provide.text().Airbnb correctness rules added (config-only)
eqeqeq(smart),no-throw-literal,array-callback-return,@typescript-eslint/no-unused-expressions,@typescript-eslint/no-shadow. Zero violations in existing code.Deferred
require-test-filesandtest-imports-sourceassume tests are colocated with source (src/foo.test.ts). This repo uses a separatetests/dir that does not map 1:1, so porting them needs a path-logic rewrite with false-positive risk — deferred to a focused follow-up.Verification
npm run lint— clean (0 errors)npm run typecheck— passnpm run typecheck:examples— passnpm run format:check— passnpm test— 911 passed / 911No
eslint-disableor per-file overrides added.Generated with Droid