Skip to content

Commit 1babee2

Browse files
committed
Enable TypeScript
1 parent baf5b95 commit 1babee2

File tree

13 files changed

+473
-18
lines changed

13 files changed

+473
-18
lines changed

.eslintrc.cjs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@
1717

1818
module.exports = {
1919
root: true,
20+
plugins: [
21+
'@typescript-eslint',
22+
],
23+
parser: 'vue-eslint-parser',
2024
parserOptions: {
2125
/* Allow new ECMAScript syntax but not globals. This is because vite/esbuild
2226
transforms syntax to es2015 (at the earliest) but does not pollyfill APIs. */
2327
ecmaVersion: 'latest',
28+
parser: '@typescript-eslint/parser'
2429
},
2530
extends: [
2631
'standard',
2732
'eslint:recommended',
2833
'plugin:vue/vue3-essential',
2934
'plugin:vuetify/base',
3035
'plugin:cypress/recommended',
36+
'plugin:@typescript-eslint/recommended',
3137
],
3238
rules: {
3339
'comma-dangle': [
@@ -43,6 +49,35 @@ module.exports = {
4349
'template-curly-spacing': [
4450
'off'
4551
],
52+
'@typescript-eslint/no-unused-vars': [
53+
'error',
54+
{
55+
vars: 'all',
56+
args: 'none',
57+
}
58+
],
59+
'@typescript-eslint/no-var-requires': [
60+
'error',
61+
{
62+
allow: [
63+
'.*\\.cjs',
64+
'.*\\.json',
65+
],
66+
}
67+
],
68+
'@typescript-eslint/no-explicit-any': [
69+
'off', // Off while we migrate to TypeScript
70+
],
71+
'no-use-before-define': [
72+
'off' // Handled by @typescript-eslint below
73+
],
74+
'@typescript-eslint/no-use-before-define': [
75+
'error',
76+
{
77+
functions: false,
78+
variables: false,
79+
}
80+
],
4681
'vue/multi-word-component-names': [
4782
'off'
4883
],
@@ -60,6 +95,6 @@ module.exports = {
6095
],
6196
'cypress/unsafe-to-chain-command': [
6297
'off'
63-
]
98+
],
6499
},
65100
}

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ jobs:
3939
run: |
4040
yarn run lint
4141
42+
- name: Type check
43+
run: |
44+
yarn run type-check
45+
4246
- name: Test
4347
run: |
4448
yarn run coverage:unit

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The project was originally created with [vue-cli](https://cli.vuejs.org/), but
126126
has switched to [Vite](https://vitejs.dev/) with the upgrade from Vue 2 to 3.
127127

128128
The configuration for how the app is served and built is defined in
129-
[`vite.config.js`](vite.config.js).
129+
[`vite.config.ts`](vite.config.ts).
130130

131131
We are currently using the [Vuetify component library](https://vuetifyjs.com/en/).
132132
Its configuration is defined in [`src/plugins/vuetify.js`](src/plugins/vuetify.js).
@@ -211,10 +211,22 @@ testing the development version much easier.
211211

212212
### TypeScript
213213

214-
TypeScript is most likely the future for us. It can be adopted gradually.
215-
At the moment we only have JSDoc comments which can provide type information
214+
We are starting to adopt TypeScript, so have a mixture of `.ts` and `.js` files.
215+
Vue single-file-components can use `<script lang="ts">` to enable TypeScript.
216+
There are also JSDoc comments in `.js` files which can provide type information
216217
in your IDE.
217218

219+
> [!NOTE]
220+
> Vite performs transpilation of TypeScript but does not perform type checking.
221+
> It assumes type checking is taken care of by your IDE or a tool such as
222+
> [`vue-tsc`](https://github.com/vuejs/language-tools/tree/master/packages/tsc)
223+
> e.g. `vue-tsc --noEmit --watch`.
224+
225+
Useful resources:
226+
- [Using Vue with TypeScript](https://vuejs.org/guide/typescript/overview.html)
227+
- [Vite features - TypeScript](https://vitejs.dev/guide/features#typescript)
228+
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
229+
218230
## How The Data Is Provisioned
219231

220232
The Cylc UI connects to the GraphQL endpoint provided by the Cylc UI Server

cypress.config.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
12
const { defineConfig } = require('cypress')
23
const vitePreprocessor = require('cypress-vite')
34
const path = require('path')
@@ -29,7 +30,7 @@ module.exports = defineConfig({
2930
on(
3031
'file:preprocessor',
3132
vitePreprocessor({
32-
configFile: path.resolve(__dirname, './vite.config.js'),
33+
configFile: path.resolve(__dirname, './vite.config.ts'),
3334
mode: 'development',
3435
})
3536
)

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"test:component": "cypress open --component",
2222
"test:e2e": "yarn run serve e2e:open",
2323
"test:unit": "vitest",
24-
"test": "vitest run && yarn run serve cy:run"
24+
"test": "vitest run && yarn run serve cy:run",
25+
"type-check": "vue-tsc --noEmit"
2526
},
2627
"dependencies": {
2728
"@apollo/client": "3.10.3",
@@ -55,6 +56,9 @@
5556
},
5657
"devDependencies": {
5758
"@cypress/code-coverage": "3.12.39",
59+
"@types/lodash-es": "4.17.12",
60+
"@typescript-eslint/eslint-plugin": "7.1.0",
61+
"@typescript-eslint/parser": "7.1.0",
5862
"@vitejs/plugin-vue": "5.0.4",
5963
"@vitest/coverage-istanbul": "1.6.0",
6064
"@vue/test-utils": "2.4.6",
@@ -82,11 +86,13 @@
8286
"sass": "1.75.0",
8387
"sinon": "18.0.0",
8488
"standard": "17.1.0",
89+
"typescript": "5.3.3",
8590
"vite": "5.2.11",
8691
"vite-plugin-eslint": "1.8.1",
8792
"vite-plugin-istanbul": "6.0.2",
8893
"vite-plugin-vuetify": "2.0.3",
89-
"vitest": "1.6.0"
94+
"vitest": "1.6.0",
95+
"vue-tsc": "2.0.6"
9096
},
9197
"peerDependenciesMeta": {
9298
"react": {

renovate.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
"platformAutomerge": true,
77
"automergeStrategy": "squash",
88
"packageRules": [
9+
{
10+
"groupName": "typescript packages",
11+
"matchPackageNames": [
12+
"typescript",
13+
"vue-tsc"
14+
],
15+
"matchPackagePatterns": [
16+
"^@types/"
17+
],
18+
"automerge": true,
19+
"schedule": ["on saturday"]
20+
},
921
{
1022
"matchDepNames": ["yarn"],
1123
"automerge": true
@@ -78,7 +90,10 @@
7890
{
7991
"groupName": "eslint packages",
8092
"matchPackageNames": ["standard"],
81-
"matchPackagePatterns": ["^eslint"],
93+
"matchPackagePatterns": [
94+
"^eslint",
95+
"^@typescript-eslint"
96+
],
8297
"automerge": true,
8398
"schedule": ["on the first day of the month"]
8499
},

scripts/concurrently.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* eslint-disable no-console */
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/* eslint-disable no-console */
23
const concurrently = require('concurrently')
34

45
const args = process.argv.slice(2)

src/services/mock/json-server.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// TODO: make it configurable
1919
const PORT = 3000
2020

21+
/* eslint-disable @typescript-eslint/no-var-requires */
2122
const userProfile = require('./json/userprofile.json')
2223
const graphql = require('./graphql.cjs')
2324
const websockets = require('./websockets.cjs')

src/services/mock/json/index.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const IntrospectionQuery = require('./IntrospectionQuery.json')
1919
const userProfile = require('./userprofile.json')
2020
const taskProxy = require('./taskProxy.json')
2121
const familyProxy = require('./familyProxy.json')
22-
const workflowOne = require('./workflows/one')
23-
const workflowsMulti = require('./workflows/multi')
22+
const workflowOne = require('./workflows/one.json')
23+
const workflowsMulti = require('./workflows/multi.json')
2424
const { LogData } = require('./logData.cjs')
2525
const { LogFiles } = require('./logFiles.cjs')
2626
const analysisQuery = require('./analysisQuery.json')

src/services/mock/websockets.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
/* eslint-disable @typescript-eslint/no-var-requires */
1819
const { isArray } = require('lodash')
1920
const graphql = require('./graphql.cjs')
2021

0 commit comments

Comments
 (0)