Skip to content

Commit 5246348

Browse files
sportofrenzzy
andauthored
Enable noPropertyAccessFromIndexSignature and noUncheckedIndexedAccess (#216)
* Enable noPropertyAccessFromIndexSignature and noUncheckedIndexedAccess * fix eslint * npm ci --force --------- Co-authored-by: Vladimir Kutepov <frenzzy.man@gmail.com>
1 parent 7820c62 commit 5246348

9 files changed

+17
-12
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
extends: ['airbnb-base', 'plugin:jest/recommended', 'plugin:prettier/recommended'],
33
rules: {
4+
'dot-notation': 'off',
45
'no-nested-ternary': 'off',
56
'no-param-reassign': [
67
'error',
@@ -26,6 +27,7 @@ module.exports = {
2627
rules: {
2728
'@typescript-eslint/ban-types': 'off',
2829
'@typescript-eslint/no-explicit-any': 'off',
30+
'@typescript-eslint/no-non-null-assertion': 'off',
2931
'import/extensions': [
3032
'error',
3133
'ignorePackages',

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
node-version: ${{ matrix.node-version }}
1616
- name: Install dependencies
17-
run: npm ci
17+
run: npm ci --force
1818
- name: Lint
1919
run: npm run lint
2020
- name: Test

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"scripts": {
5555
"lint": "eslint . --ext .ts,.js",
5656
"test": "jest",
57-
"build": "node tools/build.js"
57+
"build": "node tools/build.js",
58+
"tsc": "tsc --noEmit"
5859
}
5960
}

src/UniversalRouter.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ test('respects baseUrl', async () => {
514514
expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c')
515515
expect(action.mock.calls[0][0]).toHaveProperty('path', '/c')
516516
expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b')
517-
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0])
517+
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0])
518518
expect(action.mock.calls[0][0]).toHaveProperty('router', router)
519519

520520
let err

src/UniversalRouter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function matchRoute<R, C extends RouterContext>(
190190
if (matchResult && route.children) {
191191
while (childIndex < route.children.length) {
192192
if (!childMatches) {
193-
const childRoute = route.children[childIndex]
193+
const childRoute = route.children[childIndex]!
194194
childRoute.parent = route
195195

196196
childMatches = matchRoute<R, C>(
@@ -320,7 +320,7 @@ class UniversalRouter<R = any, C extends RouterContext = RouterContext> {
320320
})
321321
}
322322

323-
context.next = next
323+
context['next'] = next
324324

325325
return Promise.resolve()
326326
.then(() => next(true, this.root))

src/UniversalRouterSync.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ test('respects baseUrl', () => {
511511
expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c')
512512
expect(action.mock.calls[0][0]).toHaveProperty('path', '/c')
513513
expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b')
514-
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0])
514+
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0])
515515
expect(action.mock.calls[0][0]).toHaveProperty('router', router)
516516

517517
let err

src/UniversalRouterSync.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function matchRoute<R, C extends RouterContext>(
191191
if (matchResult && route.children) {
192192
while (childIndex < route.children.length) {
193193
if (!childMatches) {
194-
const childRoute = route.children[childIndex]
194+
const childRoute = route.children[childIndex]!
195195
childRoute.parent = route
196196

197197
childMatches = matchRoute<R, C>(
@@ -318,7 +318,7 @@ class UniversalRouterSync<R = any, C extends RouterContext = RouterContext> {
318318
return next(resume, parent, result)
319319
}
320320

321-
context.next = next
321+
context['next'] = next
322322

323323
try {
324324
return next(true, this.root)

src/generateUrls.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function cacheRoutes(
5757

5858
if (routes) {
5959
for (let i = 0; i < routes.length; i++) {
60-
const childRoute = routes[i]
60+
const childRoute = routes[i]!
6161
const childName = childRoute.name
6262
childRoute.parent = route
6363
cacheRoutes(
@@ -117,7 +117,7 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G
117117
const keys: Keys = Object.create(null)
118118
for (let i = 0; i < tokens.length; i++) {
119119
const token = tokens[i]
120-
if (typeof token !== 'string') {
120+
if (token && typeof token !== 'string') {
121121
keys[token.name] = true
122122
}
123123
}
@@ -132,8 +132,8 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G
132132
const keys = Object.keys(params)
133133
for (let i = 0; i < keys.length; i++) {
134134
const key = keys[i]
135-
if (!regexp.keys[key]) {
136-
queryParams[key] = params[key]
135+
if (key && !regexp.keys[key]) {
136+
queryParams[key] = params[key] ?? ''
137137
}
138138
}
139139
const query = opts.stringifyQueryParams(queryParams)

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"strict": true,
99
"declaration": true,
1010
"noEmitOnError": true,
11+
"noPropertyAccessFromIndexSignature": true,
12+
"noUncheckedIndexedAccess": true,
1113
"noUnusedLocals": true,
1214
"noUnusedParameters": true,
1315
"sourceMap": true,

0 commit comments

Comments
 (0)