Skip to content
Myr

Merge pull request #200 from stefanwille/upgrade-prettier

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Upgrade prettier and enable prettier on TypeScript code

authored by Michel Weststrate · committed by GitHub · parents 255d135, e06b330 · Browse files · 7 files+140 added−111 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+140 added−111 removed

  • tests:+88 added−85 removed
  • other:+52 added−26 removed

7 files+140 added−111 removed

modified:__tests__/flow/ts.ts+4 added-4 removed
modified:__tests__/types.ts+84 added-81 removed
modified:src/immer.d.ts+36 added-18 removed
1// Mapped type to remove readonly modifiers from state2// Based on https://github.com/Microsoft/TypeScript/blob/d4dc67aab233f5a8834dff16531baf99b16fea78/tests/cases/conformance/types/conditional/conditionalTypes1.ts#L120-L1293export type DraftObject<T> = {4 -readonly [P in keyof T]: Draft<T[P]>;5};6export interface DraftArray<T> extends Array<Draft<T>> { }7export type Draft<T> =8 T extends any[] ? DraftArray<T[number]> :9 T extends ReadonlyArray<any> ? DraftArray<T[number]> :10 T extends object ? DraftObject<T> :11 T;3export type DraftObject<T> = {-readonly [P in keyof T]: Draft<T[P]>}4export interface DraftArray<T> extends Array<Draft<T>> {}5export type Draft<T> = T extends any[]6 ? DraftArray<T[number]>7 : T extends ReadonlyArray<any>8 ? DraftArray<T[number]>9 : T extends object ? DraftObject<T> : T1011export interface Patch {14 op: "replace" | "remove" | "add",15 path: (string|number)[]12 op: "replace" | "remove" | "add"13 path: (string | number)[]14 value?: any15}1617export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void
35 unmodified lines
53 initialState: S54 ): (currentState: S | undefined, a: A, b: B) => S55 // 3 additional arguments of types A, B and C56 <S = any, A = any, B = any, C = any>(59 recipe: (this: Draft<S>, draftState: Draft<S>, a: A, b: B, c: C) => void | S,57 recipe: (58 this: Draft<S>,59 draftState: Draft<S>,60 a: A,61 b: B,62 c: C63 ) => void | S,64 initialState: S65 ): (currentState: S | undefined, a: A, b: B, c: C) => S66 // any number of additional arguments, but with loss of type safety67 // this may be alleviated if "variadic kinds" makes it into Typescript:68 // https://github.com/Microsoft/TypeScript/issues/545369 <S = any>(66 recipe: (this: Draft<S>, draftState: Draft<S>, ...extraArgs: any[]) => void | S,70 recipe: (71 this: Draft<S>,72 draftState: Draft<S>,73 ...extraArgs: any[]74 ) => void | S,75 initialState: S76 ): (currentState: S | undefined, ...extraArgs: any[]) => S7778 // curried invocations without default initial state79 // 0 additional arguments72 <S = any>(73 recipe: (this: Draft<S>, draftState: Draft<S>) => void | S74 ): (currentState: S) => S80 <S = any>(recipe: (this: Draft<S>, draftState: Draft<S>) => void | S): (81 currentState: S82 ) => S83 // 1 additional argument of type A84 <S = any, A = any>(85 recipe: (this: Draft<S>, draftState: Draft<S>, a: A) => void | S86 ): (currentState: S, a: A) => S
2 unmodified lines
89 recipe: (this: Draft<S>, draftState: Draft<S>, a: A, b: B) => void | S90 ): (currentState: S, a: A, b: B) => S91 // 3 additional arguments of types A, B and C92 <S = any, A = any, B = any, C = any>(85 recipe: (this: Draft<S>, draftState: Draft<S>, a: A, b: B, c: C) => void | S93 recipe: (94 this: Draft<S>,95 draftState: Draft<S>,96 a: A,97 b: B,98 c: C99 ) => void | S100 ): (currentState: S, a: A, b: B, c: C) => S101 // any number of additional arguments, but with loss of type safety102 // this may be alleviated if "variadic kinds" makes it into Typescript:103 // https://github.com/Microsoft/TypeScript/issues/5453104 <S = any>(91 recipe: (this: Draft<S>, draftState: Draft<S>, ...extraArgs: any[]) => void | S105 recipe: (106 this: Draft<S>,107 draftState: Draft<S>,108 ...extraArgs: any[]109 ) => void | S110 ): (currentState: S, ...extraArgs: any[]) => S111}112113export const produce: IProduce
21 unmodified lines
modified:src/patches.js+5 added-3 removed
81 unmodified lines
82 const origValue = baseValue[key]83 const value = resultValue[key]84 const op = !assignedValue85 ? "remove"86 : key in baseValue ? "replace" : "add"86 : key in baseValue87 ? "replace"88 : "add"89 if (origValue === baseValue && op === "replace") return90 const path = basepath.concat(key)91 patches.push(op === "remove" ? {op, path} : {op, path, value})92 inversePatches.push(93 op === "add"94 ? {op: "remove", path}95 : op === "remove"94 ? {op: "add", path, value: origValue}95 : {op: "replace", path, value: origValue}96 ? {op: "add", path, value: origValue}97 : {op: "replace", path, value: origValue}98 )99 })100}101
45 unmodified lines
modified:src/proxy.js+3 added-1 removed
112 unmodified lines
113114function getOwnPropertyDescriptor(state, prop) {115 const owner = state.modified116 ? state.copy117 : has(state.proxies, prop) ? state.proxies : state.base117 : has(state.proxies, prop)118 ? state.proxies119 : state.base120 const descriptor = Reflect.getOwnPropertyDescriptor(owner, prop)121 if (descriptor && !(Array.isArray(owner) && prop === "length"))122 descriptor.configurable = true123 return descriptor
71 unmodified lines
modified:package.json+6 added-2 removed
13 unmodified lines
14 "test:perf": "NODE_ENV=production yarn-or-npm build && cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js",15 "test:flow": "yarn-or-npm flow check",16 "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",17 "build": "rimraf dist/ && cross-env NODE_ENV=production rollup -c && cpx \"src/immer.{d.ts,js.flow}\" dist",18 "prettier": "prettier \"*/**/*.js\" --ignore-path ./.prettierignore --write",18 "prettier": "prettier \"*/**/*.js\" \"*/**/*.ts\" --ignore-path ./.prettierignore --write",19 "precommit": "lint-staged",20 "prepublish": "yarn-or-npm run build",21 "release": "np --no-cleanup"22 },
54 unmodified lines
77 "lint-staged": {78 "*.js": [79 "prettier --write",80 "git add"81 ],82 "*.ts": [83 "prettier --write",84 "git add"85 ]86 },87 "jest": {88 "transform": {
15 unmodified lines
104 "json",105 "node"106 ]107 }104}108}
modified:yarn.lock+2 added-2 removed
3929 unmodified lines
3930 version "0.2.0"3931 resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"39323933prettier@^1.9.2:3934 version "1.9.2"3935 resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827"3934 version "1.14.3"3935 resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.3.tgz#90238dd4c0684b7edce5f83b0fb7328e48bd0895"39363937pretty-format@^21.2.1:3938 version "21.2.1"3939 resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.2.1.tgz#ae5407f3cf21066cd011aa1ba5fce7b6a2eddb36"
1277 unmodified lines