Skip to content

Commit 9c70063

Browse files
committed
fixed lint errors
1 parent 0abfcd1 commit 9c70063

File tree

2 files changed

+51
-35
lines changed

2 files changed

+51
-35
lines changed

packages/pwa-kit-create-app/scripts/trim-extensions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const traverse = require('@babel/traverse').default
1111
const generate = require('@babel/generator').default
1212
const path = require('path')
1313
const pluginConfig = require('../assets/plugin-config')
14-
const { execSync } = require('child_process')
14+
const {execSync} = require('child_process')
1515

1616
const removeComponentCandidates = [] // List of files that are candidates for removal, as a result of trimming.
1717
const SEPARATOR = path.sep // Use OS-specific path separator

packages/pwa-kit-create-app/scripts/trim-extensions.test.js

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
/* eslint-disable @typescript-eslint/no-var-requires */
88
const fs = require('fs')
9-
const { execSync } = require('child_process')
9+
const {execSync} = require('child_process')
1010

1111
jest.mock('../assets/plugin-config', () => ({
1212
plugins: {
@@ -25,32 +25,36 @@ jest.mock('child_process')
2525
// custom matcher to compare strings line by line with trimming
2626
expect.extend({
2727
toEqualTrimmedLines(received, expected) {
28-
const clean = str =>
29-
str
30-
.split('\n')
31-
.map(line => line.trim()) // Trim each line
32-
.filter(line => line.length > 0) // Optional: remove empty lines
33-
34-
const receivedLines = clean(received)
35-
const expectedLines = clean(expected)
36-
37-
const pass = this.equals(receivedLines, expectedLines)
38-
39-
if (pass) {
40-
return {
41-
pass: true,
42-
message: () =>
43-
`✅ Expected strings not to match line by line (but they did).\n\nExpected: ${this.utils.printExpected(expectedLines)}\nReceived: ${this.utils.printReceived(receivedLines)}`,
44-
};
45-
} else {
46-
return {
47-
pass: false,
48-
message: () =>
49-
`❌ Expected strings to match line by line (with trimming).\n\nExpected: ${this.utils.printExpected(expectedLines)}\nReceived: ${this.utils.printReceived(receivedLines)}`,
50-
};
51-
}
52-
},
53-
})
28+
const clean = (str) =>
29+
str
30+
.split('\n')
31+
.map((line) => line.trim()) // Trim each line
32+
.filter((line) => line.length > 0) // Optional: remove empty lines
33+
34+
const receivedLines = clean(received)
35+
const expectedLines = clean(expected)
36+
37+
const pass = this.equals(receivedLines, expectedLines)
38+
39+
if (pass) {
40+
return {
41+
pass: true,
42+
message: () =>
43+
`✅ Expected strings not to match line by line (but they did).\n\nExpected: ${this.utils.printExpected(
44+
expectedLines
45+
)}\nReceived: ${this.utils.printReceived(receivedLines)}`
46+
}
47+
} else {
48+
return {
49+
pass: false,
50+
message: () =>
51+
`❌ Expected strings to match line by line (with trimming).\n\nExpected: ${this.utils.printExpected(
52+
expectedLines
53+
)}\nReceived: ${this.utils.printReceived(receivedLines)}`
54+
}
55+
}
56+
}
57+
})
5458

5559
const trimExtensions = require('./trim-extensions')
5660

@@ -97,7 +101,9 @@ describe('trim-extensions', () => {
97101
expect.any(String),
98102
expect.toEqualTrimmedLines("const feature = 'Feature Enabled';")
99103
)
100-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
104+
expect(execSync).toHaveBeenCalledWith(
105+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
106+
)
101107
})
102108

103109
it('handles variable declarations correctly', () => {
@@ -122,7 +128,9 @@ describe('trim-extensions', () => {
122128
expect.any(String),
123129
expect.not.stringContaining("const featureBFunc = () => 'Feature B';")
124130
)
125-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
131+
expect(execSync).toHaveBeenCalledWith(
132+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
133+
)
126134
})
127135

128136
it('handles variable with ternary expressions correctly', () => {
@@ -139,13 +147,15 @@ describe('trim-extensions', () => {
139147

140148
expect(fs.writeFileSync).toHaveBeenCalledWith(
141149
expect.any(String),
142-
expect.toEqualTrimmedLines("const showFeature = Feature_A;")
150+
expect.toEqualTrimmedLines('const showFeature = Feature_A;')
143151
)
144152
expect(fs.writeFileSync).toHaveBeenCalledWith(
145153
expect.any(String),
146154
expect.not.stringContaining('const showFeature = Feature_B')
147155
)
148-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
156+
expect(execSync).toHaveBeenCalledWith(
157+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
158+
)
149159
})
150160

151161
it('handles return with ternary expressions correctly', () => {
@@ -167,7 +177,9 @@ describe('trim-extensions', () => {
167177
expect.any(String),
168178
expect.toEqualTrimmedLines(expected)
169179
)
170-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
180+
expect(execSync).toHaveBeenCalledWith(
181+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
182+
)
171183
})
172184

173185
it('handles PropTypes declarations correctly', () => {
@@ -207,7 +219,9 @@ describe('trim-extensions', () => {
207219
expect.any(String),
208220
expect.stringContaining('featureBProp: PropTypes.string')
209221
)
210-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
222+
expect(execSync).toHaveBeenCalledWith(
223+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
224+
)
211225
})
212226

213227
it('handles JSX elements in return statements correctly', () => {
@@ -241,7 +255,9 @@ describe('trim-extensions', () => {
241255
expect.any(String),
242256
expect.stringContaining('<ComponentB />')
243257
)
244-
expect(execSync).toHaveBeenCalledWith('npx prettier --write /mock/dir/src/components/featureComponent.jsx')
258+
expect(execSync).toHaveBeenCalledWith(
259+
'npx prettier --write /mock/dir/src/components/featureComponent.jsx'
260+
)
245261
})
246262

247263
it('does not remove referenced imports', () => {

0 commit comments

Comments
 (0)