Skip to content

Commit 506a062

Browse files
authored
chore: avoid backticks without template in strings (#12328)
1 parent dfbe71d commit 506a062

File tree

93 files changed

+385
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+385
-359
lines changed

.eslintrc.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ module.exports = {
155155
'sort-keys': 'off',
156156
},
157157
},
158+
// snapshots in examples plus inline snapshots need to keep backtick
159+
{
160+
files: ['*.md', 'e2e/custom-inline-snapshot-matchers/__tests__/*'],
161+
rules: {
162+
quotes: [
163+
'error',
164+
'single',
165+
{allowTemplateLiterals: true, avoidEscape: true},
166+
],
167+
},
168+
},
158169
{
159170
files: ['website/**/*'],
160171
rules: {
@@ -469,7 +480,7 @@ module.exports = {
469480
quotes: [
470481
'error',
471482
'single',
472-
{allowTemplateLiterals: true, avoidEscape: true},
483+
{allowTemplateLiterals: false, avoidEscape: true},
473484
],
474485
radix: 'warn',
475486
'require-jsdoc': 'off',

e2e/__tests__/customReporters.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('Custom Reporters Integration', () => {
138138

139139
test('prints reporter errors', () => {
140140
writeFiles(DIR, {
141-
'__tests__/test.test.js': `test('test', () => {});`,
141+
'__tests__/test.test.js': "test('test', () => {});",
142142
'package.json': JSON.stringify({
143143
jest: {
144144
reporters: ['default', '<rootDir>/reporter.js'],
@@ -163,7 +163,7 @@ describe('Custom Reporters Integration', () => {
163163
onNodeVersions('>=12.17.0', () => {
164164
test('supports reporter written in ESM', () => {
165165
writeFiles(DIR, {
166-
'__tests__/test.test.js': `test('test', () => {});`,
166+
'__tests__/test.test.js': "test('test', () => {});",
167167
'package.json': JSON.stringify({
168168
jest: {
169169
reporters: ['default', '<rootDir>/reporter.mjs'],

e2e/__tests__/executeTestsOnceInMpr.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ test('Tests are executed only once even in an MPR', () => {
3333

3434
/* eslint-disable sort-keys */
3535
writeFiles(DIR, {
36-
'foo/folder/my-test-bar.js': `test('bar', () => console.log('Bar!'));`,
36+
'foo/folder/my-test-bar.js': "test('bar', () => console.log('Bar!'));",
3737
'foo/folder/package.json': JSON.stringify(childConfig, null, 2),
3838

39-
'foo/directory/my-test-baz.js': `test('baz', () => console.log('Baz!'));`,
39+
'foo/directory/my-test-baz.js': "test('baz', () => console.log('Baz!'));",
4040
'foo/directory/package.json': JSON.stringify(childConfig, null, 2),
4141

42-
'foo/whatever/my-test-qux.js': `test('qux', () => console.log('Qux!'));`,
42+
'foo/whatever/my-test-qux.js': "test('qux', () => console.log('Qux!'));",
4343
'foo/whatever/package.json': JSON.stringify(childConfig, null, 2),
4444

4545
'package.json': JSON.stringify(config, null, 2),

e2e/__tests__/globalSetup.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test('globalSetup is triggered once before all test suites', () => {
5757
const setupPath = path.join(e2eDir, 'setup.js');
5858
const result = runWithJson(e2eDir, [
5959
`--globalSetup=${setupPath}`,
60-
`--testPathPattern=__tests__`,
60+
'--testPathPattern=__tests__',
6161
]);
6262

6363
expect(result.exitCode).toBe(0);
@@ -71,7 +71,7 @@ test('jest throws an error when globalSetup does not export a function', () => {
7171
const setupPath = path.resolve(__dirname, '../global-setup/invalidSetup.js');
7272
const {exitCode, stderr} = runJest(e2eDir, [
7373
`--globalSetup=${setupPath}`,
74-
`--testPathPattern=__tests__`,
74+
'--testPathPattern=__tests__',
7575
]);
7676

7777
expect(exitCode).toBe(1);
@@ -155,7 +155,7 @@ test('globalSetup throws with named export', () => {
155155

156156
const {exitCode, stderr} = runJest(e2eDir, [
157157
`--globalSetup=${setupPath}`,
158-
`--testPathPattern=__tests__`,
158+
'--testPathPattern=__tests__',
159159
]);
160160

161161
expect(exitCode).toBe(1);
@@ -166,13 +166,13 @@ test('globalSetup throws with named export', () => {
166166
});
167167

168168
test('should not transpile the transformer', () => {
169-
const {exitCode} = runJest('global-setup-custom-transform', [`--no-cache`]);
169+
const {exitCode} = runJest('global-setup-custom-transform', ['--no-cache']);
170170

171171
expect(exitCode).toBe(0);
172172
});
173173

174174
test('should transform node_modules if configured by transformIgnorePatterns', () => {
175-
const {exitCode} = runJest('global-setup-node-modules', [`--no-cache`]);
175+
const {exitCode} = runJest('global-setup-node-modules', ['--no-cache']);
176176

177177
expect(exitCode).toBe(0);
178178
});
@@ -190,7 +190,7 @@ test('properly handle rejections', () => {
190190
`,
191191
});
192192

193-
const {exitCode, stderr} = runJest(rejectionDir, [`--no-cache`]);
193+
const {exitCode, stderr} = runJest(rejectionDir, ['--no-cache']);
194194

195195
expect(exitCode).toBe(1);
196196
expect(stderr).toContain('Error: Jest: Got error running globalSetup');
@@ -199,7 +199,7 @@ test('properly handle rejections', () => {
199199

200200
onNodeVersions('>=12.17.0', () => {
201201
test('globalSetup works with ESM modules', () => {
202-
const {exitCode} = runJest('global-setup-esm', [`--no-cache`], {
202+
const {exitCode} = runJest('global-setup-esm', ['--no-cache'], {
203203
nodeOptions: '--experimental-vm-modules --no-warnings',
204204
});
205205

e2e/__tests__/globalTeardown.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('globalTeardown is triggered once after all test suites', () => {
4141
const teardownPath = path.resolve(e2eDir, 'teardown.js');
4242
const result = runWithJson('global-teardown', [
4343
`--globalTeardown=${teardownPath}`,
44-
`--testPathPattern=__tests__`,
44+
'--testPathPattern=__tests__',
4545
]);
4646

4747
expect(result.exitCode).toBe(0);
@@ -55,7 +55,7 @@ test('jest throws an error when globalTeardown does not export a function', () =
5555
const teardownPath = path.resolve(e2eDir, 'invalidTeardown.js');
5656
const {exitCode, stderr} = runJest(e2eDir, [
5757
`--globalTeardown=${teardownPath}`,
58-
`--testPathPattern=__tests__`,
58+
'--testPathPattern=__tests__',
5959
]);
6060

6161
expect(exitCode).toBe(1);
@@ -126,7 +126,7 @@ test('globalTeardown throws with named export', () => {
126126

127127
const {exitCode, stderr} = runJest(e2eDir, [
128128
`--globalTeardown=${teardownPath}`,
129-
`--testPathPattern=__tests__`,
129+
'--testPathPattern=__tests__',
130130
]);
131131

132132
expect(exitCode).toBe(1);
@@ -138,7 +138,7 @@ test('globalTeardown throws with named export', () => {
138138

139139
onNodeVersions('>=12.17.0', () => {
140140
test('globalTeardown works with ESM modules', () => {
141-
const {exitCode} = runJest('global-teardown-esm', [`--no-cache`], {
141+
const {exitCode} = runJest('global-teardown-esm', ['--no-cache'], {
142142
nodeOptions: '--experimental-vm-modules --no-warnings',
143143
});
144144

e2e/__tests__/jest.config.js.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ afterAll(() => cleanup(DIR));
1616

1717
test('works with jest.config.js', () => {
1818
writeFiles(DIR, {
19-
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
20-
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
19+
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
20+
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
2121
'package.json': '{}',
2222
});
2323

@@ -35,7 +35,7 @@ test('traverses directory tree up until it finds jest.config', () => {
3535
test('banana', () => expect(1).toBe(1));
3636
test('abc', () => console.log(slash(process.cwd())));
3737
`,
38-
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
38+
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
3939
'package.json': '{}',
4040
'some/nested/directory/file.js': '// nothing special',
4141
});
@@ -57,8 +57,8 @@ test('traverses directory tree up until it finds jest.config', () => {
5757

5858
test('invalid JS in jest.config.js', () => {
5959
writeFiles(DIR, {
60-
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
61-
'jest.config.js': `module.exports = i'll break this file yo`,
60+
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
61+
'jest.config.js': "module.exports = i'll break this file yo",
6262
'package.json': '{}',
6363
});
6464

e2e/__tests__/jest.config.ts.test.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ afterAll(() => cleanup(DIR));
1616

1717
test('works with jest.config.ts', () => {
1818
writeFiles(DIR, {
19-
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
20-
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
19+
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
20+
'jest.config.ts':
21+
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
2122
'package.json': '{}',
2223
});
2324

@@ -30,8 +31,9 @@ test('works with jest.config.ts', () => {
3031

3132
test('works with tsconfig.json', () => {
3233
writeFiles(DIR, {
33-
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
34-
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
34+
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
35+
'jest.config.ts':
36+
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
3537
'package.json': '{}',
3638
'tsconfig.json': '{ "compilerOptions": { "module": "esnext" } }',
3739
});
@@ -50,7 +52,8 @@ test('traverses directory tree up until it finds jest.config', () => {
5052
test('giraffe', () => expect(1).toBe(1));
5153
test('abc', () => console.log(slash(process.cwd())));
5254
`,
53-
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
55+
'jest.config.ts':
56+
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
5457
'package.json': '{}',
5558
'some/nested/directory/file.js': '// nothing special',
5659
});
@@ -72,8 +75,8 @@ test('traverses directory tree up until it finds jest.config', () => {
7275

7376
test('it does type check the config', () => {
7477
writeFiles(DIR, {
75-
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
76-
'jest.config.ts': `export default { testTimeout: "10000" }`,
78+
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
79+
'jest.config.ts': 'export default { testTimeout: "10000" }',
7780
'package.json': '{}',
7881
});
7982

@@ -84,8 +87,8 @@ test('it does type check the config', () => {
8487

8588
test('invalid JS in jest.config.ts', () => {
8689
writeFiles(DIR, {
87-
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
88-
'jest.config.ts': `export default i'll break this file yo`,
90+
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
91+
'jest.config.ts': "export default i'll break this file yo",
8992
'package.json': '{}',
9093
});
9194

e2e/__tests__/jestChangedFiles.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ it('does not find changes in files with no diff, for git', async () => {
341341
test('handles a bad revision for "changedSince", for git', async () => {
342342
writeFiles(DIR, {
343343
'.watchmanconfig': '',
344-
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
344+
'__tests__/file1.test.js': "require('../file1'); test('file1', () => {});",
345345
'file1.js': 'module.exports = {}',
346346
'package.json': '{}',
347347
});
@@ -494,7 +494,7 @@ testIfHg('monitors only root paths for hg', async () => {
494494
testIfHg('handles a bad revision for "changedSince", for hg', async () => {
495495
writeFiles(DIR, {
496496
'.watchmanconfig': '',
497-
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
497+
'__tests__/file1.test.js': "require('../file1'); test('file1', () => {});",
498498
'file1.js': 'module.exports = {}',
499499
'package.json': '{}',
500500
});

e2e/__tests__/jestEnvironmentJsdom.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ afterAll(() => cleanup(DIR));
1717

1818
test('check is not leaking memory', () => {
1919
writeFiles(DIR, {
20-
'__tests__/a.test.js': `test('a', () => console.log('a'));`,
21-
'__tests__/b.test.js': `test('b', () => console.log('b'));`,
20+
'__tests__/a.test.js': "test('a', () => console.log('a'));",
21+
'__tests__/b.test.js': "test('b', () => console.log('b'));",
2222
'package.json': JSON.stringify({jest: {testEnvironment: 'jsdom'}}),
2323
});
2424

e2e/__tests__/jestRequireActual.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ test('understands dependencies using jest.requireActual', () => {
2323
2424
test('a', () => {});
2525
`,
26-
'__tests__/b.test.js': `test('b', () => {});`,
27-
'a.js': `module.exports = {}`,
26+
'__tests__/b.test.js': "test('b', () => {});",
27+
'a.js': 'module.exports = {}',
2828
'package.json': JSON.stringify({jest: {}}),
2929
});
3030

e2e/__tests__/jestRequireMock.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ test('understands dependencies using jest.requireMock', () => {
2323
2424
test('a', () => {});
2525
`,
26-
'__tests__/b.test.js': `test('b', () => {});`,
27-
'a.js': `module.exports = {}`,
26+
'__tests__/b.test.js': "test('b', () => {});",
27+
'a.js': 'module.exports = {}',
2828
'package.json': JSON.stringify({jest: {}}),
2929
});
3030

e2e/__tests__/logHeapUsage.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ afterAll(() => cleanup(DIR));
1717

1818
test('logs memory usage', () => {
1919
writeFiles(DIR, {
20-
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
20+
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
2121
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
2222
});
2323

e2e/__tests__/multiProjectRunner.test.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ afterEach(() => cleanup(DIR));
2020
test("--listTests doesn't duplicate the test files", () => {
2121
writeFiles(DIR, {
2222
'.watchmanconfig': '',
23-
'/project1.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
24-
'/project2.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
25-
'__tests__/inBothProjectsTest.js': `test('test', () => {});`,
23+
'/project1.js': "module.exports = {rootDir: './', displayName: 'BACKEND'}",
24+
'/project2.js': "module.exports = {rootDir: './', displayName: 'BACKEND'}",
25+
'__tests__/inBothProjectsTest.js': "test('test', () => {});",
2626
'package.json': JSON.stringify({
2727
jest: {projects: ['<rootDir>/project1.js', '<rootDir>/project2.js']},
2828
}),
@@ -139,13 +139,13 @@ test('"No tests found" message for projects', () => {
139139
test('file1', () => {});
140140
`,
141141
'project1/file1.js': SAMPLE_FILE_CONTENT,
142-
'project1/jest.config.js': `module.exports = {rootDir: './'}`,
142+
'project1/jest.config.js': "module.exports = {rootDir: './'}",
143143
'project2/__tests__/file1.test.js': `
144144
const file1 = require('../file1');
145145
test('file1', () => {});
146146
`,
147147
'project2/file1.js': SAMPLE_FILE_CONTENT,
148-
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
148+
'project2/jest.config.js': "module.exports = {rootDir: './'}",
149149
});
150150
const {stdout: verboseOutput} = runJest(DIR, [
151151
'--no-watchman',
@@ -352,9 +352,11 @@ test('resolves projects and their <rootDir> properly', () => {
352352
setupFiles: ['<rootDir>/project1_setup.js'],
353353
testEnvironment: 'node',
354354
}),
355-
'project1/__tests__/test.test.js': `test('project1', () => expect(global.project1).toBe(true))`,
355+
'project1/__tests__/test.test.js':
356+
"test('project1', () => expect(global.project1).toBe(true))",
356357
'project1/project1_setup.js': 'global.project1 = true;',
357-
'project2/__tests__/test.test.js': `test('project2', () => expect(global.project2).toBe(true))`,
358+
'project2/__tests__/test.test.js':
359+
"test('project2', () => expect(global.project2).toBe(true))",
358360
'project2/project2.conf.json': JSON.stringify({
359361
name: 'project2',
360362
rootDir: '../', // root dir is set to the top level
@@ -427,7 +429,7 @@ test('resolves projects and their <rootDir> properly', () => {
427429

428430
({stderr} = runJest(DIR, ['--no-watchman']));
429431
expect(stderr).toMatch(
430-
`Can't find a root directory while resolving a config file path.`,
432+
"Can't find a root directory while resolving a config file path.",
431433
);
432434
expect(stderr).toMatch(/banana/);
433435
});

0 commit comments

Comments
 (0)