Skip to content

Commit

Permalink
Enable noPropertyAccessFromIndexSignature and noUncheckedIndexedAccess (
Browse files Browse the repository at this point in the history
#216)

* Enable noPropertyAccessFromIndexSignature and noUncheckedIndexedAccess

* fix eslint

* npm ci --force

---------

Co-authored-by: Vladimir Kutepov <[email protected]>
  • Loading branch information
sporto and frenzzy authored Nov 22, 2024
1 parent 7820c62 commit 5246348
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
extends: ['airbnb-base', 'plugin:jest/recommended', 'plugin:prettier/recommended'],
rules: {
'dot-notation': 'off',
'no-nested-ternary': 'off',
'no-param-reassign': [
'error',
Expand All @@ -26,6 +27,7 @@ module.exports = {
rules: {
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'import/extensions': [
'error',
'ignorePackages',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
run: npm ci --force
- name: Lint
run: npm run lint
- name: Test
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"scripts": {
"lint": "eslint . --ext .ts,.js",
"test": "jest",
"build": "node tools/build.js"
"build": "node tools/build.js",
"tsc": "tsc --noEmit"
}
}
2 changes: 1 addition & 1 deletion src/UniversalRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ test('respects baseUrl', async () => {
expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c')
expect(action.mock.calls[0][0]).toHaveProperty('path', '/c')
expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b')
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0])
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0])
expect(action.mock.calls[0][0]).toHaveProperty('router', router)

let err
Expand Down
4 changes: 2 additions & 2 deletions src/UniversalRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function matchRoute<R, C extends RouterContext>(
if (matchResult && route.children) {
while (childIndex < route.children.length) {
if (!childMatches) {
const childRoute = route.children[childIndex]
const childRoute = route.children[childIndex]!
childRoute.parent = route

childMatches = matchRoute<R, C>(
Expand Down Expand Up @@ -320,7 +320,7 @@ class UniversalRouter<R = any, C extends RouterContext = RouterContext> {
})
}

context.next = next
context['next'] = next

return Promise.resolve()
.then(() => next(true, this.root))
Expand Down
2 changes: 1 addition & 1 deletion src/UniversalRouterSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ test('respects baseUrl', () => {
expect(action.mock.calls[0][0]).toHaveProperty('pathname', '/base/a/b/c')
expect(action.mock.calls[0][0]).toHaveProperty('path', '/c')
expect(action.mock.calls[0][0]).toHaveProperty('baseUrl', '/base/a/b')
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0].children[0])
expect(action.mock.calls[0][0]).toHaveProperty('route', routes.children[0]?.children[0])
expect(action.mock.calls[0][0]).toHaveProperty('router', router)

let err
Expand Down
4 changes: 2 additions & 2 deletions src/UniversalRouterSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function matchRoute<R, C extends RouterContext>(
if (matchResult && route.children) {
while (childIndex < route.children.length) {
if (!childMatches) {
const childRoute = route.children[childIndex]
const childRoute = route.children[childIndex]!
childRoute.parent = route

childMatches = matchRoute<R, C>(
Expand Down Expand Up @@ -318,7 +318,7 @@ class UniversalRouterSync<R = any, C extends RouterContext = RouterContext> {
return next(resume, parent, result)
}

context.next = next
context['next'] = next

try {
return next(true, this.root)
Expand Down
8 changes: 4 additions & 4 deletions src/generateUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function cacheRoutes(

if (routes) {
for (let i = 0; i < routes.length; i++) {
const childRoute = routes[i]
const childRoute = routes[i]!
const childName = childRoute.name
childRoute.parent = route
cacheRoutes(
Expand Down Expand Up @@ -117,7 +117,7 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G
const keys: Keys = Object.create(null)
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i]
if (typeof token !== 'string') {
if (token && typeof token !== 'string') {
keys[token.name] = true
}
}
Expand All @@ -132,8 +132,8 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G
const keys = Object.keys(params)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (!regexp.keys[key]) {
queryParams[key] = params[key]
if (key && !regexp.keys[key]) {
queryParams[key] = params[key] ?? ''
}
}
const query = opts.stringifyQueryParams(queryParams)
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"strict": true,
"declaration": true,
"noEmitOnError": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
Expand Down

0 comments on commit 5246348

Please sign in to comment.