Skip to content

chore: jscpd が見つける重複をまとめる - #186

Merged
isamu merged 1 commit into
mainfrom
chore/jscpd-duplicates
Oct 21, 2026
Merged

isamu merged 1 commit into
mainfrom
chore/jscpd-duplicates

Conversation

@isamu

@isamu isamu commented Oct 21, 2026

Copy link
Copy Markdown
Member

Summary

Folds every repeated block that jscpd finds (with scoria's settings) into a shared function. After this, jscpd finds no repeated code.

src (behaviour unchanged):

  • statistical-analysis.ts:
    • rankedHandler (range, k) is exported, and descriptive.ts uses it instead of its own copy, rangeAndNumber.
    • New rankingHandler(rule): a factory for the (number, ref, [order]) argument pattern. RANK uses it, and so does descriptive.ts's RANK.AVG.
  • nameBinding.ts: endOfBracket and nextLambda both had their own loop that scans text while skipping quoted strings. Both now call one shared findOutsideQuotes.

tests (new files under tests/engine/):

  • formulaAnswers.ts, with four helpers:
    • formulaValue: what a formula answers alone in A1;
    • valueBelow: what a formula answers placed under the data;
    • spilledBeside: what a formula placed beside the data spills;
    • rowMajorCells: the coordinates of a block, one row after another.
  • formulaColumns.ts: new valuesBesideCells, for data cells down column A with formulas down column B.
  • closeness.ts (relative and absolute closeness checks) and referenceFixture.ts (reading { cases } from a fixture).
  • seededRandom.ts: new lcgRandom, the old LCG stream, so the same seed produces the same sequence.
  • scriptRunner.ts: the tsx scripts' test / summary / expect. The PV sheet's data moves into test-utils.ts.
  • Two pairs of tests in one file that differed only in their input now share one helper: test_customFunctions, which checks a function body that does not compile, and test_crossSheetReference, which checks reference cycles across sheets.

Items to Confirm

  • src behaviour is unchanged. origin/main and this branch were run side by side and compared:
    • over every formula in the tests (corpusdiff.mts): identical;
    • over generated inputs: RANK, RANK.EQ, RANK.AVG, PERCENTRANK, LARGE and SMALL, plus LAMBDA and LET with quotes and brackets inside strings — identical.
  • The tests still catch breakage. Each new helper was broken in turn (wrong slice position, wrong row, coordinates swapped, the formula not placed, the wrong column read), and the tests that use it went red every time. The script runner exits 1 when a test fails.
  • Small behaviour changes in tests:
    • referenceCases now also fails when a fixture has no cases (only test_regression checked that before).
    • The closeness message now includes the size of the error.
  • yarn lint, yarn typecheck, yarn build, yarn test, yarn test:engine, run-all-fixtures.ts, test:calculator, test:evaluator, test:functions and test:scripts all pass. oxlint run with scoria's settings reports nothing.

User Prompt

🤖 Generated with Claude Code

work in GUIChatPluginSpreadsheet

src: LARGE/SMALL-style and RANK-style handlers come from one factory each, and nameBinding's two
quote-skipping scans share findOutsideQuotes. tests: the small sheets, closeness checks, fixture
reading, LCG stream, script runner and PV sheet each live in one file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isamu

isamu commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

CODEX VERDICT: LGTM

Read commit c9408d2612b3c90812f1258ef405ebd2073f673a.

Axis Result
correctness and edge cases none
security (injection / path traversal / code evaluation) none
tests: does a test go red if the new behaviour breaks none
API / schema / wire / on-disk compatibility none
consistency with the rest of the codebase none
i18n lockstep (src/lang, 8 locales) none
TIER C: source behavior preservation and touched test-helper behavior none
source behavior preservation: rankedHandler, rankingHandler, and findOutsideQuotes none
test helpers: layouts, reads, tolerances, fixtures, vacuity, and LCG sequence none
script runner: output, exit codes, printErrors, and expect semantics none
supplied differential: coverage of the source changes none; the supplied corpusdiff.mts covers formula-level paths, but I could not rerun it here because .old/src/engine/index.ts is absent

Verification: yarn typecheck passed; yarn test:engine passed with 2,216 tests; targeted descriptive/statistical/custom-function/cross-sheet tests passed; git diff --check passed.

FINDINGS COMPLETE: I read every hunk of the diff and this is every finding I have.

@isamu
isamu merged commit 17acd64 into main Oct 21, 2026
17 checks passed
@isamu
isamu deleted the chore/jscpd-duplicates branch October 21, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant