Skip to content

Commit

Permalink
Merge pull request #16688 from schlawg/ui-readd-lint-ci
Browse files Browse the repository at this point in the history
resume ci linting and move code style configs to ui
  • Loading branch information
ornicar authored Dec 29, 2024
2 parents 3dd1582 + afa449b commit 6c64687
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 86 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ jobs:
languages: javascript
- uses: github/codeql-action/analyze@v3
- run: pnpm install
- run: pnpm run lint
- run: pnpm run check-format
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/project/.bloop/
/conf/application.conf
/conf/version.conf
/conf/manifest.*
/translation/js
logs/
/project/metals.sbt
Expand All @@ -26,7 +25,6 @@ node_modules/
ui/common/css/theme/gen/*.scss
ui/.build/build
ui/voice/crowdv
ui/*/npm-debug.log
ui/*/tsconfig.tsbuildinfo
hs_*.log
dependency-graph.png
Expand Down Expand Up @@ -54,4 +52,4 @@ RUNNING_PID
/?

# eslint cache
/.eslintcache
/ui/.eslintcache
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
# format only these files at top level
!/package.json
!/crowdin.yml
!/eslint.config.mjs
!/pnpm-workspace.yaml

# format only these top level directories and their contents
!/.github/
!/.github/**
!/ui/
!/ui/**
!/bin/
!/bin/**

# ignore these patterns anywhere
dist/
Expand Down
8 changes: 4 additions & 4 deletions bin/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# the commit by .15s or so, which is annoying.
if \git --no-pager diff-index -z --name-only --no-renames --cached HEAD | \
\grep -qzE '\.(json|scss|ts)$'; then
# NOTE! grep must be kept in sync with lint-staged config (bin/lint-staged-config.mjs)
# NOTE! grep must be kept in sync with lint-staged config (ui/lint-staged-config.mjs)

BIN_DIR="$(dirname -- $0)/.."
LINT_STAGED="$BIN_DIR/../node_modules/.bin/lint-staged"
ROOT_DIR="$(dirname -- $0)/../.."
LINT_STAGED="$ROOT_DIR/node_modules/.bin/lint-staged"

# pnpm or npx adds .25s overhead. exec further reduces overhead.
if [ -x "$LINT_STAGED" ]; then
exec "$LINT_STAGED" --config "$BIN_DIR/lint-staged.config.mjs"
exec "$LINT_STAGED" --config "$ROOT_DIR/ui/lint-staged.config.mjs"
else
exec pnpm lint-staged
fi
Expand Down
5 changes: 4 additions & 1 deletion bin/mongodb/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ db.puzzle2_puzzle.createIndex({ day: 1 }, { partialFilterExpression: { day: { $e
db.puzzle2_puzzle.createIndex({ themes: 1, votes: -1 });
db.puzzle2_puzzle.createIndex({ themes: 1 });
db.puzzle2_puzzle.createIndex({ users: 1 });
db.puzzle2_puzzle.createIndex({ opening: 1, votes: -1 }, { partialFilterExpression: { opening: { $exists: 1 } } });
db.puzzle2_puzzle.createIndex(
{ opening: 1, votes: -1 },
{ partialFilterExpression: { opening: { $exists: 1 } } },
);
db.puzzle2_puzzle.createIndex({ tagMe: 1 }, { partialFilterExpression: { tagMe: true } });
db.puzzle2_path.createIndex({ min: 1, max: -1 });
64 changes: 37 additions & 27 deletions bin/mongodb/recap-notif.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ function reloadHasRecap() {
reloadHasRecap();
setInterval(reloadHasRecap, 1000 * 60 * 10);

const hasPuzzles = userId => db.user_perf.countDocuments({ _id: userId, 'puzzle.nb': { $gt: 0 } }, { limit: 1 });
const hasPuzzles = userId =>
db.user_perf.countDocuments({ _id: userId, 'puzzle.nb': { $gt: 0 } }, { limit: 1 });

// only keeps users that don't yet have a recap notification for the year
// and don't have yet loaded their recap from another link
const filterNewUsers = users => {
const noRecap = users.filter(u => !hasRecap.has(u._id));
const hasNotif = new Set(db.notify.distinct('notifies', {
notifies: { $in: noRecap.map(u => u._id) }, 'content.type': 'recap', 'content.year': year
}));
const hasNotif = new Set(
db.notify.distinct('notifies', {
notifies: { $in: noRecap.map(u => u._id) },
'content.type': 'recap',
'content.year': year,
}),
);
return noRecap.filter(u => !hasNotif.has(u._id));
}
};

function* group(size) {
let batch = [];
Expand All @@ -40,20 +45,21 @@ function* group(size) {
batch = [element];
}
}
};
}

function sendToUser(user) {
if (!user.count?.game && !hasPuzzles(user._id)) return;
if (!dry) db.notify.insertOne({
_id: Math.random().toString(36).substring(2, 10),
notifies: user._id,
content: {
type: 'recap',
year: NumberInt(year),
},
read: false,
createdAt: new Date(),
});
if (!dry)
db.notify.insertOne({
_id: Math.random().toString(36).substring(2, 10),
notifies: user._id,
content: {
type: 'recap',
year: NumberInt(year),
},
read: false,
createdAt: new Date(),
});
countSent++;
}

Expand All @@ -67,21 +73,25 @@ function sendToRandomOfflinePlayers() {
const newUsers = filterNewUsers(batch);
newUsers.forEach(sendToUser);
if (countAll % 1000 == 0) {
print(`+ ${countSent - lastPrinted} = ${countSent} / ${countAll} | ${user.createdAt.toLocaleDateString('fr')}`);
print(
`+ ${countSent - lastPrinted} = ${countSent} / ${countAll} | ${user.createdAt.toLocaleDateString('fr')}`,
);
lastPrinted = countSent;
}
sleep(10 * newUsers.length);
}
}
db.user4.find({
enabled: true,
createdAt: { $lt: new Date(year, 9, 1) },
seenAt: {
$gt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30 * 3),
// $lt: new Date(Date.now() - 1000 * 60 * 20) // avoid the lila notif cache!
},
marks: { $nin: ['boost', 'engine', 'troll'] }
}).forEach(process);
};
db.user4
.find({
enabled: true,
createdAt: { $lt: new Date(year, 9, 1) },
seenAt: {
$gt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30 * 3),
// $lt: new Date(Date.now() - 1000 * 60 * 20) // avoid the lila notif cache!
},
marks: { $nin: ['boost', 'engine', 'troll'] },
})
.forEach(process);
process(); // flush the generator
}

Expand Down
2 changes: 1 addition & 1 deletion bin/mongodb/relay-round-finishedAt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
db.relay.find({ finished: true, finishedAt: { $exists: false } }).forEach(function(relay) {
db.relay.find({ finished: true, finishedAt: { $exists: false } }).forEach(function (relay) {
print(relay.tourId + '/' + relay._id + ' ' + relay.name);
const actualStartsAt = relay.startsAt && relay.startsAt != 'afterPrevious' ? relay.startsAt : undefined;
const startAt = relay.startedAt || actualStartsAt || relay.createdAt;
Expand Down
24 changes: 15 additions & 9 deletions bin/mongodb/report-atom-reason-migration.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
db.report2.find({ reason: { $exists: 1 } }).sort({ $natural: -1 }).forEach(r => {
const sets = {};
r.atoms.forEach((_, i) => {
sets[`atoms.${i}.reason`] = r.reason;
db.report2
.find({ reason: { $exists: 1 } })
.sort({ $natural: -1 })
.forEach(r => {
const sets = {};
r.atoms.forEach((_, i) => {
sets[`atoms.${i}.reason`] = r.reason;
});
db.report2.updateOne(
{ _id: r._id },
{
$unset: { reason: 1 },
$set: sets,
},
);
});
db.report2.updateOne({ _id: r._id }, {
$unset: { reason: 1 },
$set: sets
});
});
25 changes: 12 additions & 13 deletions bin/mongodb/tournament-spotlight-icons.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
const replacements =
[
[7, ''], // atomic
[6, ''], // antichess
[2, ''], // chess960
[10, ''], // crazyhouse
[8, ''], // horde
[4, ''], // kingOfTheHill
[9, ''], // racingKings
[5, ''], // threeCheck
];
const replacements = [
[7, ''], // atomic
[6, ''], // antichess
[2, ''], // chess960
[10, ''], // crazyhouse
[8, ''], // horde
[4, ''], // kingOfTheHill
[9, ''], // racingKings
[5, ''], // threeCheck
];

replacements.forEach(([variantId, icon]) => {
print(variantId, icon);
const res = db.tournament2.updateMany(
{ 'spotlight.iconFont': { $exists: true }, variant: variantId },
{ $set: { 'spotlight.iconFont': icon } }
{ $set: { 'spotlight.iconFont': icon } },
);
print('done: ' + res.modifiedCount);
});

const res = db.tournament2.updateMany(
{ 'schedule.freq': 'shield', 'spotlight.iconFont': '' },
{ $set: { 'spotlight.iconFont': '' } }
{ $set: { 'spotlight.iconFont': '' } },
);
print('done: ' + res.modifiedCount);
31 changes: 15 additions & 16 deletions bin/mongodb/trophy-icons.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const replacements =
[
['wayOfBerserk', ''],
['marathonWinner', ''],
['marathonTopTen', ''],
['marathonTopFifty', ''],
['marathonTopHundred', ''],
['marathonSurvivor', ','],
['developer', ''],
['moderator', ''],
['verified', ''],
['marathonTopFivehundred', ''],
['contentTeam', ''],
['secAdvisor', ''],
['broadcastTeam', '']
];
const replacements = [
['wayOfBerserk', ''],
['marathonWinner', ''],
['marathonTopTen', ''],
['marathonTopFifty', ''],
['marathonTopHundred', ''],
['marathonSurvivor', ','],
['developer', ''],
['moderator', ''],
['verified', ''],
['marathonTopFivehundred', ''],
['contentTeam', ''],
['secAdvisor', ''],
['broadcastTeam', ''],
];

replacements.forEach(([kind, icon]) => {
print(kind, icon);
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@
"typescript above just to allow manual tsc. ui/.build/package.json's typesript version is the truth"
],
"scripts": {
"format": "prettier --cache --write --log-level warn .",
"check-format": "prettier --cache --check --log-level warn .",
"watch-format": "onchange \"**/*\" -- prettier --cache --write --log-level warn {{changed}}",
"add-hooks": "git config --add core.hooksPath bin/git-hooks",
"remove-hooks": "git config --unset core.hooksPath bin/git-hooks",
"lint": "eslint --cache",
"lint-staged": "lint-staged --config bin/lint-staged.config.mjs",
"format": "prettier --config=ui/.prettierrc.json --cache --write --log-level=warn .",
"check-format": "prettier --config=ui/.prettierrc.json --cache --check --log-level=warn .",
"watch-format": "onchange \"**/*\" -- prettier --config=ui/.prettierrc.json --cache --write --log-level=warn {{changed}}",
"add-hooks": "git config get --all core.hooksPath | grep -Fxq bin/git-hooks || git config set --append core.hooksPath bin/git-hooks",
"remove-hooks": "git config unset --value=bin/git-hooks core.hooksPath || true",
"lint": "eslint --config=ui/eslint.config.mjs --cache --cache-location=ui/.eslintcache",
"lint-staged": "lint-staged --config=ui/lint-staged.config.mjs",
"journal": "journalctl --user -fu lila -o cat",
"metals": "tail -F .metals/metals.log | stdbuf -oL cut -c 21- | rg -v '(notification for request|handleCancellation)'",
"serverlog": "pnpm journal & pnpm metals",
"piece-css": "pnpx tsx bin/gen/piece-css.ts",
"trans-dump": "pnpx tsx bin/trans-dump.ts",
"test": "vitest run -c ui/vitest.config.mts",
"test:watch": "vitest -c ui/vitest.config.mts",
"test": "vitest run --config=ui/vitest.config.mts",
"test:watch": "vitest --config=ui/vitest.config.mts",
"multilog": "pnpm serverlog & ui/build -w"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion eslint.config.mjs → ui/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import tsParser from '@typescript-eslint/parser';
export default [
{ ignores: ['*', '!ui/', '!bin/', '**/dist/'] },
{
files: ['**/*.ts'],
files: ['**/*.{ts,mts}'],
plugins: { '@typescript-eslint': typescriptEslint },
languageOptions: { parser: tsParser, ecmaVersion: 5, sourceType: 'module' },
rules: {
Expand Down
4 changes: 3 additions & 1 deletion bin/lint-staged.config.mjs → ui/lint-staged.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default {
// NOTE: these patterns must stay in sync with bin/git-hooks/pre-commit!
'*.{json,scss,ts}': files => {
const regularFiles = files.filter(f => !lstatSync(f).isSymbolicLink());
return regularFiles.length ? `prettier --write ${regularFiles.join(' ')}` : 'true';
return regularFiles.length
? `prettier --config=ui/.prettierrc.json --write ${regularFiles.join(' ')}`
: 'true';
},
};

0 comments on commit 6c64687

Please sign in to comment.