Skip to content

Commit 08579d6

Browse files
authored
Add initial typescript config and use it for eslint,vitest,playwright (go-gitea#31186)
This enables eslint to use the typescript parser and resolver which brings some benefits that eslint rules now have type information available and a tsconfig.json is required for the upcoming typescript migration as well. Notable changes done: - Add typescript parser and resolver - Move the vue-specific config into the root file - Enable `vue-scoped-css/enforce-style-type` rule, there was only one violation and I added a inline disable there. - Fix new lint errors that were detected because of the parser change - Update `i/no-unresolved` to remove now-unnecessary workaround for the resolver - Disable `i/no-named-as-default` as it seems to raise bogus issues in the webpack config - Change vitest config to typescript - Change playwright config to typescript - Add `eslint-plugin-playwright` and fix issues - Add `tsc` linting to `make lint-js`
1 parent df805d6 commit 08579d6

15 files changed

+249
-66
lines changed

.eslintrc.yaml

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ ignorePatterns:
66
- /web_src/fomantic
77
- /public/assets/js
88

9+
parser: "@typescript-eslint/parser"
10+
911
parserOptions:
1012
sourceType: module
1113
ecmaVersion: latest
14+
project: true
15+
extraFileExtensions: [".vue"]
16+
17+
settings:
18+
import/extensions: [".js", ".ts"]
19+
import/parsers:
20+
"@typescript-eslint/parser": [".js", ".ts"]
21+
import/resolver:
22+
typescript: true
1223

1324
plugins:
1425
- "@eslint-community/eslint-plugin-eslint-comments"
@@ -103,6 +114,22 @@ overrides:
103114
- files: ["web_src/js/modules/fetch.js", "web_src/js/standalone/**/*"]
104115
rules:
105116
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]
117+
- files: ["**/*.vue"]
118+
plugins:
119+
- eslint-plugin-vue
120+
- eslint-plugin-vue-scoped-css
121+
extends:
122+
- plugin:vue/vue3-recommended
123+
- plugin:vue-scoped-css/vue3-recommended
124+
rules:
125+
vue/attributes-order: [0]
126+
vue/html-closing-bracket-spacing: [2, {startTag: never, endTag: never, selfClosingTag: never}]
127+
vue/max-attributes-per-line: [0]
128+
vue/singleline-html-element-content-newline: [0]
129+
- files: ["tests/e2e/**"]
130+
plugins:
131+
- eslint-plugin-playwright
132+
extends: plugin:playwright/recommended
106133

107134
rules:
108135
"@eslint-community/eslint-comments/disable-enable-pair": [2]
@@ -264,7 +291,7 @@ rules:
264291
i/no-internal-modules: [0]
265292
i/no-mutable-exports: [0]
266293
i/no-named-as-default-member: [0]
267-
i/no-named-as-default: [2]
294+
i/no-named-as-default: [0]
268295
i/no-named-default: [0]
269296
i/no-named-export: [0]
270297
i/no-namespace: [0]
@@ -274,7 +301,7 @@ rules:
274301
i/no-restricted-paths: [0]
275302
i/no-self-import: [2]
276303
i/no-unassigned-import: [0]
277-
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$", ^vitest/]}]
304+
i/no-unresolved: [2, {commonjs: true, ignore: ["\\?.+$"]}]
278305
i/no-unused-modules: [2, {unusedExports: true}]
279306
i/no-useless-path-segments: [2, {commonjs: true}]
280307
i/no-webpack-loader-syntax: [2]

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,13 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
375375

376376
.PHONY: lint-js
377377
lint-js: node_modules
378-
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES)
378+
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
379+
npx tsc
379380

380381
.PHONY: lint-js-fix
381382
lint-js-fix: node_modules
382-
npx eslint --color --max-warnings=0 --ext js,vue $(ESLINT_FILES) --fix
383+
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
384+
npx tsc
383385

384386
.PHONY: lint-css
385387
lint-css: node_modules

package-lock.json

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

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"tippy.js": "6.3.7",
5252
"toastify-js": "1.12.0",
5353
"tributejs": "5.1.3",
54+
"typescript": "5.5.2",
5455
"uint8-to-base64": "0.2.0",
5556
"vanilla-colorful": "0.7.2",
5657
"vue": "3.4.29",
@@ -67,13 +68,16 @@
6768
"@stoplight/spectral-cli": "6.11.1",
6869
"@stylistic/eslint-plugin-js": "2.2.1",
6970
"@stylistic/stylelint-plugin": "2.1.2",
71+
"@typescript-eslint/parser": "7.14.1",
7072
"@vitejs/plugin-vue": "5.0.5",
7173
"eslint": "8.57.0",
74+
"eslint-import-resolver-typescript": "3.6.1",
7275
"eslint-plugin-array-func": "4.0.0",
7376
"eslint-plugin-github": "5.0.1",
7477
"eslint-plugin-i": "2.29.1",
7578
"eslint-plugin-no-jquery": "3.0.1",
7679
"eslint-plugin-no-use-extend-native": "0.5.0",
80+
"eslint-plugin-playwright": "1.6.2",
7781
"eslint-plugin-regexp": "2.6.0",
7882
"eslint-plugin-sonarjs": "1.0.3",
7983
"eslint-plugin-unicorn": "54.0.0",

playwright.config.js playwright.config.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
// @ts-check
21
import {devices} from '@playwright/test';
2+
import {env} from 'node:process';
3+
import type {PlaywrightTestConfig} from '@playwright/test';
34

4-
const BASE_URL = process.env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
5+
const BASE_URL = env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
56

6-
/**
7-
* @see https://playwright.dev/docs/test-configuration
8-
* @type {import('@playwright/test').PlaywrightTestConfig}
9-
*/
107
export default {
118
testDir: './tests/e2e/',
12-
testMatch: /.*\.test\.e2e\.js/, // Match any .test.e2e.js files
9+
testMatch: /.*\.test\.e2e\.ts/, // Match any .test.e2e.ts files
1310

1411
/* Maximum time one test can run for. */
1512
timeout: 30 * 1000,
@@ -24,13 +21,13 @@ export default {
2421
},
2522

2623
/* Fail the build on CI if you accidentally left test.only in the source code. */
27-
forbidOnly: Boolean(process.env.CI),
24+
forbidOnly: Boolean(env.CI),
2825

2926
/* Retry on CI only */
30-
retries: process.env.CI ? 2 : 0,
27+
retries: env.CI ? 2 : 0,
3128

3229
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33-
reporter: process.env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],
30+
reporter: env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],
3431

3532
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3633
use: {
@@ -98,4 +95,4 @@ export default {
9895
outputDir: 'tests/e2e/test-artifacts/',
9996
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
10097
snapshotDir: 'tests/e2e/test-snapshots/',
101-
};
98+
} satisfies PlaywrightTestConfig;

tests/e2e/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=
6565

6666
## Running individual tests
6767

68-
Example command to run `example.test.e2e.js` test file:
68+
Example command to run `example.test.e2e.ts` test file:
6969

7070
_Note: unlike integration tests, this filtering is at the file level, not function_
7171

tests/e2e/e2e_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func TestMain(m *testing.M) {
7373
os.Exit(exitVal)
7474
}
7575

76-
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js" files in this directory and build a test for each.
76+
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.ts" files in this directory and build a test for each.
7777
func TestE2e(t *testing.T) {
7878
// Find the paths of all e2e test files in test directory.
79-
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")
79+
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.ts")
8080
paths, err := filepath.Glob(searchGlob)
8181
if err != nil {
8282
t.Fatal(err)

0 commit comments

Comments
 (0)