Skip to content

Commit 938c7ea

Browse files
committed
Update eslint: new configuration, stricter rules and javascript code
1 parent ce26030 commit 938c7ea

19 files changed

+98
-96
lines changed

.eslintrc.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

bun.lockb

-26 KB
Binary file not shown.

e2e/.eslintrc.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

e2e/cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig(
88
e2e: {
99
// supportFolder: "support",
1010
baseUrl: "http://0.0.0.0:8080",
11-
setupNodeEvents(on, config) {
11+
setupNodeEvents(on) {
1212
htmlvalidate.install(on, {
1313
rules: {
1414
// a few frameworks use improper elements to render various roles

e2e/cypress/support/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import "cypress-html-validate/dist/commands";
1717
import * as cypressSnapshots from "@cypress/snapshot";
1818
// @ts-expect-error: register does not exist
19-
cypressSnapshots.register();
19+
cypressSnapshots.register(); // eslint-disable-line @typescript-eslint/no-unsafe-call
2020
afterEach(() => cy.htmlvalidate());
2121
// Silence issue https://github.com/quasarframework/quasar/issues/2233#issuecomment-1006506083
2222
// Cypress issue (open) https://github.com/cypress-io/cypress/issues/20341

e2e/cypress/support/snapshots.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// add a minimal declaration file
22
declare module "@cypress/snapshot" {
33
global {
4-
// eslint-disable-next-line @typescript-eslint/no-namespace
54
namespace Cypress {
65
interface Chainable {
76
// Missing declaration from snapshots
@@ -10,4 +9,3 @@ declare module "@cypress/snapshot" {
109
}
1110
}
1211
}
13-

e2e/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"type": "module",
66
"devDependencies": {
77
"@cypress/snapshot": "^2.1.7",
8-
"@types/node": "20.14.0",
9-
"cypress": "13.10.0",
8+
"@types/node": "20.14.2",
9+
"cypress": "13.11.0",
1010
"cypress-html-validate": "6.1.0",
1111
"eslint-plugin-cypress": "3.3.0",
1212
"eslint-plugin-promise": "6.2.0",
1313
"html-validate": "8.20.0",
14-
"start-server-and-test": "2.0.3"
14+
"start-server-and-test": "2.0.4"
1515
},
1616
"scripts": {
1717
"lint-fix": "eslint --fix cypress --ext .ts"

e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["./cypress/**/*.ts"],
2+
"include": ["cypress/**/*.ts", "cypress.config.ts"],
33
"compilerOptions": {
44
"strict": true,
55
"target": "ESNext",

eslint.config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
import alignAssignments from 'eslint-plugin-align-assignments';
4+
import pluginCypress from 'eslint-plugin-cypress/flat'
5+
6+
export default tseslint.config(
7+
{
8+
// We lint only typescript sources and tests. Everything else is generated.
9+
files: ['src/pagy.ts', 'e2e/cypress/*.ts', 'e2e/cypress.config.ts'],
10+
extends: [
11+
eslint.configs.recommended,
12+
...tseslint.configs.recommended,
13+
...tseslint.configs.recommendedTypeChecked,
14+
...tseslint.configs.strict, // opinionated but ok for now
15+
],
16+
plugins: {
17+
alignAssignments: alignAssignments,
18+
'@typescript-eslint': tseslint.plugin,
19+
},
20+
languageOptions: {
21+
parser: tseslint.parser,
22+
parserOptions: {
23+
project: true,
24+
},
25+
},
26+
rules: {
27+
'alignAssignments/align-assignments': 'warn',
28+
'semi': ["warn", "always", {"omitLastInOneLineBlock": true}],
29+
'@typescript-eslint/array-type': 'error',
30+
'@typescript-eslint/consistent-type-imports': 'error',
31+
'@typescript-eslint/no-unsafe-argument': 'error',
32+
'@typescript-eslint/no-unsafe-assignment': 'error',
33+
'@typescript-eslint/no-unsafe-call': 'error',
34+
'@typescript-eslint/no-unsafe-member-access': 'error',
35+
'@typescript-eslint/no-unsafe-return': 'error',
36+
}
37+
},
38+
{
39+
files: ['e2e/cypress/*.ts', 'e2e/cypress.config.ts'],
40+
...pluginCypress.configs.recommended,
41+
rules: {
42+
'cypress/no-unnecessary-waiting': 'warn',
43+
'cypress/unsafe-to-chain-command': 'error',
44+
}
45+
}
46+
);

gem/javascripts/pagy-module.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const Pagy = (() => {
1313
let html = tokens.before;
1414
const series = sequels[width.toString()];
1515
const labels = labelSequels?.[width.toString()] ?? series.map((l) => l.toString());
16-
for (const i in series) {
17-
const item = series[i];
16+
series.forEach((item, i) => {
1817
const label = labels[i];
1918
let filled;
2019
if (typeof item === "number") {
@@ -25,7 +24,7 @@ const Pagy = (() => {
2524
filled = fillIn(tokens.current, item, label);
2625
}
2726
html += typeof trimParam === "string" && item == 1 ? trim(filled, trimParam) : filled;
28-
}
27+
});
2928
html += tokens.after;
3029
el.innerHTML = "";
3130
el.insertAdjacentHTML("afterbegin", html);
@@ -64,7 +63,7 @@ const Pagy = (() => {
6463
link.href = url;
6564
link.click();
6665
};
67-
["change", "focus"].forEach((e) => input.addEventListener(e, input.select));
66+
["change", "focus"].forEach((e) => input.addEventListener(e, () => input.select()));
6867
input.addEventListener("focusout", action);
6968
input.addEventListener("keypress", (e) => {
7069
if (e.key === "Enter") {

0 commit comments

Comments
 (0)