Skip to content

⬅️ Back to Table of Contents

📄 utils/rules

📊 Analysis Summary

Metric Count
🔧 Functions 6
📦 Imports 4
📊 Variables & Constants 1
📑 Type Aliases 1

📚 Table of Contents

🛠️ File Location:

📂 packages/website/plugins/utils/rules.ts

📦 Imports

Name Source
ESLintPluginRuleModule @typescript-eslint/eslint-plugin/use-at-your-own-risk/rules
RuleModule @typescript-eslint/utils/ts-eslint
VFile vfile
nodeIsHeading ./nodes

Variables & Constants

Name Type Kind Value Exported
sourceUrlPrefix "https://github.com/typescript-eslint... const 'https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/es...

Functions

getRulesString(extendsBaseRuleName: string, stem: string, withComment: boolean): string

Parameters:

  • withComment any: Whether to include a full comment note.

Tags: @remarks withComment can't be used inside a JSON object which is needed for eslintrc in the playground

Raw JSDoc
/**
 * @param withComment Whether to include a full comment note.
 * @remarks `withComment` can't be used inside a JSON object which is needed for eslintrc in the playground
 */
Code
export function getRulesString(
  extendsBaseRuleName: string,
  stem: string,
  withComment: boolean,
): string {
  return `{${
    withComment
      ? '\n    // Note: you must disable the base rule as it can report incorrect errors'
      : ''
  }
    "${extendsBaseRuleName}": "off",
    "@typescript-eslint/${stem}": "error"
  }`;
}

convertToPlaygroundHash(eslintrc: string): string

Parameters:

  • eslintrc string

Returns: string

Calls:

  • lz.compressToEncodedURIComponent
Code
export function convertToPlaygroundHash(eslintrc: string): string {
  return lz.compressToEncodedURIComponent(eslintrc);
}

getUrlForRuleTest(ruleName: string): string

Parameters:

  • ruleName string

Returns: string

Calls:

  • fs.existsSync
Code
export function getUrlForRuleTest(ruleName: string): string {
  for (const localPath of [
    `tests/rules/${ruleName}.test.ts`,
    `tests/rules/${ruleName}/`,
  ]) {
    if (fs.existsSync(`${eslintPluginDirectory}/${localPath}`)) {
      return `${sourceUrlPrefix}${localPath}`;
    }
  }

  throw new Error(`Could not find test file for ${ruleName}.`);
}

isESLintPluginRuleModule(rule: RuleModule<string, readonly unknown[]> …): rule is ESLintPluginRuleModule

Parameters:

  • rule RuleModule<string, readonly unknown[]> | undefined

Returns: rule is ESLintPluginRuleModule

Code
export function isESLintPluginRuleModule(
  rule: RuleModule<string, readonly unknown[]> | undefined,
): rule is ESLintPluginRuleModule {
  return !!rule?.meta.docs;
}

isVFileWithStem(file: VFile): file is VFileWithStem

Parameters:

  • file VFile

Returns: file is VFileWithStem

Code
export function isVFileWithStem(file: VFile): file is VFileWithStem {
  return !!file.stem;
}

findHeadingIndex(children: readonly unist.Node[], depth: 2 | 3, contents: string | ((node: mdast.PhrasingContent)…): number

Parameters:

  • children readonly unist.Node[]
  • depth 2 | 3
  • contents string | ((node: mdast.PhrasingContent) => boolean)

Returns: number

Calls:

  • children.findIndex
  • nodeIsHeading (from ./nodes)
  • childMatch
Code
export function findHeadingIndex(
  children: readonly unist.Node[],
  depth: 2 | 3,
  contents: string | ((node: mdast.PhrasingContent) => boolean),
): number {
  const childMatch =
    typeof contents === 'string'
      ? (node: mdast.PhrasingContent): boolean =>
          node.type === 'text' && node.value === contents
      : contents;

  return children.findIndex(
    node =>
      nodeIsHeading(node) &&
      node.depth === depth &&
      node.children.length === 1 &&
      childMatch(node.children[0]),
  );
}

Type Aliases

VFileWithStem

type VFileWithStem = {
  stem: string;
} & VFile;

Generated by Syntax Scribe