Skip to content

Commit 8fa47c6

Browse files
authored
Merge pull request lichess-org#15997 from schlawg/ui-eslint-stylelint-formatting
UI eslint stylelint formatting
2 parents 6c30814 + eae1516 commit 8fa47c6

File tree

269 files changed

+2650
-2604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+2650
-2604
lines changed

.git-blame-ignore-revs

+3
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ f058dab0bfdfcf3f40d510526607e3e359354e54
6666

6767
# prettier upgrade from 3.0.x to 3.3.x
6868
f617815e0a3a2d96de9aca3a04d589c78cbd14e8
69+
70+
# eslint --fix
71+
35c26fbd9bc0895d0119e4e313003c220417d4bc

.prettierignore

+13-32
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1-
!.build
2-
/modules
3-
/app
4-
/project
5-
/local
6-
/pnpm-lock.yaml
7-
/public/css
8-
/public/piece-css
9-
/public/compiled
10-
/public/glyphs.json
11-
/public/javascripts/vendor
12-
/public/vendor
13-
/public/oops/429.html
14-
15-
/translation/dest
16-
17-
/dist/
18-
/ui/common/**/*.js
19-
/ui/common/**/*.d.ts
20-
/ui/game/**/*.js
21-
/ui/game/**/*.d.ts
22-
/ui/voice/@build/crowdv/*.json
23-
/ui/nvui/**/*.js
24-
/ui/nvui/**/*.d.ts
25-
/ui/puz/**/*.js
26-
/ui/puz/**/*.d.ts
27-
28-
*.min.js
1+
*
2+
!/package.json
3+
!/crowdin.yml
4+
!/eslint.config.mjs
5+
!/package.json
6+
!/pnpm-workspace.yaml
7+
!/.github/
8+
!/.github/**
9+
!/ui/
10+
!/ui/**
11+
*.ts
12+
dist/
2913
readme
30-
31-
/.bloop/
32-
/.bsp/
33-
/.metals/
14+
/ui/voice/@build/crowdv/*.json

bin/watch-format

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
cd "$(dirname "${BASH_SOURCE:-$0}")/.."
3+
4+
# onchange only has one action, so we need two of them to watch prettier and eslint in parallel.
5+
# this script avoids zombie processes by killing both when it exits.
6+
7+
pnpm onchange 'ui/**/*.scss' -- prettier --write {{file}} &
8+
PRETTIER_PID=$!
9+
10+
pnpm onchange 'ui/**/*.ts' -- eslint --fix {{file}} &
11+
ESLINT_PID=$!
12+
13+
trap "kill $PRETTIER_PID $ESLINT_PID" EXIT
14+
15+
wait

eslint.config.mjs

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import typescriptEslint from '@typescript-eslint/eslint-plugin';
2+
import stylisticEslint from '@stylistic/eslint-plugin';
23
import tsParser from '@typescript-eslint/parser';
34

