/**
 * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
 *
 * @emails oncall+ads_integration_management
 * @flow strict-local
 * @format
 * @oncall ads_integration_management
 */

'use strict';

const MAX_ASCII_CHARACTER = 127;

/**
 * Serializes strings with non-ASCII characters to their Unicode escape
 * sequences (eg. \u2022), to avoid hitting this lint rule:
 * "Source code should only include printable US-ASCII bytes"
 */
const NonASCIIStringSnapshotSerializer = {
  test(val: mixed): boolean {
    if (typeof val !== 'string') {
      return false;
    }
    for (let i = 0; i < val.length; i++) {
      if (val.charCodeAt(i) > MAX_ASCII_CHARACTER) {
        return true;
      }
    }
    return false;
  },

  print: (val: string): string => {
    return (
      '"' +
      val
        .split('')
        .map((char) => {
          const code = char.charCodeAt(0);
          return code > MAX_ASCII_CHARACTER
            ? '\\u' + code.toString(16).padStart(4, '0')
            : char;
        })
        .join('')
        // Keep the same behaviour as Jest's regular string snapshot
        // serialization, which escapes double quotes.
        .replace(/"/g, '\\"') +
      '"'
    );
  },
};

module.exports = NonASCIIStringSnapshotSerializer;

/**
 * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
 *
 * @flow strict-local
 * @format
 * @oncall ads_integration_management
 */

'use strict';

const MAX_ASCII_CHARACTER = 127;

/**
 * Serializes strings with non-ASCII characters to their Unicode escape
 * sequences (eg. \u2022), to avoid hitting this lint rule:
 * "Source code should only include printable US-ASCII bytes"
 */
const NonASCIIStringSnapshotSerializer = {
  test(val: mixed): boolean {
    if (typeof val !== 'string') {
      return false;
    }
    for (let i = 0; i < val.length; i++) {
      if (val.charCodeAt(i) > MAX_ASCII_CHARACTER) {
        return true;
      }
    }
    return false;
  },

  print: (val: string): string => {
    return (
      '"' +
      val
        .split('')
        .map((char) => {
          const code = char.charCodeAt(0);
          return code > MAX_ASCII_CHARACTER
            ? '\\u' + code.toString(16).padStart(4, '0')
            : char;
        })
        .join('')
        // Keep the same behaviour as Jest's regular string snapshot
        // serialization, which escapes double quotes.
        .replace(/"/g, '\\"') +
      '"'
    );
  },
};

module.exports = NonASCIIStringSnapshotSerializer;

Remove @emails from non-generated files (91/n)
Remove @emails from non-generated files (91/n)

Summary:
Context - [[quip](https://fb.quip.com/1T2uAglapSkF)]

We are updating the oncall annotation format of all javascript files from  `emails oncall+my_oncall_shortname` to `oncall my_oncall_shortname`.

NOTE: There are other linter errors in some of these files that have not been introduced by this change, they are not being fixed here since they are non-trivial fixes (eg. moving a file to a different path).

To ensure we don't break anything, we are making this update with the following steps:
1. Add 'oncall' annotation format to JSCodegenModule and its generated files
2. Add new linter rule to add the annotation to existing non-codegen files
3. Add the new annotation to existing non-codegen files - D37541172
4. Update www oncall extraction logic and VS Code templates to use the new format - D37862548
5. Remove 'emails' annotation from JSCodegenModule and its generated files - D37963776
6. **(This diff)** Remove old annotation format from existing non-codegen files
7. Consolidate linters rule to ask user to add new annotation to new files

drop-conflicts
ignore-nocommit

Differential Revision: D38292971

fbshipit-source-id: 716de2affb520ae5e33aa9e1a051499c272bcc88
