Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use typescript-eslint@v6 internally #4566

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module.exports = {
extends: 'react-app',
extends: [
'react-app',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked'
],

parser: '@typescript-eslint/parser',

parserOptions: {
project: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project: true is already in typescript-eslint@v5. It's just a nice way to enable parserOptions.project 😄

tsconfigRootDir: __dirname
},

plugins: ['@typescript-eslint'],

settings: {
Expand All @@ -20,8 +29,8 @@ module.exports = {

rules: {
'jsx-a11y/href-no-hash': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-expressions': 'off',

// These off/not-configured-the-way-we-want lint rules we like & opt into
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand All @@ -31,6 +40,33 @@ module.exports = {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
]
],
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNever: true
}
],

// Todo: investigate whether we'd like these on
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'prefer-rest-params': 'off',

// These lint rules don't make sense for us but are enabled in the preset configs
'@typescript-eslint/no-unused-expressions': 'off'
}
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"devDependencies": {
"@babel/core": "^7.19.0",
"@types/node": "^18.7.16",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"@typescript-eslint/eslint-plugin": "6.0.0-alpha.158",
"@typescript-eslint/parser": "6.0.0-alpha.158",
"cross-env": "^7.0.3",
"esbuild-extra": "^0.1.3",
"eslint": "^8.23.0",
Expand All @@ -78,5 +78,9 @@
"typescript": "^4.8.3",
"vitest": "^0.27.2"
},
"resolutions": {
"@typescript-eslint/eslint-plugin": "6.0.0-alpha.158",
"@typescript-eslint/parser": "6.0.0-alpha.158"
},
"sideEffects": false
}
2 changes: 1 addition & 1 deletion src/applyMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function applyMiddleware(

const middlewareAPI: MiddlewareAPI = {
getState: store.getState,
dispatch: (action, ...args) => dispatch(action, ...args)
dispatch: (action, ...args: unknown[]) => dispatch(action, ...args)
}
const chain = middlewares.map(middleware => middleware(middlewareAPI))
dispatch = compose<typeof dispatch>(...chain)(store.dispatch)
Expand Down
9 changes: 3 additions & 6 deletions src/combineReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ export default function combineReducers(reducers: {
}) {
const reducerKeys = Object.keys(reducers)
const finalReducers: { [key: string]: Reducer<any, any, any> } = {}
for (let i = 0; i < reducerKeys.length; i++) {
const key = reducerKeys[i]

for (const key of reducerKeys) {
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
warning(`No reducer provided for key "${key}"`)
Expand Down Expand Up @@ -176,13 +174,12 @@ export default function combineReducers(reducers: {

let hasChanged = false
const nextState: StateFromReducersMapObject<typeof reducers> = {}
for (let i = 0; i < finalReducerKeys.length; i++) {
const key = finalReducerKeys[i]
for (const key of finalReducerKeys) {
const reducer = finalReducers[key]
const previousStateForKey = state[key]
const nextStateForKey = reducer(previousStateForKey, action)
if (typeof nextStateForKey === 'undefined') {
const actionType = action && action.type
const actionType = action?.type
throw new Error(
`When called with an action of type ${
actionType ? `"${String(actionType)}"` : '(unknown type)'
Expand Down
6 changes: 3 additions & 3 deletions test/combineReducers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Utils', () => {
type PushAction = { type: 'push'; value: unknown }

const reducer = combineReducers({
counter: (state: number = 0, action: IncrementAction) =>
counter: (state = 0, action: IncrementAction) =>
action.type === 'increment' ? state + 1 : state,
stack: (state: any[] = [], action: PushAction) =>
action.type === 'push' ? [...state, action.value] : state
Expand Down Expand Up @@ -64,8 +64,8 @@ describe('Utils', () => {

it('throws an error if a reducer returns undefined handling an action', () => {
const reducer = combineReducers({
counter(state: number = 0, action: Action) {
switch (action && action.type) {
counter(state = 0, action: Action) {
switch (action?.type) {
case 'increment':
return state + 1
case 'decrement':
Expand Down
4 changes: 2 additions & 2 deletions test/createStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ describe('createStore', () => {
const store = createStore(reducers.todos)

let resolve: (value: unknown) => void = () => {}
let promise = new Promise(_resolve => {
const promise = new Promise(_resolve => {
resolve = _resolve
})
store.subscribe(() => {
Expand All @@ -451,7 +451,7 @@ describe('createStore', () => {
it('does not leak private listeners array', async () => {
const store = createStore(reducers.todos)
let resolve: (value: unknown) => void = () => {}
let promise = new Promise(_resolve => {
const promise = new Promise(_resolve => {
resolve = _resolve
})

Expand Down
2 changes: 1 addition & 1 deletion test/typescript/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace FreeShapeAction {
text: 'test'
}

const text: string = action['text']
const text: string = action.text
}

namespace StringLiteralTypeAction {
Expand Down
10 changes: 5 additions & 5 deletions test/typescript/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ const storeWithCombineReducerAndBadPreloadedState = createStore(
)

const nestedCombinedReducer = combineReducers({
a: (state: string = 'a') => state,
a: (state = 'a') => state,
b: combineReducers({
c: (state: string = 'c') => state,
d: (state: string = 'd') => state
c: (state = 'c') => state,
d: (state = 'd') => state
}),
e: (state: BrandedString = brandedString) => state
})
Expand All @@ -116,8 +116,8 @@ const storeWithNestedCombineReducer = createStore(nestedCombinedReducer, {
})

const simpleCombinedReducer = combineReducers({
c: (state: string = 'c') => state,
d: (state: string = 'd') => state
c: (state = 'c') => state,
d: (state = 'd') => state
})

// @ts-expect-error
Expand Down
Loading