45
export default [
56
{
67
files: ['**/*.ts'],
78
ignores: ['**/dist/**', '**/node_modules/**', '**/public/**'],
8-
plugins: { '@typescript-eslint': typescriptEslint },
9-
languageOptions: {
10-
parser: tsParser,
11-
ecmaVersion: 5,
12-
sourceType: 'module',
13-
},
14-
9+
plugins: { '@typescript-eslint': typescriptEslint, '@stylistic': stylisticEslint },
10+
languageOptions: { parser: tsParser, ecmaVersion: 5, sourceType: 'module' },
1511
rules: {
16-
'linebreak-style': ['error', 'unix'],
17-
'prefer-spread': 'off',
18-
'prefer-rest-params': 'off',
12+
'@stylistic/indent': ['error', 2],
13+
'@stylistic/quotes': ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
14+
'@stylistic/semi': ['error', 'always'],
15+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
16+
'@stylistic/object-curly-spacing': ['error', 'always'],
17+
'@stylistic/space-before-function-paren': ['error', 'never'],
18+
'@stylistic/max-len': [
19+
'warn',
20+
{
21+
code: 110,
22+
ignoreUrls: true,
23+
ignoreStrings: true,
24+
ignoreComments: true,
25+
ignoreTemplateLiterals: true,
26+
},
27+
],
28+
1929
'@typescript-eslint/no-empty-interface': 'off',
2030
'@typescript-eslint/explicit-module-boundary-types': 'off',
2131
'@typescript-eslint/no-empty-function': 'off',
@@ -24,22 +34,17 @@ export default [
2434
'@typescript-eslint/no-this-alias': 'off',
2535
'@typescript-eslint/no-unused-vars': [
2636
'warn',
27-
{
28-
varsIgnorePattern: '^_',
29-
argsIgnorePattern: '^_',
30-
caughtErrorsIgnorePattern: '^_',
31-
},
37+
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
3238
],
39+
40+
'linebreak-style': ['error', 'unix'],
41+
'prefer-spread': 'off',
42+
'prefer-rest-params': 'off',
3343
'no-duplicate-imports': 'error',
3444
'no-useless-escape': 'off',
3545
'no-var': 'warn',
3646
'no-async-promise-executor': 'warn',
37-
'no-constant-condition': [
38-
'warn',
39-
{
40-
checkLoops: false,
41-
},
42-
],
47+
'no-constant-condition': ['warn', { checkLoops: false }],
4348
'no-restricted-globals': [
4449
'error',
4550
'addEventListener',
@@ -200,7 +205,7 @@ export default [
200205
'scrollTo',
201206
'scrollX',
202207
'scrollY',
203-
//"self",
208+
//'self',
204209
'status',
205210
'statusbar',
206211
'stop',

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@types/web": "^0.0.158",
3232
"@typescript-eslint/eslint-plugin": "^8.3.0",
3333
"@typescript-eslint/parser": "^8.3.0",
34+
"@stylistic/eslint-plugin": "^2.7.2",
3435
"ab": "github:lichess-org/ab-stub",
3536
"chessground": "^9.1.1",
3637
"eslint": "^9.9.1",
@@ -40,9 +41,9 @@
4041
"typescript": "^5.5.4"
4142
},
4243
"scripts": {
43-
"format": "prettier --write --log-level warn .",
44-
"check-format": "prettier --check --log-level warn .",
45-
"watch-format": "onchange \"**/*\" -- prettier --write --log-level warn {{changed}}",
44+
"format": "prettier --write --log-level warn . && eslint --fix ui",
45+
"check-format": "prettier --check --log-level warn . && eslint ui",
46+
"watch-format": "bin/watch-format",
4647
"add-hooks": "git config --add core.hooksPath bin/git-hooks",
4748
"remove-hooks": "git config --unset core.hooksPath bin/git-hooks",
4849
"lint": "eslint ui",

pnpm-lock.yaml

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/.build/src/esbuild.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function esbuild(tsc?: Promise<void>): Promise<void> {
5858
const onEndPlugin = {
5959
name: 'onEnd',
6060
setup(build: es.PluginBuild) {
61-
build.onEnd(async (result: es.BuildResult) => {
61+
build.onEnd(async(result: es.BuildResult) => {
6262
for (const err of result.errors) esbuildMessage(err, true);
6363
for (const warn of result.warnings) esbuildMessage(warn);
6464
if (result.errors.length === 0) await jsManifest(result.metafile!);

ui/.build/src/monitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function startMonitor(mods: string[]): Promise<void> {
3636
esbuild(tsc());
3737
}, 2000);
3838
};
39-
const packageChange = async () => {
39+
const packageChange = async() => {
4040
if (env.rebuild) {
4141
clearTimeout(tscTimeout);
4242
clearTimeout(reinitTimeout);

ui/.build/src/sass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function compile(sources: string[], logAll = true) {
8181
const txts = lines(buf.toString('utf8'));
8282
for (const txt of txts) env.log(c.red(txt), { ctx: 'sass' });
8383
});
84-
sassPs.on('close', async (code: number) => {
84+
sassPs.on('close', async(code: number) => {
8585
if (code !== 0) return env.done(code, 'sass');
8686
if (awaitingFullBuild && compile(await unbuiltSources()) > 0) return;
8787
awaitingFullBuild = false; // now we are ready to make manifests

ui/.build/src/tsc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function stopTsc(): void {
1414

1515
export async function tsc(): Promise<void> {
1616
return new Promise((resolve, reject) =>
17-
(async () => {
17+
(async() => {
1818
if (!env.tsc) return resolve();
1919

2020
const cfg: any = { files: [] };

ui/@types/lichess/tree.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ declare namespace Tree {
8888
by:
8989
| string
9090
| {
91-
id: string;
92-
name: string;
93-
};
91+
id: string;
92+
name: string;
93+
};
9494
text: string;
9595
}
9696

ui/analyse/src/autoShape.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function compute(ctrl: AnalyseCtrl): DrawShape[] {
9292
nCeval.pvs[1] &&
9393
!(ctrl.threatMode() && nThreat && nThreat.pvs.length > 2)
9494
) {
95-
nCeval.pvs.forEach(function (pv) {
95+
nCeval.pvs.forEach(function(pv) {
9696
if (pv.moves[0] === nextBest) return;
9797
const shift = winningChances.povDiff(color, nCeval.pvs[0], pv);
9898
if (shift >= 0 && shift < 0.2) {
@@ -111,7 +111,7 @@ export function compute(ctrl: AnalyseCtrl): DrawShape[] {
111111

112112
shapes = shapes.concat(makeShapesFromUci(rcolor, pv0.moves[0], pv1s.length > 0 ? 'paleRed' : 'red'));
113113

114-
pv1s.forEach(function (pv) {
114+
pv1s.forEach(function(pv) {
115115
const shift = winningChances.povDiff(rcolor, pv, pv0);
116116
if (shift >= 0 && shift < 0.2) {
117117
shapes = shapes.concat(

ui/analyse/src/boot.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AnalyseApi, AnalyseOpts } from './interfaces';
22
import StrongSocket from 'common/socket';
33

4-
export default function (start: (opts: AnalyseOpts) => AnalyseApi) {
5-
return function (cfg: AnalyseOpts) {
4+
export default function(start: (opts: AnalyseOpts) => AnalyseApi) {
5+
return function(cfg: AnalyseOpts) {
66
const socketUrl = `/watch/${cfg.data.game.id}/${cfg.data.player.color}/v6`;
77
site.socket = new StrongSocket(socketUrl, cfg.data.player.version, {
88
params: {

ui/analyse/src/control.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function exitVariation(ctrl: AnalyseCtrl): void {
1919
if (ctrl.onMainline) return;
2020
let found,
2121
path = treePath.root;
22-
ctrl.nodeList.slice(1, -1).forEach(function (n: Tree.Node) {
22+
ctrl.nodeList.slice(1, -1).forEach(function(n: Tree.Node) {
2323
path += n.id;
2424
if (n.children[1]) found = path;
2525
});

ui/analyse/src/crazy/crazyView.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const oKeys = ['pawn', 'knight', 'bishop', 'rook', 'queen'];
99

1010
type Position = 'top' | 'bottom';
1111

12-
export default function (ctrl: AnalyseCtrl, color: Color, position: Position) {
12+
export default function(ctrl: AnalyseCtrl, color: Color, position: Position) {
1313
if (!ctrl.node.crazy || ctrl.data.game.variant.key !== 'crazyhouse') return;
1414
const pocket = ctrl.node.crazy.pockets[color === 'white' ? 0 : 1];
1515
const dropped = ctrl.justDropped;

0 commit comments

Comments
 (0)