Skip to content

Commit

Permalink
Upgrade prettier to v2 (#926)
Browse files Browse the repository at this point in the history
* Upgrade to prettier v2 for modern TypeScript support.

* Change trailing comma to prettier v1 default.

Minimizes changes during v2 upgrade.

* Apply prettier v2 formatting changes.

Yaaay touching all of the files!

* Set end of line to LF.
  • Loading branch information
wjhsf authored Jan 24, 2023
1 parent 6d8563a commit 37c932e
Show file tree
Hide file tree
Showing 89 changed files with 411 additions and 654 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/package-lock.json binary linguist-generated=true
* text=auto
* text=auto eol=lf
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"format": "lerna run --parallel --stream format",
"bump-version": "node ./scripts/bump-version.js"
}
}
}
1 change: 1 addition & 0 deletions packages/commerce-sdk-react/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ semi: false
bracketSpacing: false
tabWidth: 4
arrowParens: 'always'
trailingComma: 'none'
5 changes: 1 addition & 4 deletions packages/commerce-sdk-react/scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const path = require('path')
const os = require('os')
const fs = require('fs')

const date = new Date()
.toString()
.split(' ')
.slice(1, 4)
const date = new Date().toString().split(' ').slice(1, 4)
const heading = `## v${pkg.version} (${date[0]} ${date[1]}, ${date[2]})\n`

const changelog = path.resolve(os.tmpdir(), 'CHANGELOG.md')
Expand Down
4 changes: 2 additions & 2 deletions packages/commerce-sdk-react/src/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {helpers} from 'commerce-sdk-isomorphic'

