chore: use consistent casing in escape characters (#14806)

This commit is contained in:
Simen Bekkhus
2023-12-29 16:15:04 +00:00
committed by GitHub
parent 9818081202
commit 6593081340
25 changed files with 54 additions and 58 deletions
+2 -5
View File
@@ -33,9 +33,9 @@ module.exports = {
'plugin:markdown/recommended',
'plugin:import/errors',
'plugin:eslint-comments/recommended',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'plugin:prettier/recommended',
],
globals: {
console: 'readonly',
@@ -424,6 +424,7 @@ module.exports = {
rules: {
'unicorn/prefer-code-point': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/text-encoding-identifier-case': 'off',
},
},
{
@@ -670,7 +671,6 @@ module.exports = {
// nah
'unicorn/consistent-destructuring': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/no-null': 'off',
'unicorn/no-process-exit': 'off',
@@ -688,7 +688,6 @@ module.exports = {
'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/error-message': 'off',
'unicorn/escape-case': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-console-spaces': 'off',
'unicorn/no-empty-file': 'off',
@@ -699,7 +698,6 @@ module.exports = {
'unicorn/no-typeof-undefined': 'off',
'unicorn/no-useless-promise-resolve-reject': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/number-literal-case': 'off',
'unicorn/prefer-date-now': 'off',
'unicorn/prefer-logical-operator-over-ternary': 'off',
'unicorn/prefer-math-trunc': 'off',
@@ -710,7 +708,6 @@ module.exports = {
'unicorn/prefer-spread': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/text-encoding-identifier-case': 'off',
// enabling this is blocked by https://github.com/microsoft/rushstack/issues/2780
'unicorn/prefer-export-from': 'off',
+1 -1
View File
@@ -25,7 +25,7 @@ it('code coverage for Handlebars', () => {
expect(result.stdout).toMatchSnapshot();
const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));
expect(
Object.keys(coverageMap).map(filename => path.basename(filename)),
+1 -1
View File
@@ -24,7 +24,7 @@ it('maps code coverage against original source', () => {
expect(result.exitCode).toBe(0);
const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));
// reduce absolute paths embedded in the coverage map to just filenames
for (const filename of Object.keys(coverageMap)) {
@@ -24,7 +24,7 @@ it('code coverage for transform instrumented code', () => {
expect(result.exitCode).toBe(0);
const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));
// reduce absolute paths embedded in the coverage map to just filenames
for (const filename of Object.keys(coverageMap)) {
+1 -1
View File
@@ -81,6 +81,6 @@ test('does not re-run tests when only access time is modified', async () => {
expect(numberOfTestRuns(testRun.getCurrentOutput().stderr)).toBe(2);
// Should re-run the test
fs.writeFileSync(modulePath, 'module.exports = 1;', {encoding: 'utf-8'});
fs.writeFileSync(modulePath, 'module.exports = 1;', 'utf8');
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 3);
});
@@ -42,7 +42,7 @@ class TestReporter {
*/
clearLine() {
if (process.stdout.isTTY) {
process.stderr.write('\x1b[999D\x1b[K');
process.stderr.write('\x1B[999D\x1B[K');
}
}
+1 -1
View File
@@ -62,7 +62,7 @@ export async function runCreate(rootDir = process.cwd()): Promise<void> {
try {
projectPackageJson = JSON.parse(
fs.readFileSync(projectPackageJsonPath, 'utf-8'),
fs.readFileSync(projectPackageJsonPath, 'utf8'),
) as ProjectPackageJson;
} catch {
throw new MalformedPackageJsonError(projectPackageJsonPath);
+1 -1
View File
@@ -17,7 +17,7 @@ type ResolveOptions = {
optional?: boolean;
};
export const BULLET: string = chalk.bold('\u25cf ');
export const BULLET: string = chalk.bold('\u25CF ');
export const DOCUMENTATION_NOTE = ` ${chalk.bold(
'Configuration Documentation:',
)}
+1 -1
View File
@@ -164,7 +164,7 @@ function findNative(
'stdout is null - this should never happen. Please open up an issue at https://github.com/jestjs/jest',
);
}
child.stdout.setEncoding('utf-8');
child.stdout.setEncoding('utf8');
child.stdout.on('data', data => (stdout += data));
child.stdout.on('close', () => {
@@ -116,16 +116,16 @@ exports[`on node >=15.0.0 should return the inner errors of an AggregateError 1`
AggregateError:
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:586:22)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:587:22)</intensity>
Errors contained in AggregateError:
Err 1
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:587:7)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:588:7)</intensity>
Err 2
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:588:7)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:589:7)</intensity>
"
`;
@@ -177,12 +177,12 @@ exports[`should return the error cause if there is one 1`] = `
Test exception
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:565:17)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:566:17)</intensity>
Cause:
Cause Error
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:568:17)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:569:17)</intensity>
"
`;
@@ -78,6 +78,7 @@ const vendorStack =
const babelStack =
' ' +
// eslint-disable-next-line unicorn/escape-case
`
packages/react/src/forwardRef.js: Unexpected token, expected , (20:10)
\u001b[0m \u001b[90m 18 | \u001b[39m \u001b[36mfalse\u001b[39m\u001b[33m,\u001b[39m
+1 -1
View File
@@ -58,7 +58,7 @@ const TITLE_INDENT = ' ';
const MESSAGE_INDENT = ' ';
const STACK_INDENT = ' ';
const ANCESTRY_SEPARATOR = ' \u203A ';
const TITLE_BULLET = chalk.bold('\u25cf ');
const TITLE_BULLET = chalk.bold('\u25CF ');
const STACK_TRACE_COLOR = chalk.dim;
const STACK_PATH_REGEXP = /\s*at.*\(?(:\d*:\d*|native)\)?/;
const EXEC_ERROR_MESSAGE = 'Test suite failed to run';
@@ -30,7 +30,7 @@ import type {ReporterOnStartOptions} from './types';
type write = WriteStream['write'];
type FlushBufferedOutput = () => void;
const TITLE_BULLET = chalk.bold('\u25cf ');
const TITLE_BULLET = chalk.bold('\u25CF ');
export default class DefaultReporter extends BaseReporter {
private _clear: string; // ANSI clear sequence for the last printed status
@@ -16,7 +16,7 @@ export default function wrapAnsiString(
return string;
}
const ANSI_REGEXP = /[\u001b\u009b]\[\d{1,2}m/gu;
const ANSI_REGEXP = /[\u001B\u009B]\[\d{1,2}m/gu;
const tokens = [];
let lastIndex = 0;
let match;
+1 -1
View File
@@ -10,7 +10,7 @@ import chalk = require('chalk');
import {ValidationError} from 'jest-validate';
import Resolver from './resolver';
const BULLET: string = chalk.bold('\u25cf ');
const BULLET: string = chalk.bold('\u25CF ');
const DOCUMENTATION_NOTE = ` ${chalk.bold('Configuration Documentation:')}
https://jestjs.io/docs/configuration
`;
@@ -40,7 +40,7 @@ describe('Runtime require.resolve', () => {
await fs.writeFile(
absoluteFilePath,
'module.exports = require.resolve(__filename);',
'utf-8',
'utf8',
);
const runtime = await createRuntime(__filename);
@@ -66,10 +66,10 @@ describe('Runtime require.resolve', () => {
`module.exports = require.resolve(${JSON.stringify(
target,
)}, {paths: []});`,
'utf-8',
'utf8',
);
await fs.writeFile(target, 'module.exports = {}', 'utf-8');
await fs.writeFile(target, 'module.exports = {}', 'utf8');
const runtime = await createRuntime(__filename);
const resolved = runtime.requireModule(runtime.__mockRootPath, entrypoint);
@@ -58,7 +58,7 @@ test('saveInlineSnapshots() replaces empty function call with a template literal
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot(`1`);\n',
);
});
@@ -187,7 +187,7 @@ it('foos', async () => {
null,
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`${`
it('foos', async () => {
const Foo = (props: { foo: string }) => <div>{props.foo}</div>;
@@ -229,7 +229,7 @@ expect(a).toMatchInlineSnapshot();
null,
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`${`
const Foo = (props: { foo: string }) => <div>{props.foo}</div>;
const a = Foo({ foo: "hello" });
@@ -260,7 +260,7 @@ expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`const a = [1, 2];
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
@@ -292,7 +292,7 @@ test.each([['babel'], ['flow'], ['typescript']])(
jest.mocked(prettier.resolveConfig.sync).mock.results[0].value,
).toEqual({parser});
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot(`1`);\n',
);
},
@@ -313,7 +313,7 @@ test('saveInlineSnapshots() replaces existing template literal with property mat
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot({}, `1`);\n',
);
});
@@ -335,7 +335,7 @@ test.each(['prettier', null])(
prettierModule,
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot({}, `1`);\n',
);
},
@@ -391,7 +391,7 @@ test('saveInlineSnapshots() uses escaped backticks', () => {
const frame = {column: 13, file: filename, line: 1} as Frame;
saveInlineSnapshots([{frame, snapshot: '`'}], dir, 'prettier');
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect("`").toMatchInlineSnapshot(`\\``);\n',
);
});
@@ -415,7 +415,7 @@ test('saveInlineSnapshots() works with non-literals in expect call', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"expect({a: 'a'}).toMatchInlineSnapshot(`{a: 'a'}`);\n",
);
});
@@ -444,7 +444,7 @@ test('saveInlineSnapshots() indents multi-line snapshots with spaces', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
@@ -487,7 +487,7 @@ test('saveInlineSnapshots() does not re-indent error snapshots', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is an error test', () => {\n" +
' expect(() => {\n' +
" throw new Error(['a', 'b'].join('\\n'));\n" +
@@ -537,7 +537,7 @@ test('saveInlineSnapshots() does not re-indent already indented snapshots', () =
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
@@ -580,7 +580,7 @@ test('saveInlineSnapshots() indents multi-line snapshots with tabs', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
"\texpect({a: 'a'}).toMatchInlineSnapshot(`\n" +
'\t\tObject {\n' +
@@ -613,7 +613,7 @@ test('saveInlineSnapshots() indents snapshots after prettier reformats', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () =>\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
@@ -645,7 +645,7 @@ test('saveInlineSnapshots() does not indent empty lines', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () =>\n" +
' expect(`hello\n\nworld`).toMatchInlineSnapshot(`\n' +
' hello\n' +
@@ -680,7 +680,7 @@ test('saveInlineSnapshots() indents awaited snapshots with spaces', () => {
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', async () => {\n" +
" const a = Promise.resolve({a: 'a'});\n" +
' await expect(a).resolves.toMatchInlineSnapshot(`\n' +
@@ -722,7 +722,7 @@ test('saveInlineSnapshots() prioritize parser from project/editor configuration'
);
expect(prettierSpy).not.toHaveBeenCalled();
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'const foo = {\n' +
' "1": "Some value",\n' +
'};\n' +
@@ -747,7 +747,7 @@ test('saveInlineSnapshots() replaces string literal, not just template literal',
'prettier',
);
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect("a").toMatchInlineSnapshot(`a`);\n',
);
});
@@ -8,7 +8,7 @@
import chalk = require('chalk');
import slash = require('slash');
const BULLET = '\u25cf ';
const BULLET = '\u25CF ';
const DOCUMENTATION_NOTE = ` ${chalk.bold(
'Code Transformation Documentation:',
)}
+1 -1
View File
@@ -9,6 +9,6 @@ import type {WriteStream} from 'tty';
export default function clearLine(stream: WriteStream): void {
if (stream.isTTY) {
stream.write('\x1b[999D\x1b[K');
stream.write('\x1B[999D\x1B[K');
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ import chalk = require('chalk');
import leven from 'leven';
import {format as prettyFormat} from 'pretty-format';
const BULLET: string = chalk.bold('\u25cf');
const BULLET: string = chalk.bold('\u25CF');
export const DEPRECATION = `${BULLET} Deprecation Warning`;
export const ERROR = `${BULLET} Validation Error`;
export const WARNING = `${BULLET} Validation Warning`;
@@ -21,7 +21,7 @@ import {
logValidationWarning,
} from './utils';
const BULLET: string = chalk.bold('\u25cf');
const BULLET: string = chalk.bold('\u25CF');
export const DOCUMENTATION_NOTE = ` ${chalk.bold('CLI Options Documentation:')}
https://jestjs.io/docs/cli
`;
+5 -5
View File
@@ -8,14 +8,14 @@
const isWindows = process.platform === 'win32';
export const KEYS = {
ARROW_DOWN: '\u001b[B',
ARROW_LEFT: '\u001b[D',
ARROW_RIGHT: '\u001b[C',
ARROW_UP: '\u001b[A',
ARROW_DOWN: '\u001B[B',
ARROW_LEFT: '\u001B[D',
ARROW_RIGHT: '\u001B[C',
ARROW_UP: '\u001B[A',
BACKSPACE: Buffer.from(isWindows ? '08' : '7f', 'hex').toString(),
CONTROL_C: '\u0003',
CONTROL_D: '\u0004',
CONTROL_U: '\u0015',
ENTER: '\r',
ESCAPE: '\u001b',
ESCAPE: '\u001B',
};
@@ -39,9 +39,7 @@ beforeAll(async () => {
const result = await transformFileAsync(sourcePath);
await writeFile(writePath, result!.code!, {
encoding: 'utf-8',
});
await writeFile(writePath, result!.code!, 'utf8');
}
});
+1 -1
View File
@@ -11,7 +11,7 @@ const linkRegex =
/\[#(\d+)]\(https:\/\/github.com\/facebook\/jest\/(issues|pull)\/(\d+)\)/g;
const changelogPath = 'CHANGELOG.md';
const data = fs.readFileSync(changelogPath, 'utf-8');
const data = fs.readFileSync(changelogPath, 'utf8');
let error = false;
let lineNumber = 1;
+2 -2
View File
@@ -9,7 +9,7 @@ import {execSync} from 'child_process';
import fs from 'graceful-fs';
import {isBinaryFileSync} from 'isbinaryfile';
const getFileContents = path => fs.readFileSync(path, {encoding: 'utf-8'});
const getFileContents = path => fs.readFileSync(path, 'utf8');
const isDirectory = path => fs.lstatSync(path).isDirectory();
const createRegExp = pattern => new RegExp(pattern);
@@ -130,7 +130,7 @@ function needsCopyrightHeader(file) {
}
function check() {
const allFiles = execSync('git ls-files', {encoding: 'utf-8'})
const allFiles = execSync('git ls-files', {encoding: 'utf8'})
.trim()
.split('\n');