Files
Cloudnyco ae22335cfe feedback7: the battle sim uses engine-independent math — Chrome, Firefox, Safari and the server agree bit for bit (PR #373 by @Cloudnyco)
- server/sim/detmath.js: hypot (sqrt of the squares, rescaled outside 2^±500), powi (integer powers in double-double,
  one rounding), sin / cos (fdlibm 5.3) and atan2 (fdlibm / FreeBSD msun) built only from correctly rounded IEEE
  operations; the sim's Math.hypot / sin / cos / atan2 / pow calls go through it (65 files); eslint.config.js forbids
  the approximated Math functions under server/sim and test/sim/detmath.test.js scans for them.
- sin / cos / atan2 are the algorithms V8 runs in Node, so the server's results stay; only hypot differs from V8's.
  Golden: 2 moved — diy-027 (a hypot distance, damage +80) and coop3-ABYSS-5 (a later card pick from round 9, same end).
- Applied unchanged after review (Grok static review: MERGE; the diff read in full: no network, no new dependency).
- Tests: broad node --test 5155 / 5155 with the new file tracked (detmath 7 / 7, package 10 / 10); lint 0 errors,
  typecheck, check:imports.
2026-10-08 18:35:55 +08:00

112 lines
4.0 KiB
JavaScript

// Correctness lint only (npm run lint). No formatter, no stylistic rules, no repo-wide reformat.
//
// Node: server, shared, tools, scripts, types.
// Browser: public/js (also loaded under Node by unit tests, so `process` is a known global).
// Tests: Node globals plus browser globals (page.evaluate callbacks).
// Warnings (unused vars, and a few rules that fire on intentional patterns) do not fail the run.
// `npm run lint` does not pass --max-warnings=0.
import js from '@eslint/js';
import globals from 'globals';
const unused = ['warn', {
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
}];
// eslint:recommended, with the style-adjacent rules turned down. Empty `catch { }` is how this
// code skips a missing file; `no-useless-escape` / `no-extra-boolean-cast` / `no-regex-spaces`
// only complain about how a correct expression is written.
const rules = {
...js.configs.recommended.rules,
'no-unused-vars': unused,
'no-empty': ['warn', { allowEmptyCatch: true }],
'no-useless-escape': 'off',
'no-extra-boolean-cast': 'off',
'no-regex-spaces': 'off',
// `while (true)` is a normal loop. A constant condition anywhere else still warns.
'no-constant-condition': ['warn', { checkLoops: false }],
// Calling hasOwnProperty on a foreign object is a real footgun, but a lot of call sites are
// plain data. Warn; do not fail the build on them.
'no-prototype-builtins': 'warn',
// Redundant initializers (`let x = 0; x = …`) are common here and are not behavior bugs.
'no-useless-assignment': 'warn',
// Name sanitizers intentionally match control characters.
'no-control-regex': 'off',
// ESLint 10 wants `error.cause`. The two hits already put the original message in the text.
'preserve-caught-error': 'warn',
};
// ECMA-262 §21.3.2: the Math functions whose results are "implementation-approximated".
const APPROXIMATED_MATH = ['acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'atan2', 'cbrt', 'cos', 'cosh', 'exp',
'expm1', 'hypot', 'log', 'log1p', 'log10', 'log2', 'pow', 'sin', 'sinh', 'tan', 'tanh'];
const nodeFiles = [
'server/**/*.js',
'shared/**/*.js',
'tools/**/*.js',
'tools/**/*.mjs',
'scripts/**/*.js',
'scripts/**/*.mjs',
'types/**/*.js',
];
export default [
{
ignores: [
'node_modules/**',
'public/vendor/**',
'public/assets/**',
'public/fonts/**',
'public/dev/**',
'.cache/**',
'coverage/**',
],
},
{
files: nodeFiles,
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: { ...globals.node },
},
rules,
},
{
files: ['public/js/**/*.js'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: { ...globals.browser, process: 'readonly' },
},
rules,
},
{
// The sim runs in every player's browser and on the server, and must give the same bits everywhere. ECMA-262
// leaves these Math functions (and **) implementation-approximated: engines differ in the last bits.
files: ['server/sim/**/*.js'],
rules: {
'no-restricted-properties': ['error', ...APPROXIMATED_MATH.map((property) => ({
object: 'Math', property, message: 'implementation-approximated (engines differ in the last bits): use server/sim/detmath.js',
}))],
'no-restricted-syntax': ['error',
{ selector: "BinaryExpression[operator='**']", message: 'implementation-approximated: use powi from server/sim/detmath.js' },
{ selector: "AssignmentExpression[operator='**=']", message: 'implementation-approximated: use powi from server/sim/detmath.js' },
],
},
},
{
// Node test runner, plus browser tests whose page.evaluate callbacks use DOM globals.
// PIXI is the page global those render tests read inside evaluate().
files: ['test/**/*.js'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: { ...globals.node, ...globals.browser, PIXI: 'readonly' },
},
rules,
},
];