jest.mock('./storage', () => {
return {
CookieStorage: jest.fn(function() {
CookieStorage: jest.fn(function () {
const map = new Map()
return {
set(key: string, value: string) {
Expand All @@ -24,7 +24,7 @@ jest.mock('./storage', () => {
}
}
}),
LocalStorage: jest.fn(function() {
LocalStorage: jest.fn(function () {
const map = new Map()
return {
set(key: string, value: string) {
Expand Down
15 changes: 9 additions & 6 deletions packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ type UseShopperBasketsMutationArg = {
}

type ShopperBasketsClient = ApiClients['shopperBaskets']
export type ShopperBasketsMutationType = typeof ShopperBasketsMutations[keyof typeof ShopperBasketsMutations]
export type ShopperBasketsMutationType =
(typeof ShopperBasketsMutations)[keyof typeof ShopperBasketsMutations]

/**
* @private
Expand Down Expand Up @@ -450,11 +451,13 @@ export function useShopperBasketsMutation<Action extends ShopperBasketsMutationT
return useMutation<Data, Error, Params>(
(params, apiClients) => {
const method = apiClients['shopperBaskets'][action] as MutationFunction<Data, Params>
return (method.call as (
apiClient: ShopperBasketsClient,
params: Params,
rawResponse: boolean | undefined
) => any)(apiClients['shopperBaskets'], {...params, headers}, rawResponse)
return (
method.call as (
apiClient: ShopperBasketsClient,
params: Params,
rawResponse: boolean | undefined
) => any
)(apiClients['shopperBaskets'], {...params, headers}, rawResponse)
},
{
onSuccess: (data, params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ export const SHOPPER_CUSTOMERS_NOT_IMPLEMENTED = [
'updateCustomerProductList'
]

export type ShopperCustomersMutationType = typeof ShopperCustomersMutations[keyof typeof ShopperCustomersMutations]
export type ShopperCustomersMutationType =
(typeof ShopperCustomersMutations)[keyof typeof ShopperCustomersMutations]

type UseShopperCustomersMutationHeaders = NonNullable<
Argument<Client['registerCustomer']>
Expand Down Expand Up @@ -473,11 +474,13 @@ function useShopperCustomersMutation<Action extends ShopperCustomersMutationType
return useMutation<Data, Error, Params>(
(params, apiClients) => {
const method = apiClients['shopperCustomers'][action] as MutationFunction<Data, Params>
return (method.call as (
apiClient: ShopperCustomersClient,
params: Params,
rawResponse: boolean | undefined
) => any)(apiClients['shopperCustomers'], {...params, headers}, rawResponse)
return (
method.call as (
apiClient: ShopperCustomersClient,
params: Params,
rawResponse: boolean | undefined
) => any
)(apiClients['shopperCustomers'], {...params, headers}, rawResponse)
},
{
onSuccess: (data, params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ShopperLoginHelpers = {
Logout: 'logout'
} as const

type ShopperLoginHelpersType = typeof ShopperLoginHelpers[keyof typeof ShopperLoginHelpers]
type ShopperLoginHelpersType = (typeof ShopperLoginHelpers)[keyof typeof ShopperLoginHelpers]

/**
* A hook for Public Client Shopper Login OAuth helpers.
Expand Down
15 changes: 9 additions & 6 deletions packages/commerce-sdk-react/src/hooks/ShopperOrders/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const SHOPPER_ORDERS_NOT_IMPLEMENTED = [
'UpdatePaymentInstrumentForOrder'
]

export type ShopperOrdersMutationType = typeof ShopperOrdersMutations[keyof typeof ShopperOrdersMutations]
export type ShopperOrdersMutationType =
(typeof ShopperOrdersMutations)[keyof typeof ShopperOrdersMutations]

type UseShopperOrdersMutationHeaders = NonNullable<Argument<Client['createOrder']>>['headers']
type UseShopperOrdersMutationArg = {
Expand Down Expand Up @@ -113,11 +114,13 @@ function useShopperOrdersMutation<Action extends ShopperOrdersMutationType>(
return useMutation<Data, Error, Params>(
(params, apiClients) => {
const method = apiClients['shopperOrders'][action] as MutationFunction<Data, Params>
return (method.call as (
apiClient: ShopperOrdersClient,
params: Params,
rawResponse: boolean | undefined
) => any)(apiClients['shopperOrders'], {...params, headers}, rawResponse)
return (
method.call as (
apiClient: ShopperOrdersClient,
params: Params,
rawResponse: boolean | undefined
) => any
)(apiClients['shopperOrders'], {...params, headers}, rawResponse)
},
{
onSuccess: (data, params) => {
Expand Down
4 changes: 1 addition & 3 deletions packages/commerce-sdk-react/src/hooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export const updateCache = <Action extends CombinedMutationTypes>(
const isMatchingKey = (cacheQuery: {queryKey: {[x: string]: any}}, queryKey: QueryKey) =>
queryKey.every((item, index) =>
isObject(item) && isObject(cacheQuery.queryKey[index])
? Object.entries(cacheQuery.queryKey[index])
.sort()
.toString() ===
? Object.entries(cacheQuery.queryKey[index]).sort().toString() ===
Object.entries(item as Record<string, unknown>)
.sort()
.toString()
Expand Down
1 change: 1 addition & 0 deletions packages/internal-lib-build/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ semi: false
bracketSpacing: false
tabWidth: 4
arrowParens: 'always'
trailingComma: 'none'
6 changes: 3 additions & 3 deletions packages/internal-lib-build/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/internal-lib-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"jest-environment-jsdom": "^26.6.2",
"jest-environment-jsdom-global": "^2.0.4",
"jest-fetch-mock": "^2.1.2",
"prettier": "^1.19.1",
"prettier": "^2.8.3",
"raf": "^3.4.0",
"regenerator-runtime": "^0.13.9",
"replace-in-file": "^6.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/pwa-kit-create-app/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ semi: false
bracketSpacing: false
tabWidth: 4
arrowParens: 'always'
trailingComma: 'none'
1 change: 1 addition & 0 deletions packages/pwa-kit-dev/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ semi: false
bracketSpacing: false
tabWidth: 4
arrowParens: 'always'
trailingComma: 'none'
6 changes: 3 additions & 3 deletions packages/pwa-kit-dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pwa-kit-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"mime-types": "2.1.32",
"minimatch": "3.0.5",
"open": "^8.4.0",
"prettier": "^1.18.2",
"prettier": "^2.8.3",
"pwa-kit-runtime": "^2.6.0-dev",
"react-refresh": "^0.13.0",
"replace-in-file": "^6.2.0",
Expand Down
18 changes: 11 additions & 7 deletions packages/pwa-kit-dev/scripts/file-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const fs = require('fs')

const fileUtils = require('./file-utils')

const successCallbackAdapter = (value = true) => (...args) => {
args[args.length - 1](null, value)
}

const failureCallbackAdapter = (value = {}) => (...args) => {
args[args.length - 1](value)
}
const successCallbackAdapter =
(value = true) =>
(...args) => {
args[args.length - 1](null, value)
}

const failureCallbackAdapter =
(value = {}) =>
(...args) => {
args[args.length - 1](value)
}

const argsIgnoringCallback = (mock, index = 0) => mock.mock.calls[index].slice(0, -1)

Expand Down
5 changes: 1 addition & 4 deletions packages/pwa-kit-dev/scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const path = require('path')
const os = require('os')
const fs = require('fs')

const date = new Date()
.toString()
.split(' ')
.slice(1, 4)
const date = new Date().toString().split(' ').slice(1, 4)
const heading = `## v${pkg.version} (${date[0]} ${date[1]}, ${date[2]})\n`

const changelog = path.resolve(os.tmpdir(), 'CHANGELOG.md')
Expand Down
7 changes: 2 additions & 5 deletions packages/pwa-kit-dev/src/configs/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ module.exports = {
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['node_modules', 'build'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(
__dirname,
'mocks',
'fileMock.js'
),
'\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
path.join(__dirname, 'mocks', 'fileMock.js'),
'\\.(svg)$': path.join(__dirname, 'mocks', 'svgMock.js'),
'\\.(css|less)$': path.join(__dirname, 'mocks', 'styleMock.js')
},
Expand Down
24 changes: 7 additions & 17 deletions packages/pwa-kit-dev/src/ssr/server/build-dev-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('DevServer proxying', () => {
.get(targetPath)
.reply(
200,
function() {
function () {
requestHeaders.push(this.req.headers)
},
responseHeaders
Expand Down Expand Up @@ -414,9 +414,7 @@ describe('DevServer proxying', () => {
test('restricts methods', () => {
// Use nock to mock out a host to which we proxy, though we
// do not expect the request to be made.
const nockResponse = nock('https://test.proxy.com')
.get('/test/path3')
.reply(200, 'OK')
const nockResponse = nock('https://test.proxy.com').get('/test/path3').reply(200, 'OK')

const app = NoWebpackDevServerFactory._createApp(opts())
const path = '/mobify/caching/base3/test/path3'
Expand All @@ -434,7 +432,7 @@ describe('DevServer proxying', () => {
// Use nock to mock out a host to which we proxy
const nockResponse = nock('https://test.proxy.com')
.get('/test/path3')
.reply(200, function() {
.reply(200, function () {
const headers = this.req.headers
expect('x-mobify-access-key' in headers).toBe(false)
expect('cache-control' in headers).toBe(false)
Expand Down Expand Up @@ -474,9 +472,7 @@ describe('DevServer proxying', () => {
test('handles error', () => {
const app = NoWebpackDevServerFactory._createApp(opts())

return request(app)
.get('/mobify/proxy/base2/test/path')
.expect(500)
return request(app).get('/mobify/proxy/base2/test/path').expect(500)
})
})

Expand Down Expand Up @@ -748,9 +744,7 @@ describe('DevServer service worker', () => {
test(`${name} (and handle 404s correctly)`, () => {
const app = createApp()

return request(app)
.get(requestPath)
.expect(404)
return request(app).get(requestPath).expect(404)
})
})
})
Expand Down Expand Up @@ -795,18 +789,14 @@ describe('DevServer serveStaticFile', () => {
const app = NoWebpackDevServerFactory._createApp(options)
app.__devMiddleware = MockWebpackDevMiddleware
app.use('/test', NoWebpackDevServerFactory.serveStaticFile('static/favicon.ico'))
return request(app)
.get('/test')
.expect(200)
return request(app).get('/test').expect(200)
})

test('should return 404 if static file does not exist', async () => {
const options = opts()
const app = NoWebpackDevServerFactory._createApp(options)
app.__devMiddleware = MockWebpackDevMiddleware
app.use('/test', NoWebpackDevServerFactory.serveStaticFile('static/IDoNotExist.ico'))
return request(app)
.get('/test')
.expect(404)
return request(app).get('/test').expect(404)
})
})
1 change: 1 addition & 0 deletions packages/pwa-kit-react-sdk/.prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ semi: false
bracketSpacing: false
tabWidth: 4
arrowParens: 'always'
trailingComma: 'none'
18 changes: 11 additions & 7 deletions packages/pwa-kit-react-sdk/scripts/file-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ const fs = require('fs')

const fileUtils = require('./file-utils')

const successCallbackAdapter = (value = true) => (...args) => {
args[args.length - 1](null, value)
}

const failureCallbackAdapter = (value = {}) => (...args) => {
args[args.length - 1](value)
}
const successCallbackAdapter =
(value = true) =>
(...args) => {
args[args.length - 1](null, value)
}

const failureCallbackAdapter =
(value = {}) =>
(...args) => {
args[args.length - 1](value)
}

const argsIgnoringCallback = (mock, index = 0) => mock.mock.calls[index].slice(0, -1)

Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-react-sdk/scripts/setup-jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ global.document = require('jsdom').jsdom('<body></body>')
global.window = document.defaultView
global.window.matchMedia =
global.window.matchMedia ||
function() {
function () {
return {
matches: false,
addListener: () => {},
Expand Down
5 changes: 1 addition & 4 deletions packages/pwa-kit-react-sdk/scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const path = require('path')
const os = require('os')
const fs = require('fs')

const date = new Date()
.toString()
.split(' ')
.slice(1, 4)
const date = new Date().toString().split(' ').slice(1, 4)
const heading = `## v${pkg.version} (${date[0]} ${date[1]}, ${date[2]})\n`

const changelog = path.resolve(os.tmpdir(), 'CHANGELOG.md')
Expand Down
Loading

0 comments on commit 37c932e

Please sign in to comment.